[EGIT PATCH 03/11] Notify AbstractTreeIterator implementations of skipped tree entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <spearce@xxxxxxxxxxx>
---
 .../jgit/treewalk/AbstractTreeIterator.java        |   16 ++++++++++++++++
 .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   13 ++++++++++++-
 2 files changed, 28 insertions(+), 1 deletions(-)

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 448c547..0c0257c 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.
+	 * <p>
+	 * 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 42f8b25..7ea16b5 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++)
-- 
1.6.0.rc2.219.g1250ab

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux