Browse Source

Fix idOffset when the working tree iterator matches a dircache entry

idOffset is not zero when idBuffer comes from blob in the dircache

Change-Id: Iff768422cba140a5d6a776e2c627b852f079c1da
stable-2.1
Robin Rosenberg 12 years ago
parent
commit
342de38e57
  1. 25
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
  2. 14
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

25
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java

@ -197,6 +197,31 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertEquals(expect, top.getEntryObjectId()); assertEquals(expect, top.getEntryObjectId());
} }
@Test
public void testDirCacheMatchingId() throws Exception {
File f = writeTrashFile("file", "content");
Git git = new Git(db);
writeTrashFile("file", "content");
fsTick(f);
git.add().addFilepattern("file").call();
DirCacheEntry dce = db.readDirCache().getEntry("file");
TreeWalk tw = new TreeWalk(db);
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
.getConfig().get(WorkingTreeOptions.KEY));
tw.addTree(fti);
DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
tw.addTree(dci);
fti.setDirCacheIterator(tw, 1);
while (tw.next() && !tw.getPathString().equals("file")) {
//
}
assertEquals(MetadataDiff.EQUAL, fti.compareMetadata(dce));
ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
fromRaw.getName());
assertFalse(fti.isModified(dce, false));
}
@Test @Test
public void testIsModifiedSymlink() throws Exception { public void testIsModifiedSymlink() throws Exception {
File f = writeTrashFile("symlink", "content"); File f = writeTrashFile("symlink", "content");

14
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

@ -131,6 +131,9 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
/** Cached canonical length, initialized from {@link #idBuffer()} */ /** Cached canonical length, initialized from {@link #idBuffer()} */
private long canonLen = -1; private long canonLen = -1;
/** The offset of the content id in {@link #idBuffer()} */
private int contentIdOffset;
/** /**
* Create a new iterator with no parent. * Create a new iterator with no parent.
* *
@ -234,11 +237,14 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
DirCacheIterator.class); DirCacheIterator.class);
if (i != null) { if (i != null) {
DirCacheEntry ent = i.getDirCacheEntry(); DirCacheEntry ent = i.getDirCacheEntry();
if (ent != null && compareMetadata(ent) == MetadataDiff.EQUAL) if (ent != null && compareMetadata(ent) == MetadataDiff.EQUAL) {
return i.idBuffer(); contentIdOffset = i.idOffset();
contentIdFromPtr = ptr;
return contentId = i.idBuffer();
}
contentIdOffset = 0;
} }
} }
switch (mode & FileMode.TYPE_MASK) { switch (mode & FileMode.TYPE_MASK) {
case FileMode.TYPE_FILE: case FileMode.TYPE_FILE:
contentIdFromPtr = ptr; contentIdFromPtr = ptr;
@ -427,7 +433,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
@Override @Override
public int idOffset() { public int idOffset() {
return 0; return contentIdOffset;
} }
@Override @Override

Loading…
Cancel
Save