From 3d7351ee50b2ef45613b2223856f31e5af1c7ca1 Mon Sep 17 00:00:00 2001 From: kylezhao Date: Fri, 12 Nov 2021 14:34:46 +0800 Subject: [PATCH] TreeRevFilter: fix wrong stop when the given path disappears MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../jgit/revwalk/RevWalkPathFilter1Test.java | 20 +++++++++++++++++++ .../eclipse/jgit/revwalk/TreeRevFilter.java | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java index 31629f3de..5cce11aa1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java @@ -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()); + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java index e46502431..822fc5320 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java @@ -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.