aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2010-10-25 07:00:13 (EDT)
committerJens Baumgart2010-10-25 07:00:13 (EDT)
commit6f3b089188ef4937ab4e9970b0987b061000831e (patch)
tree11471a7502c6de059c6b707a3dce7a7df5277c05
parentd00420ae6ec47419567493ee40b8cfa6525ad93d (diff)
downloadjgit-6f3b089188ef4937ab4e9970b0987b061000831e.zip
jgit-6f3b089188ef4937ab4e9970b0987b061000831e.tar.gz
jgit-6f3b089188ef4937ab4e9970b0987b061000831e.tar.bz2
Allow setting a filter in IndexDiffrefs/changes/79/1779/3
IndexDiff now allows to set an additional filter. This can be used e.g. for restricting the tree walk to a given set of files. Change-Id: I642de17e74b997fa0c5878c90631f6640ed70bdd Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index eccaa55..4319fed 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -46,6 +46,8 @@
package org.eclipse.jgit.lib;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import org.eclipse.jgit.dircache.DirCache;
@@ -84,6 +86,8 @@ public class IndexDiff {
private final RevTree tree;
+ private TreeFilter filter = null;
+
private final WorkingTreeIterator initialWorkingTreeIterator;
private HashSet<String> added = new HashSet<String>();
@@ -140,6 +144,15 @@ public class IndexDiff {
this.initialWorkingTreeIterator = workingTreeIterator;
}
+ /**
+ * Sets a filter. Can be used e.g. for restricting the tree walk to a set of
+ * files.
+ *
+ * @param filter
+ */
+ public void setFilter(TreeFilter filter) {
+ this.filter = filter;
+ }
/**
* Run the diff operation. Until this is called, all lists will be empty
@@ -160,10 +173,14 @@ public class IndexDiff {
treeWalk.addTree(new EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(initialWorkingTreeIterator);
- treeWalk.setFilter(TreeFilter.ANY_DIFF);
- treeWalk.setFilter(AndTreeFilter.create(new TreeFilter[] {
- new NotIgnoredFilter(WORKDIR), new SkipWorkTreeFilter(INDEX),
- TreeFilter.ANY_DIFF }));
+ Collection<TreeFilter> filters = new ArrayList<TreeFilter>(
+ filter == null ? 3 : 4);
+ if (filter != null)
+ filters.add(filter);
+ filters.add(new NotIgnoredFilter(WORKDIR));
+ filters.add(new SkipWorkTreeFilter(INDEX));
+ filters.add(TreeFilter.ANY_DIFF);
+ treeWalk.setFilter(AndTreeFilter.create(filters));
while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
AbstractTreeIterator.class);