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