diff options
author | Jonathan Nieder <jrn@google.com> | 2021-01-29 01:52:13 -0500 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2021-01-29 01:52:13 -0500 |
commit | 59420886e98bfcb574511cea191ccb3953004610 (patch) | |
tree | 5b977111399a915ae9a53e36efd8d43d78fdaa9f | |
parent | 6f82690aaf2be783be6d77f0903788ff0832472a (diff) | |
parent | dbd05433ecc77d8044e567f512bb721ff259d7f8 (diff) | |
download | jgit-59420886e98bfcb574511cea191ccb3953004610.tar.gz jgit-59420886e98bfcb574511cea191ccb3953004610.zip |
Merge "Move reachability checker generation into the ObjectReader object"
17 files changed, 137 insertions, 33 deletions
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index a1239468db..0540cfb045 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -34,6 +34,7 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)", org.eclipse.jgit.ignore.internal;version="[5.11.0,5.12.0)", org.eclipse.jgit.internal;version="[5.11.0,5.12.0)", org.eclipse.jgit.internal.fsck;version="[5.11.0,5.12.0)", + org.eclipse.jgit.internal.revwalk;version="[5.11.0,5.12.0)", org.eclipse.jgit.internal.storage.dfs;version="[5.11.0,5.12.0)", org.eclipse.jgit.internal.storage.file;version="[5.11.0,5.12.0)", org.eclipse.jgit.internal.storage.io;version="[5.11.0,5.12.0)", diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedObjectReachabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityTest.java index d2b6e89168..f2f74050b9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedObjectReachabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityTest.java @@ -7,11 +7,12 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.internal.storage.file.GC; import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.revwalk.ObjectReachabilityChecker; public class BitmappedObjectReachabilityTest extends ObjectReachabilityTestCase { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedReachabilityCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityCheckerTest.java index 2cb88b979e..5833c7a81b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedReachabilityCheckerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityCheckerTest.java @@ -7,13 +7,14 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import static org.junit.Assert.assertNotNull; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.internal.storage.file.GC; import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.revwalk.ReachabilityChecker; public class BitmappedReachabilityCheckerTest extends ReachabilityCheckerTestCase { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectReachabilityTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ObjectReachabilityTestCase.java index 267b163f43..37ff40bdf7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectReachabilityTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ObjectReachabilityTestCase.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -20,6 +20,10 @@ import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository.CommitBuilder; +import org.eclipse.jgit.revwalk.ObjectReachabilityChecker; +import org.eclipse.jgit.revwalk.RevBlob; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevObject; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianObjectReachabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/PedestrianObjectReachabilityTest.java index b1c9556df8..f06a768340 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianObjectReachabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/PedestrianObjectReachabilityTest.java @@ -7,10 +7,11 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.revwalk.ObjectReachabilityChecker; public class PedestrianObjectReachabilityTest extends ObjectReachabilityTestCase { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianReachabilityCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityCheckerTest.java index 3029e056eb..f9d4e182a4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianReachabilityCheckerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityCheckerTest.java @@ -7,10 +7,11 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.revwalk.ReachabilityChecker; public class PedestrianReachabilityCheckerTest extends ReachabilityCheckerTestCase { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ReachabilityCheckerTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ReachabilityCheckerTestCase.java index 4695eaa695..1ff6e7defb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ReachabilityCheckerTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ReachabilityCheckerTestCase.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -19,6 +19,8 @@ import java.util.stream.Stream; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.revwalk.ReachabilityChecker; +import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters index 8f1433cf55..b74e703a0c 100644 --- a/org.eclipse.jgit/.settings/.api_filters +++ b/org.eclipse.jgit/.settings/.api_filters @@ -8,4 +8,20 @@ </message_arguments> </filter> </resource> + <resource path="src/org/eclipse/jgit/revwalk/ObjectWalk.java" type="org.eclipse.jgit.revwalk.ObjectWalk"> + <filter id="421654647"> + <message_arguments> + <message_argument value="org.eclipse.jgit.revwalk.ObjectWalk"/> + <message_argument value="createObjectReachabilityChecker()"/> + </message_arguments> + </filter> + </resource> + <resource path="src/org/eclipse/jgit/revwalk/RevWalk.java" type="org.eclipse.jgit.revwalk.RevWalk"> + <filter id="421654647"> + <message_arguments> + <message_argument value="org.eclipse.jgit.revwalk.RevWalk"/> + <message_argument value="createReachabilityChecker()"/> + </message_arguments> + </filter> + </resource> </component> diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF index 9dc26ecb49..47b030ca04 100644 --- a/org.eclipse.jgit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/MANIFEST.MF @@ -72,7 +72,8 @@ Export-Package: org.eclipse.jgit.annotations;version="5.11.0", org.eclipse.jgit.http.test", org.eclipse.jgit.internal.fsck;version="5.11.0"; x-friends:="org.eclipse.jgit.test", - org.eclipse.jgit.internal.revwalk;version="5.11.0";x-internal:=true, + org.eclipse.jgit.internal.revwalk;version="5.11.0"; + x-friends:="org.eclipse.jgit.test", org.eclipse.jgit.internal.storage.dfs;version="5.11.0"; x-friends:="org.eclipse.jgit.test, org.eclipse.jgit.http.server, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmappedObjectReachabilityChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityChecker.java index 89aef7dc41..d8056490aa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmappedObjectReachabilityChecker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityChecker.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import java.io.IOException; import java.util.ArrayList; @@ -21,12 +21,16 @@ import java.util.stream.Stream; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder; +import org.eclipse.jgit.revwalk.BitmapWalker; +import org.eclipse.jgit.revwalk.ObjectReachabilityChecker; +import org.eclipse.jgit.revwalk.ObjectWalk; +import org.eclipse.jgit.revwalk.RevObject; /** * Checks if all objects are reachable from certain starting points using * bitmaps. */ -class BitmappedObjectReachabilityChecker +public class BitmappedObjectReachabilityChecker implements ObjectReachabilityChecker { private final ObjectWalk walk; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmappedReachabilityChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityChecker.java index 0d9c4593bf..37721ad1ea 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmappedReachabilityChecker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityChecker.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import java.io.IOException; import java.util.ArrayList; @@ -23,12 +23,17 @@ import org.eclipse.jgit.lib.BitmapIndex; import org.eclipse.jgit.lib.BitmapIndex.Bitmap; import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.revwalk.ReachabilityChecker; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevFlag; +import org.eclipse.jgit.revwalk.RevSort; +import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.filter.RevFilter; /** * Checks the reachability using bitmaps. */ -class BitmappedReachabilityChecker implements ReachabilityChecker { +public class BitmappedReachabilityChecker implements ReachabilityChecker { private final RevWalk walk; @@ -42,7 +47,7 @@ class BitmappedReachabilityChecker implements ReachabilityChecker { * @throws IOException * if the index or the object reader cannot be opened. */ - BitmappedReachabilityChecker(RevWalk walk) + public BitmappedReachabilityChecker(RevWalk walk) throws IOException { this.walk = walk; if (walk.getObjectReader().getBitmapIndex() == null) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PedestrianObjectReachabilityChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianObjectReachabilityChecker.java index df5d68a66e..1d1f5fddaf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PedestrianObjectReachabilityChecker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianObjectReachabilityChecker.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import java.io.IOException; import java.io.InvalidObjectException; @@ -17,12 +17,18 @@ import java.util.Optional; import java.util.stream.Stream; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.revwalk.ObjectReachabilityChecker; +import org.eclipse.jgit.revwalk.ObjectWalk; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevObject; +import org.eclipse.jgit.revwalk.RevSort; /** * Checks if all objects are reachable from certain starting points doing a * walk. */ -class PedestrianObjectReachabilityChecker implements ObjectReachabilityChecker { +public class PedestrianObjectReachabilityChecker + implements ObjectReachabilityChecker { private final ObjectWalk walk; /** @@ -31,7 +37,7 @@ class PedestrianObjectReachabilityChecker implements ObjectReachabilityChecker { * @param walk * ObjectWalk instance to reuse. Caller retains ownership. */ - PedestrianObjectReachabilityChecker(ObjectWalk walk) { + public PedestrianObjectReachabilityChecker(ObjectWalk walk) { this.walk = walk; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PedestrianReachabilityChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java index 5dc03776c2..a03306b6ee 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PedestrianReachabilityChecker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.revwalk; +package org.eclipse.jgit.internal.revwalk; import java.io.IOException; import java.util.Collection; @@ -17,12 +17,16 @@ import java.util.stream.Stream; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.revwalk.ReachabilityChecker; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevSort; +import org.eclipse.jgit.revwalk.RevWalk; /** * Checks the reachability walking the graph from the starters towards the * target. */ -class PedestrianReachabilityChecker implements ReachabilityChecker { +public class PedestrianReachabilityChecker implements ReachabilityChecker { private final boolean topoSort; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java index 6bb6ae590a..718ed89142 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java @@ -17,9 +17,18 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import org.eclipse.jgit.annotations.NonNull; import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.internal.revwalk.BitmappedObjectReachabilityChecker; +import org.eclipse.jgit.internal.revwalk.BitmappedReachabilityChecker; +import org.eclipse.jgit.internal.revwalk.PedestrianObjectReachabilityChecker; +import org.eclipse.jgit.internal.revwalk.PedestrianReachabilityChecker; +import org.eclipse.jgit.revwalk.ObjectReachabilityChecker; +import org.eclipse.jgit.revwalk.ObjectWalk; +import org.eclipse.jgit.revwalk.ReachabilityChecker; +import org.eclipse.jgit.revwalk.RevWalk; /** * Reads an {@link org.eclipse.jgit.lib.ObjectDatabase} for a single thread. @@ -408,6 +417,54 @@ public abstract class ObjectReader implements AutoCloseable { } /** + * Create a reachability checker that will use bitmaps if possible. + * + * @param rw + * revwalk for use by the reachability checker + * @return the most efficient reachability checker for this repository. + * @throws IOException + * if it cannot open any of the underlying indices. + * + * @since 5.11 + */ + @NonNull + public ReachabilityChecker createReachabilityChecker(RevWalk rw) + throws IOException { + if (getBitmapIndex() != null) { + return new BitmappedReachabilityChecker(rw); + } + + return new PedestrianReachabilityChecker(true, rw); + } + + /** + * Create an object reachability checker that will use bitmaps if possible. + * + * This reachability checker accepts any object as target. For checks + * exclusively between commits, use + * {@link #createReachabilityChecker(RevWalk)}. + * + * @param ow + * objectwalk for use by the reachability checker + * @return the most efficient object reachability checker for this + * repository. + * + * @throws IOException + * if it cannot open any of the underlying indices. + * + * @since 5.11 + */ + @NonNull + public ObjectReachabilityChecker createObjectReachabilityChecker( + ObjectWalk ow) throws IOException { + if (getBitmapIndex() != null) { + return new BitmappedObjectReachabilityChecker(ow); + } + + return new PedestrianObjectReachabilityChecker(ow); + } + + /** * Get the {@link org.eclipse.jgit.lib.ObjectInserter} from which this * reader was created using {@code inserter.newReader()} * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java index 4c7a6f556e..e6f9580bf7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java @@ -172,14 +172,14 @@ public class ObjectWalk extends RevWalk { * when the index fails to load. * * @since 5.8 + * @deprecated use + * {@code ObjectReader#createObjectReachabilityChecker(ObjectWalk)} + * instead. */ - public ObjectReachabilityChecker createObjectReachabilityChecker() + @Deprecated + public final ObjectReachabilityChecker createObjectReachabilityChecker() throws IOException { - if (reader.getBitmapIndex() != null) { - return new BitmappedObjectReachabilityChecker(this); - } - - return new PedestrianObjectReachabilityChecker(this); + return reader.createObjectReachabilityChecker(this); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java index 6b62fcdf6d..631d861c0d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java @@ -236,13 +236,13 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * if it cannot open any of the underlying indices. * * @since 5.4 + * @deprecated use {@code ObjectReader#createReachabilityChecker(RevWalk)} + * instead. */ - public ReachabilityChecker createReachabilityChecker() throws IOException { - if (reader.getBitmapIndex() != null) { - return new BitmappedReachabilityChecker(this); - } - - return new PedestrianReachabilityChecker(true, this); + @Deprecated + public final ReachabilityChecker createReachabilityChecker() + throws IOException { + return reader.createReachabilityChecker(this); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index e0b86f5c11..7f1ddaab2e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1959,8 +1959,8 @@ public class UploadPack { .map(objId -> objectIdToRevObject(objWalk, objId)) .filter(Objects::nonNull); // Ignore missing tips - ObjectReachabilityChecker reachabilityChecker = objWalk - .createObjectReachabilityChecker(); + ObjectReachabilityChecker reachabilityChecker = reader + .createObjectReachabilityChecker(objWalk); Optional<RevObject> unreachable = reachabilityChecker .areAllReachable(wantsAsObjs, startersAsObjs); if (unreachable.isPresent()) { @@ -1971,8 +1971,8 @@ public class UploadPack { } // All wants are commits, we can use ReachabilityChecker - ReachabilityChecker reachabilityChecker = walk - .createReachabilityChecker(); + ReachabilityChecker reachabilityChecker = reader + .createReachabilityChecker(walk); Stream<RevCommit> reachableCommits = importantRefsFirst(visibleRefs) .map(UploadPack::refToObjectId) |