1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.revwalk;
11
12 import java.io.IOException;
13 import java.io.InvalidObjectException;
14 import java.util.Collection;
15 import java.util.Iterator;
16 import java.util.Optional;
17 import java.util.stream.Stream;
18
19 import org.eclipse.jgit.errors.MissingObjectException;
20
21
22
23
24
25 class PedestrianObjectReachabilityChecker implements ObjectReachabilityChecker {
26 private final ObjectWalk walk;
27
28
29
30
31
32
33
34 PedestrianObjectReachabilityChecker(ObjectWalk walk) {
35 this.walk = walk;
36 }
37
38
39
40
41 @Override
42 public Optional<RevObject> areAllReachable(Collection<RevObject> targets,
43 Stream<RevObject> starters) throws IOException {
44 try {
45 walk.reset();
46 walk.sort(RevSort.TOPO);
47 for (RevObject target : targets) {
48 walk.markStart(target);
49 }
50
51 Iterator<RevObject> iterator = starters.iterator();
52 while (iterator.hasNext()) {
53 RevObject o = iterator.next();
54 walk.markUninteresting(o);
55
56 RevObject peeled = walk.peel(o);
57 if (peeled instanceof RevCommit) {
58
59
60
61
62 walk.markUninteresting(((RevCommit) peeled).getTree());
63 }
64 }
65
66 RevCommit commit = walk.next();
67 if (commit != null) {
68 return Optional.of(commit);
69 }
70
71 RevObject object = walk.nextObject();
72 if (object != null) {
73 return Optional.of(object);
74 }
75
76 return Optional.empty();
77 } catch (MissingObjectException | InvalidObjectException e) {
78 throw new IllegalStateException(e);
79 }
80 }
81 }