1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.internal.revwalk;
11
12 import java.io.IOException;
13 import java.util.Collection;
14 import java.util.Iterator;
15 import java.util.Optional;
16 import java.util.stream.Stream;
17
18 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
19 import org.eclipse.jgit.errors.MissingObjectException;
20 import org.eclipse.jgit.revwalk.ReachabilityChecker;
21 import org.eclipse.jgit.revwalk.RevCommit;
22 import org.eclipse.jgit.revwalk.RevSort;
23 import org.eclipse.jgit.revwalk.RevWalk;
24
25
26
27
28
29 public class PedestrianReachabilityChecker implements ReachabilityChecker {
30
31 private final boolean topoSort;
32
33 private final RevWalk walk;
34
35
36
37
38
39
40
41
42
43 public PedestrianReachabilityChecker(boolean topoSort,
44 RevWalk walk) {
45 this.topoSort = topoSort;
46 this.walk = walk;
47 }
48
49 @Override
50 public Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
51 Stream<RevCommit> starters)
52 throws MissingObjectException, IncorrectObjectTypeException,
53 IOException {
54 walk.reset();
55 if (topoSort) {
56 walk.sort(RevSort.TOPO);
57 }
58
59 for (RevCommit target: targets) {
60 walk.markStart(target);
61 }
62
63 Iterator<RevCommit> iterator = starters.iterator();
64 while (iterator.hasNext()) {
65 walk.markUninteresting(iterator.next());
66 }
67
68 return Optional.ofNullable(walk.next());
69 }
70 }