diff options
author | Dave Borowitz <dborowitz@google.com> | 2012-12-27 09:29:44 -0800 |
---|---|---|
committer | Dave Borowitz <dborowitz@google.com> | 2012-12-27 12:24:50 -0800 |
commit | 75eb6a147ffa8089e48d409f0215a16c755305e7 (patch) | |
tree | 81f5f5c0907403946d5db23765364efe012033bb /org.eclipse.jgit | |
parent | 154e3c886bafc429fe310d40741be34e5e4c87c9 (diff) | |
download | jgit-75eb6a147ffa8089e48d409f0215a16c755305e7.tar.gz jgit-75eb6a147ffa8089e48d409f0215a16c755305e7.zip |
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
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java index d85ea8cc5d..365a820981 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.treewalk.filter; +import org.eclipse.jgit.errors.StopWalkException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.treewalk.TreeWalk; @@ -97,7 +98,10 @@ public class PathFilter extends TreeFilter { @Override 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 |