Browse Source

RevWalk: new method createReachabilityChecker()

Every caller would need to check if bitmaps are available in the repo to
instantiate a reachability checker.

Offer a method to create the reachability checker in the walk: the
caller has already a walk over the repo, and the walk has all the
information required.

This allows us to make the implementation classes package-private.

Change-Id: I355e47486fcd9d55baa7cb5700ec08dcc230eea5
Signed-off-by: Ivan Frade <ifrade@google.com>
stable-5.5
Ivan Frade 6 years ago committed by Jonathan Nieder
parent
commit
5dce8614ab
  1. 4
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmappedReachabilityChecker.java
  2. 4
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PedestrianReachabilityChecker.java
  3. 17
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
  4. 7
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

4
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmappedReachabilityChecker.java

@ -55,10 +55,8 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
/** /**
* Checks the reachability using bitmaps. * Checks the reachability using bitmaps.
*
* @since 5.4
*/ */
public class BitmappedReachabilityChecker implements ReachabilityChecker { class BitmappedReachabilityChecker implements ReachabilityChecker {
private final RevWalk walk; private final RevWalk walk;

4
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PedestrianReachabilityChecker.java

@ -52,10 +52,8 @@ import org.eclipse.jgit.errors.MissingObjectException;
/** /**
* Checks the reachability walking the graph from the starters towards the * Checks the reachability walking the graph from the starters towards the
* target. * target.
*
* @since 5.4
*/ */
public class PedestrianReachabilityChecker implements ReachabilityChecker { class PedestrianReachabilityChecker implements ReachabilityChecker {
private final boolean topoSort; private final boolean topoSort;

17
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

@ -249,6 +249,23 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
return reader; return reader;
} }
/**
* Get a reachability checker for commits over this revwalk.
*
* @return the most efficient reachability checker for this repository.
* @throws IOException
* if it cannot open any of the underlying indices.
*
* @since 5.4
*/
public ReachabilityChecker createReachabilityChecker() throws IOException {
if (reader.getBitmapIndex() != null) {
return new BitmappedReachabilityChecker(this);
}
return new PedestrianReachabilityChecker(true, this);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* <p> * <p>

7
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -106,10 +106,8 @@ import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.AsyncRevObjectQueue; import org.eclipse.jgit.revwalk.AsyncRevObjectQueue;
import org.eclipse.jgit.revwalk.BitmapWalker; import org.eclipse.jgit.revwalk.BitmapWalker;
import org.eclipse.jgit.revwalk.BitmappedReachabilityChecker;
import org.eclipse.jgit.revwalk.DepthWalk; import org.eclipse.jgit.revwalk.DepthWalk;
import org.eclipse.jgit.revwalk.ObjectWalk; import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.PedestrianReachabilityChecker;
import org.eclipse.jgit.revwalk.ReachabilityChecker; import org.eclipse.jgit.revwalk.ReachabilityChecker;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevFlag; import org.eclipse.jgit.revwalk.RevFlag;
@ -1909,9 +1907,8 @@ public class UploadPack {
} }
// All wants are commits, we can use ReachabilityChecker // All wants are commits, we can use ReachabilityChecker
ReachabilityChecker reachabilityChecker = repoHasBitmaps ReachabilityChecker reachabilityChecker = walk
? new BitmappedReachabilityChecker(walk) .createReachabilityChecker();
: new PedestrianReachabilityChecker(true, walk);
List<RevCommit> starters = objectIdsToRevCommits(walk, List<RevCommit> starters = objectIdsToRevCommits(walk,
reachableFrom); reachableFrom);

Loading…
Cancel
Save