]> source.dussan.org Git - jgit.git/commitdiff
CommitGraphWriter: use ANY_DIFF instead of idEquals inside next() 65/1195565/3
authorIvan Frade <ifrade@google.com>
Fri, 31 May 2024 19:20:07 +0000 (12:20 -0700)
committerIvan Frade <ifrade@google.com>
Fri, 31 May 2024 20:41:09 +0000 (13:41 -0700)
Calculating the paths modified in a commit respect its parents is
taking undue amount of time in big trees.

Use ANY_DIFF filter, instead of #idEquals() inside the #next(). This
shorcuts the tree browsing earlier.

Change-Id: I318eee3ae817b7b9004d60bdb8d0f1bf19b9962d

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriterTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java

index 7130d59b95ed7d5ee74acf267bee8c4d74df3344..80a0f0cea52d31476c8fb1c469ed4088e48c8882 100644 (file)
@@ -435,6 +435,8 @@ public class CommitGraphWriterTest extends RepositoryTestCase {
                                .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 {
index 37a0de84c45a6ade8e6375df8f12472a16425295..55539e2a668ec478a497c1dfdea52475f06c6b89 100644 (file)
@@ -52,6 +52,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
 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;
 
 /**
@@ -447,12 +448,18 @@ public class CommitGraphWriter {
 
        // 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 {
@@ -460,9 +467,7 @@ public class CommitGraphWriter {
                                }
                                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++) {