Browse Source

IndexDiff: Use isModified() when comparing index-worktree

The isModified() is more efficient because it can skip over files that
are stat clean, without needing to scan them.

This is useful to efficently work on paths that were already staged
and thus differ between HEAD and the index, but not between the index
and the working tree.

Change-Id: I4418202e612f0571974e0898050d987c6c280966
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.10
Shawn O. Pearce 14 years ago
parent
commit
a66a7d90fd
  1. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
  2. 3
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

@ -252,8 +252,10 @@ public class IndexDiffTest extends RepositoryTestCase {
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff(); diff.diff();
assertEquals(1, diff.getAssumeUnchanged().size()); assertEquals(1, diff.getAssumeUnchanged().size());
assertEquals(2, diff.getModified().size()); assertEquals(1, diff.getModified().size());
assertEquals(0, diff.getChanged().size()); assertEquals(0, diff.getChanged().size());
assertTrue(diff.getAssumeUnchanged().contains("file2"));
assertTrue(diff.getModified().contains("file"));
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
@ -261,10 +263,9 @@ public class IndexDiffTest extends RepositoryTestCase {
diff = new IndexDiff(db, Constants.HEAD, iterator); diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff(); diff.diff();
assertEquals(1, diff.getAssumeUnchanged().size()); assertEquals(1, diff.getAssumeUnchanged().size());
assertEquals(1, diff.getModified().size()); assertEquals(0, diff.getModified().size());
assertEquals(1, diff.getChanged().size()); assertEquals(1, diff.getChanged().size());
assertTrue(diff.getAssumeUnchanged().contains("file2")); assertTrue(diff.getAssumeUnchanged().contains("file2"));
assertTrue(diff.getModified().contains("file2"));
assertTrue(diff.getChanged().contains("file")); assertTrue(diff.getChanged().contains("file"));
} }

3
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

@ -232,7 +232,8 @@ public class IndexDiff {
missing.add(treeWalk.getPathString()); missing.add(treeWalk.getPathString());
changesExist = true; changesExist = true;
} else { } else {
if (!dirCacheIterator.idEqual(workingTreeIterator)) { if (workingTreeIterator.isModified(
dirCacheIterator.getDirCacheEntry(), true)) {
// in index, in workdir, content differs => modified // in index, in workdir, content differs => modified
modified.add(treeWalk.getPathString()); modified.add(treeWalk.getPathString());
changesExist = true; changesExist = true;

Loading…
Cancel
Save