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/internal/storage/file/FileSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java index 5ab973f53..6088c152a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java @@ -420,15 +420,6 @@ public boolean equals(Object obj) { return equals(other); } - /** - * Check if the file exists - * - * @return true if the file exists - */ - public boolean fileExists() { - return !MISSING_FILEKEY.equals(this.fileKey); - } - /** {@inheritDoc} */ @Override public int hashCode() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 2167262dd..07e38147f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -1092,10 +1092,6 @@ LooseRef scanRef(LooseRef ref, String name) throws IOException { final int limit = 4096; final byte[] buf; FileSnapshot otherSnapshot = FileSnapshot.save(path); - if (!otherSnapshot.fileExists()) { - return null; - } - try { buf = IO.readSome(path, limit); } catch (FileNotFoundException noFile) { 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.