]> source.dussan.org Git - jgit.git/commitdiff
SnapshottingRefDir: Reduce casts with overrides 88/1176788/2
authorNasser Grainawi <quic_nasserg@quicinc.com>
Mon, 12 Feb 2024 23:29:47 +0000 (16:29 -0700)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 13 Feb 2024 14:40:07 +0000 (15:40 +0100)
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>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/SnapshottingRefDirectory.java

index 0b9748096e846bb7da54b90c033158ec8f8a61c0..10ef7fbf3e43ccf6bd2371919680c50b2d793142 100644 (file)
@@ -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> 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 @@ 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();
+               }
        }
 }