summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2012-10-06 13:08:16 +0200
committerRobin Rosenberg <robin.rosenberg@dewire.com>2012-10-06 13:08:16 +0200
commit45edb41a9ed1248964cb4bf0d635f2643406d123 (patch)
tree2dbd5344d2cd59dc5ea3755b95d940a7207e120f
parent046a497d7774193c019d53fecc64d0a4b2e7d929 (diff)
downloadjgit-45edb41a9ed1248964cb4bf0d635f2643406d123.tar.gz
jgit-45edb41a9ed1248964cb4bf0d635f2643406d123.zip
Fix for Iff768422c, use offset 0 when going back to work tree iterator
In Iff768422c the offset used for the content id was fixed to use the offset that applied to the dircache iterator. Unfortunately the index for the dircache content id offset stuck for entries that were not in the index. Few caller probably cared about that, unless it actually caused an ArrayIndexOutOfBoundsException. Change-Id: Ic9f0e77c8ea3a0770d88565e94392e76853e3006
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java41
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java2
2 files changed, 43 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
index 209b2b8377..a06149e844 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
@@ -49,6 +49,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.IOException;
import java.security.MessageDigest;
import org.eclipse.jgit.api.Git;
@@ -58,6 +59,9 @@ import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
+import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
@@ -429,6 +433,43 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertTrue(indexIter.idEqual(workTreeIter));
}
+ @Test
+ public void idOffset() throws Exception {
+ Git git = new Git(db);
+ writeTrashFile("fileAinfsonly", "A");
+ File fileBinindex = writeTrashFile("fileBinindex", "B");
+ fsTick(fileBinindex);
+ git.add().addFilepattern("fileBinindex").call();
+ writeTrashFile("fileCinfsonly", "C");
+ TreeWalk tw = new TreeWalk(db);
+ DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
+ FileTreeIterator workTreeIter = new FileTreeIterator(db);
+ tw.addTree(indexIter);
+ tw.addTree(workTreeIter);
+ workTreeIter.setDirCacheIterator(tw, 0);
+ assertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw);
+ assertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw);
+ assertEntry("0000000000000000000000000000000000000000", "a", tw);
+ assertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw);
+ // The reason for adding this test. Check that the id is correct for
+ // mixed
+ assertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220",
+ "fileAinfsonly", tw);
+ assertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex",
+ tw);
+ assertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c",
+ "fileCinfsonly", tw);
+ assertFalse(tw.next());
+ }
+
+ private void assertEntry(String sha1string, String path, TreeWalk tw)
+ throws MissingObjectException, IncorrectObjectTypeException,
+ CorruptObjectException, IOException {
+ assertTrue(tw.next());
+ assertEquals(path, tw.getPathString());
+ assertEquals(sha1string, tw.getObjectId(1).getName() /* 1=filetree here */);
+ }
+
private static String nameOf(final AbstractTreeIterator i) {
return RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
index 8d0555bf95..9ee5f8b11d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -243,6 +243,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
return contentId = i.idBuffer();
}
contentIdOffset = 0;
+ } else {
+ contentIdOffset = 0;
}
}
switch (mode & FileMode.TYPE_MASK) {