.map(b -> StandardCharsets.UTF_8.decode(b).toString())
.collect(toList());
assertThat(asString, containsInAnyOrder("d", "d/sd2", "d/sd2/f2"));
+ // We don't walk into d/sd1/f1
+ assertEquals(1, c.stepCounter);
}
RevCommit commit(RevCommit... parents) throws Exception {
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.NB;
/**
// Visible for testing
static class PathDiffCalculator {
+
+ // Walk steps in the last invocation of changedPaths
+ int stepCounter;
+
Optional<HashSet<ByteBuffer>> changedPaths(
ObjectReader or, RevCommit cmit) throws MissingObjectException,
IncorrectObjectTypeException, CorruptObjectException, IOException {
+ stepCounter = 0;
HashSet<ByteBuffer> paths = new HashSet<>();
try (TreeWalk walk = new TreeWalk(null, or)) {
walk.setRecursive(true);
+ walk.setFilter(TreeFilter.ANY_DIFF);
if (cmit.getParentCount() == 0) {
walk.addTree(new EmptyTreeIterator());
} else {
}
walk.addTree(cmit.getTree());
while (walk.next()) {
- if (walk.idEqual(0, 1)) {
- continue;
- }
+ stepCounter += 1;
byte[] rawPath = walk.getRawPath();
paths.add(ByteBuffer.wrap(rawPath));
for (int i = 0; i < rawPath.length; i++) {