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 <quic_nasserg@quicinc.com>
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 0b97480..10ef7fb 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 @@
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 @@
}
private static <T> T invalidateSnapshotOnError(
- SupplierThrowsException<T, IOException> f, RefDatabase refDb)
+ SupplierThrowsException<T, IOException> f, SnapshottingRefDirectory refDb)
throws IOException {
return invalidateSnapshotOnError(a -> f.call(), null, refDb);
}
private static <A, R> R invalidateSnapshotOnError(
FunctionThrowsException<A, R, IOException> 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 <A1, A2, A3> void invalidateSnapshotOnError(
TriConsumerThrowsException<A1, A2, A3, IOException> 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 @@
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 @@
return invalidateSnapshotOnError(() -> super.rename(),
getRefDirectory());
}
+
+ @Override
+ public SnapshottingRefDirectory getRefDirectory() {
+ return (SnapshottingRefDirectory) super.getRefDirectory();
+ }
}
private static class SnapshotPackedBatchRefUpdate
@@ -254,5 +263,10 @@
invalidateSnapshotOnError((rw, m, a3) -> super.execute(rw, m), walk,
monitor, null, getRefDatabase());
}
+
+ @Override
+ public SnapshottingRefDirectory getRefDatabase() {
+ return (SnapshottingRefDirectory) super.getRefDatabase();
+ }
}
}