diff options
author | Nasser Grainawi <quic_nasserg@quicinc.com> | 2024-02-12 16:29:47 -0700 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2024-02-13 15:40:07 +0100 |
commit | 8b49e01abf44e21e38504ba31a68670710ca6610 (patch) | |
tree | 0699d4ba672e97217164d6a6fb1b796155e90039 /org.eclipse.jgit | |
parent | 7476183589f4c255ea561be9dff0109fc8919e9f (diff) | |
download | jgit-8b49e01abf44e21e38504ba31a68670710ca6610.tar.gz jgit-8b49e01abf44e21e38504ba31a68670710ca6610.zip |
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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/SnapshottingRefDirectory.java | 26 |
1 files changed, 20 insertions, 6 deletions
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> 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(); + } } } |