From cbe13b151906abde49cf16b63b4d50eabf1d4090 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 10 Aug 2008 01:46:18 -0700 Subject: [PATCH] Notify AbstractTreeIterator implementations of skipped tree entries Some tree iterators may benefit from knowing when their driving TreeWalk has chosen to skip past their current entry and not report it to client applications. This can be useful for an index update scenario where the client application has applied a TreeFilter to only see the entries that it wants to modify in this session. By default the new skip() method just calls next(), as most types of the tree iterator do not have this distinction between skipped entry and a non-skipped entry. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../org/spearce/jgit/treewalk/AbstractTreeIterator.java | 16 ++++++++++++++++ .../src/org/spearce/jgit/treewalk/TreeWalk.java | 13 ++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) 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 448c5474..3d4b5bb3 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java @@ -46,6 +46,7 @@ import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.FileMode; import org.spearce.jgit.lib.ObjectId; import org.spearce.jgit.lib.Repository; +import org.spearce.jgit.treewalk.filter.TreeFilter; /** * Walks a Git tree (directory) in Git sort order. @@ -316,4 +317,19 @@ public abstract class AbstractTreeIterator { * the tree is invalid. */ public abstract void next() throws CorruptObjectException; + + /** + * Advance to the next tree entry, populating this iterator with its data. + *

+ * This method behaves like {@link #next()} but is called by + * {@link TreeWalk} only if a {@link TreeFilter} was used and ruled out the + * current entry from the results. In such cases this tree iterator may + * perform special behavior. + * + * @throws CorruptObjectException + * the tree is invalid. + */ + public void skip() throws CorruptObjectException { + next(); + } } 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 42f8b255..7ea16b51 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java @@ -395,7 +395,7 @@ public class TreeWalk { currentHead = t; if (!filter.include(this)) { - popEntriesEqual(); + skipEntriesEqual(); continue; } @@ -635,6 +635,17 @@ public class TreeWalk { } } + private void skipEntriesEqual() throws CorruptObjectException { + final AbstractTreeIterator ch = currentHead; + for (int i = 0; i < trees.length; i++) { + final AbstractTreeIterator t = trees[i]; + if (t.matches == ch) { + t.skip(); + t.matches = null; + } + } + } + private void exitSubtree() throws CorruptObjectException { depth--; for (int i = 0; i < trees.length; i++) -- 2.11.4.GIT