Browse Source

Allow setting a filter in IndexDiff

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>
stable-0.10
Jens Baumgart 14 years ago
parent
commit
6f3b089188
  1. 25
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

25
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);

Loading…
Cancel
Save