TreeRevFilter: fix wrong stop when the given path disappears

When chgs[i] == adds[i], it indicated that a commit added some files
that pList[i] did not have, but didn't mean pList[i] is "empty tree
root".

Follow the example below:

.                           .
└── src                     └── src
    └── d1          ==>          └── d1
        └─ file1                    ├─  file1
                                    └── file2
   c.parents[i]                   c

The variable chg[i] equals to variable add[i],
but commit c.parents[i] is not "empty tree root".

We should add an additional check for no paths matching the filter.

Bug: 577227
Change-Id: I834e9ddd0de86b108b280a1139519ea962913b38
Signed-off-by: kylezhao <kylezhao@tencent.com>
This commit is contained in:
kylezhao 2021-11-12 14:34:46 +08:00 committed by Matthias Sohn
parent 35713588fe
commit 3d7351ee50
2 changed files with 24 additions and 1 deletions

View File

@ -15,6 +15,7 @@
import java.util.Collections;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
@ -253,4 +254,23 @@ public void testStringOfPearls_FilePath3_NoParentRewriting()
assertEquals(0, a.getParentCount());
assertNull(rw.next());
}
@Test
public void testStopWhenPathDisappears() throws Exception {
DirCacheEntry file1 = file("src/d1/file1", blob("a"));
DirCacheEntry file2 = file("src/d1/file2", blob("a"));
DirCacheEntry file3 = file("src/d1/file3", blob("a"));
RevCommit a = commit(tree(file1));
RevCommit b = commit(tree(file1, file2), a);
RevCommit c = commit(tree(file1, file3), a);
RevCommit d = commit(tree(file1, file2, file3), b, c);
filter("src/d1");
markStart(d);
rw.setRewriteParents(false);
assertCommit(d, rw.next());
assertCommit(c, rw.next());
assertCommit(b, rw.next());
assertCommit(a, rw.next());
}
}

View File

@ -211,7 +211,10 @@ public boolean include(RevWalk walker, RevCommit c)
// "empty tree root" and thus their history is not relevant.
// Cut our grandparents to be an empty list.
//
pList[i].parents = RevCommit.NO_PARENTS;
tw.reset(pList[i].getTree());
if (!tw.next()) {
pList[i].parents = RevCommit.NO_PARENTS;
}
}
// We have an interesting difference relative to this parent.