aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java
new file mode 100644
index 0000000000..a03306b6ee
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/revwalk/PedestrianReachabilityChecker.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2019, Google LLC. and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.internal.revwalk;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Optional;
+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.
+ */
+public class PedestrianReachabilityChecker implements ReachabilityChecker {
+
+ private final boolean topoSort;
+
+ private final RevWalk walk;
+
+ /**
+ * New instance of the reachability checker using a existing walk.
+ *
+ * @param topoSort
+ * walk commits in topological order
+ * @param walk
+ * RevWalk instance to reuse. Caller retains ownership.
+ */
+ public PedestrianReachabilityChecker(boolean topoSort,
+ RevWalk walk) {
+ this.topoSort = topoSort;
+ this.walk = walk;
+ }
+
+ @Override
+ public Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
+ Stream<RevCommit> starters)
+ throws MissingObjectException, IncorrectObjectTypeException,
+ IOException {
+ walk.reset();
+ if (topoSort) {
+ walk.sort(RevSort.TOPO);
+ }
+
+ for (RevCommit target: targets) {
+ walk.markStart(target);
+ }
+
+ Iterator<RevCommit> iterator = starters.iterator();
+ while (iterator.hasNext()) {
+ walk.markUninteresting(iterator.next());
+ }
+
+ return Optional.ofNullable(walk.next());
+ }
+}