From: Nasser Grainawi Date: Mon, 12 Feb 2024 23:29:47 +0000 (-0700) Subject: SnapshottingRefDir: Reduce casts with overrides X-Git-Tag: v6.9.0.202402211805-m3~13^2^2^2~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8b49e01abf44e21e38504ba31a68670710ca6610;p=jgit.git SnapshottingRefDir: Reduce casts with overrides Overriding getRefDirectory() and getRefDatabase() lets us skip casting to SnapshottingRefDirectory in several places. Change-Id: I61ba12fb6f066b1a9c4ea5ec9538978cbf040acd Signed-off-by: Nasser Grainawi --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/SnapshottingRefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/SnapshottingRefDirectory.java index 0b9748096e..10ef7fbf3e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/SnapshottingRefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/SnapshottingRefDirectory.java @@ -13,7 +13,6 @@ package org.eclipse.jgit.internal.storage.file; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.revwalk.RevWalk; @@ -148,29 +147,29 @@ class SnapshottingRefDirectory extends RefDirectory { } private static T invalidateSnapshotOnError( - SupplierThrowsException f, RefDatabase refDb) + SupplierThrowsException f, SnapshottingRefDirectory refDb) throws IOException { return invalidateSnapshotOnError(a -> f.call(), null, refDb); } private static R invalidateSnapshotOnError( FunctionThrowsException f, A a, - RefDatabase refDb) throws IOException { + SnapshottingRefDirectory refDb) throws IOException { try { return f.apply(a); } catch (IOException e) { - ((SnapshottingRefDirectory) refDb).invalidateSnapshot(); + refDb.invalidateSnapshot(); throw e; } } private static void invalidateSnapshotOnError( TriConsumerThrowsException f, A1 a1, A2 a2, - A3 a3, RefDatabase refDb) throws IOException { + A3 a3, SnapshottingRefDirectory refDb) throws IOException { try { f.accept(a1, a2, a3); } catch (IOException e) { - ((SnapshottingRefDirectory) refDb).invalidateSnapshot(); + refDb.invalidateSnapshot(); throw e; } } @@ -215,6 +214,11 @@ class SnapshottingRefDirectory extends RefDirectory { return invalidateSnapshotOnError(t -> super.link(t), target, getRefDatabase()); } + + @Override + public SnapshottingRefDirectory getRefDatabase() { + return (SnapshottingRefDirectory) super.getRefDatabase(); + } } private static class SnapshotRefDirectoryRename extends RefDirectoryRename { @@ -228,6 +232,11 @@ class SnapshottingRefDirectory extends RefDirectory { return invalidateSnapshotOnError(() -> super.rename(), getRefDirectory()); } + + @Override + public SnapshottingRefDirectory getRefDirectory() { + return (SnapshottingRefDirectory) super.getRefDirectory(); + } } private static class SnapshotPackedBatchRefUpdate @@ -254,5 +263,10 @@ class SnapshottingRefDirectory extends RefDirectory { invalidateSnapshotOnError((rw, m, a3) -> super.execute(rw, m), walk, monitor, null, getRefDatabase()); } + + @Override + public SnapshottingRefDirectory getRefDatabase() { + return (SnapshottingRefDirectory) super.getRefDatabase(); + } } }