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 eccaa5514..4319fedd6 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 added = new HashSet(); @@ -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 filters = new ArrayList( + 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);