diff options
author | Ivan Frade <ifrade@google.com> | 2020-04-01 22:10:09 -0700 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2020-04-28 16:40:52 -0700 |
commit | ae26fa19b7945960fc6e8bf2ab64ec128836ea6d (patch) | |
tree | a795e72e7df373434e3526777ce92841049e6601 /org.eclipse.jgit/src/org/eclipse/jgit/transport | |
parent | df81c56524e578f569ea12854526c1461ac6e42d (diff) | |
download | jgit-ae26fa19b7945960fc6e8bf2ab64ec128836ea6d.tar.gz jgit-ae26fa19b7945960fc6e8bf2ab64ec128836ea6d.zip |
UploadPack: Extract walk-based reachability check
Preparing the code to optimize the bitmap-based object reachability
checker. We are mirroring first the commit reachability checker
structure (interface + 2 implementations).
Move the walk-base reachability checker to its own class.
This class is public at the moment. Later ObjectWalk will return an
interface and this implementation will be package-private.
Change-Id: Ifac70094e1af137291c3607d95e689992f814b26
Signed-off-by: Ivan Frade <ifrade@google.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 45 |
1 files changed, 12 insertions, 33 deletions
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 bb826d8810..0552909c51 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -80,12 +80,12 @@ import org.eclipse.jgit.revwalk.AsyncRevObjectQueue; import org.eclipse.jgit.revwalk.BitmapWalker; import org.eclipse.jgit.revwalk.DepthWalk; import org.eclipse.jgit.revwalk.ObjectWalk; +import org.eclipse.jgit.revwalk.PedestrianObjectReachabilityChecker; import org.eclipse.jgit.revwalk.ReachabilityChecker; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevFlag; import org.eclipse.jgit.revwalk.RevFlagSet; import org.eclipse.jgit.revwalk.RevObject; -import org.eclipse.jgit.revwalk.RevSort; import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter; @@ -1910,36 +1910,6 @@ public class UploadPack { } } - private static void checkReachabilityByWalkingObjects(ObjectWalk walk, - List<RevObject> wants, Set<ObjectId> reachableFrom) throws IOException { - - walk.sort(RevSort.TOPO); - for (RevObject want : wants) { - walk.markStart(want); - } - for (ObjectId have : reachableFrom) { - RevObject o = walk.parseAny(have); - walk.markUninteresting(o); - - RevObject peeled = walk.peel(o); - if (peeled instanceof RevCommit) { - // By default, for performance reasons, ObjectWalk does not mark a - // tree as uninteresting when we mark a commit. Mark it ourselves so - // that we can determine reachability exactly. - walk.markUninteresting(((RevCommit) peeled).getTree()); - } - } - - RevCommit commit = walk.next(); - if (commit != null) { - throw new WantNotValidException(commit); - } - RevObject object = walk.nextObject(); - if (object != null) { - throw new WantNotValidException(object); - } - } - private static void checkNotAdvertisedWants(UploadPack up, List<ObjectId> notAdvertisedWants, Collection<Ref> visibleRefs) throws IOException { @@ -1967,8 +1937,17 @@ public class UploadPack { // operator is willing to pay the cost of these // reachability checks. try (ObjectWalk objWalk = walk.toObjectWalkWithSameObjects()) { - checkReachabilityByWalkingObjects(objWalk, - wantsAsObjs, reachableFrom); + List<RevObject> havesAsObjs = objectIdsToRevObjects( + objWalk, reachableFrom); + PedestrianObjectReachabilityChecker reachabilityChecker = new PedestrianObjectReachabilityChecker( + objWalk); + Optional<RevObject> unreachable = reachabilityChecker + .areAllReachable(wantsAsObjs, + havesAsObjs.stream()); + if (unreachable.isPresent()) { + throw new WantNotValidException( + unreachable.get()); + } } return; } |