From f799b5d6b51c05ddfe7ed36ad4e3846506133a20 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 11 Aug 2008 18:07:52 -0700 Subject: [PATCH] Allow AbstractTreeIterators to find out about StopWalkExceptions If a tree iterator has overridden skip() to specially handle entries which the TreeWalk has decided are not relevant then it might also need to pay attention to a StopWalkException. The SWE is thrown out of a filter and behaves much like skip, except it skips everything else in the tree. This is used by PathFilterGroup to break out of a walk once we know that no additional records could ever match. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/treewalk/AbstractTreeIterator.java | 11 +++++++++++ .../src/org/spearce/jgit/treewalk/EmptyTreeIterator.java | 6 ++++++ org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java | 2 ++ 3 files changed, 19 insertions(+) diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java index c9c9f8a9..232204a3 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java @@ -391,4 +391,15 @@ public abstract class AbstractTreeIterator { public void skip() throws CorruptObjectException { next(); } + + /** + * Indicates to the iterator that no more entries will be read. + *

+ * This is only invoked by TreeWalk when the iteration is aborted early due + * to a {@link org.spearce.jgit.errors.StopWalkException} being thrown from + * within a TreeFilter. + */ + public void stopWalk() { + // Do nothing by default. Most iterators do not care. + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/EmptyTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/EmptyTreeIterator.java index 09d2bde7..c5dc4adb 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/EmptyTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/EmptyTreeIterator.java @@ -87,4 +87,10 @@ public class EmptyTreeIterator extends AbstractTreeIterator { public void next() throws CorruptObjectException { // Do nothing. } + + @Override + public void stopWalk() { + if (parent != null) + parent.stopWalk(); + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java index 6824a0e6..969ee3fb 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java @@ -408,6 +408,8 @@ public class TreeWalk { return true; } } catch (StopWalkException stop) { + for (final AbstractTreeIterator t : trees) + t.stopWalk(); return false; } } -- 2.11.4.GIT