Browse Source

Merge "Allow setting a filter in IndexDiff"

stable-0.10
Christian Halstrick 14 years ago committed by Code Review
parent
commit
c234860765
  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; package org.eclipse.jgit.lib;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
@ -84,6 +86,8 @@ public class IndexDiff {
private final RevTree tree; private final RevTree tree;
private TreeFilter filter = null;
private final WorkingTreeIterator initialWorkingTreeIterator; private final WorkingTreeIterator initialWorkingTreeIterator;
private HashSet<String> added = new HashSet<String>(); private HashSet<String> added = new HashSet<String>();
@ -140,6 +144,15 @@ public class IndexDiff {
this.initialWorkingTreeIterator = workingTreeIterator; 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 * 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 EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(dirCache)); treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(initialWorkingTreeIterator); treeWalk.addTree(initialWorkingTreeIterator);
treeWalk.setFilter(TreeFilter.ANY_DIFF); Collection<TreeFilter> filters = new ArrayList<TreeFilter>(
treeWalk.setFilter(AndTreeFilter.create(new TreeFilter[] { filter == null ? 3 : 4);
new NotIgnoredFilter(WORKDIR), new SkipWorkTreeFilter(INDEX), if (filter != null)
TreeFilter.ANY_DIFF })); 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()) { while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE, AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
AbstractTreeIterator.class); AbstractTreeIterator.class);

Loading…
Cancel
Save