Browse Source

Stop PathFilter after walking all matching paths

After the current path of the TreeWalk is no longer a prefix of the
PathFilter's path, there can be no more matching entries, but TreeWalk
will happily keep walking the rest of a (potentially very large and
recursive) tree unless StopWalkException is thrown. So, throw
StopWalkException from PathFilter.include() at the earliest
opportunity.

Change-Id: If6c4f395a3d5ed5b71bf68de23be9f2b0620e7f1
stable-2.3
Dave Borowitz 12 years ago
parent
commit
75eb6a147f
  1. 6
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java

6
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java

@ -44,6 +44,7 @@
package org.eclipse.jgit.treewalk.filter; package org.eclipse.jgit.treewalk.filter;
import org.eclipse.jgit.errors.StopWalkException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
@ -97,7 +98,10 @@ public class PathFilter extends TreeFilter {
@Override @Override
public boolean include(final TreeWalk walker) { public boolean include(final TreeWalk walker) {
return walker.isPathPrefix(pathRaw, pathRaw.length) == 0; int cmp = walker.isPathPrefix(pathRaw, pathRaw.length);
if (cmp > 0)
throw StopWalkException.INSTANCE;
return cmp == 0;
} }
@Override @Override

Loading…
Cancel
Save