summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-12-08 12:05:48 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-12-10 17:17:22 -0800
commit45a020fe6a1ed4a7a9f8c46ab81dd4e655211941 (patch)
treef8574b5324a5ffee0b9c541004f88026a897b4bc
parent9b039b42e0ecf69640c5f1a34ee72a86dba3f1c2 (diff)
downloadjgit-45a020fe6a1ed4a7a9f8c46ab81dd4e655211941.tar.gz
jgit-45a020fe6a1ed4a7a9f8c46ab81dd4e655211941.zip
DiffFormatter: Use IndexDiffFilter to speed up working tree
If DiffFormatter is asked to compare the index to the working tree, it can go faster by using the cached stat information to compare the two entries rather than relying on SHA-1 computation alone. Change-Id: Icb21c15b8279ee8cee382e5e179e0cf8903aee4d Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java42
1 files changed, 27 insertions, 15 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index adcf0d8d60..abab3c30c0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -65,6 +65,7 @@ import java.util.List;
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
+import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.LargeObjectException;
@@ -91,7 +92,9 @@ import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
+import org.eclipse.jgit.treewalk.filter.IndexDiffFilter;
import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.QuotedString;
import org.eclipse.jgit.util.io.DisabledOutputStream;
@@ -435,15 +438,14 @@ public class DiffFormatter {
walk.addTree(b);
walk.setRecursive(true);
- TreeFilter filter = pathFilter;
-
- if (a instanceof WorkingTreeIterator)
- filter = AndTreeFilter.create(filter, new NotIgnoredFilter(0));
- if (b instanceof WorkingTreeIterator)
- filter = AndTreeFilter.create(filter, new NotIgnoredFilter(1));
- if (!(pathFilter instanceof FollowFilter))
- filter = AndTreeFilter.create(filter, TreeFilter.ANY_DIFF);
- walk.setFilter(filter);
+ TreeFilter filter = getDiffTreeFilterFor(a, b);
+ if (pathFilter instanceof FollowFilter) {
+ walk.setFilter(AndTreeFilter.create(
+ PathFilter.create(((FollowFilter) pathFilter).getPath()),
+ filter));
+ } else {
+ walk.setFilter(AndTreeFilter.create(pathFilter, filter));
+ }
source = new ContentSource.Pair(source(a), source(b));
@@ -458,12 +460,6 @@ public class DiffFormatter {
walk.reset();
walk.addTree(a);
walk.addTree(b);
-
- filter = TreeFilter.ANY_DIFF;
- if (a instanceof WorkingTreeIterator)
- filter = AndTreeFilter.create(new NotIgnoredFilter(0), filter);
- if (b instanceof WorkingTreeIterator)
- filter = AndTreeFilter.create(new NotIgnoredFilter(1), filter);
walk.setFilter(filter);
if (renameDetector == null)
@@ -476,6 +472,22 @@ public class DiffFormatter {
return files;
}
+ private static TreeFilter getDiffTreeFilterFor(AbstractTreeIterator a,
+ AbstractTreeIterator b) {
+ if (a instanceof DirCacheIterator && b instanceof WorkingTreeIterator)
+ return new IndexDiffFilter(0, 1);
+
+ if (a instanceof WorkingTreeIterator && b instanceof DirCacheIterator)
+ return new IndexDiffFilter(1, 0);
+
+ TreeFilter filter = TreeFilter.ANY_DIFF;
+ if (a instanceof WorkingTreeIterator)
+ filter = AndTreeFilter.create(new NotIgnoredFilter(0), filter);
+ if (b instanceof WorkingTreeIterator)
+ filter = AndTreeFilter.create(new NotIgnoredFilter(1), filter);
+ return filter;
+ }
+
private ContentSource source(AbstractTreeIterator iterator) {
if (iterator instanceof WorkingTreeIterator)
return ContentSource.create((WorkingTreeIterator) iterator);