git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>,
	Marek Zawirski <marek.zawirski@gmail.com>
Cc: git@vger.kernel.org
Subject: [EGIT PATCH 03/11] Notify AbstractTreeIterator implementations of skipped tree entries
Date: Sun, 10 Aug 2008 01:46:18 -0700	[thread overview]
Message-ID: <1218357986-19671-4-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1218357986-19671-3-git-send-email-spearce@spearce.org>

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@spearce.org>
---
 .../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

  reply	other threads:[~2008-08-10  8:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-10  8:46 [EGIT PATCH 00/11] Misc. cleanups and improvements Shawn O. Pearce
2008-08-10  8:46 ` [EGIT PATCH 01/11] Fix RawParseUtils.endOfParagraph to work on all corner cases Shawn O. Pearce
2008-08-10  8:46   ` [EGIT PATCH 02/11] Add test case for the RevCommit parsing code Shawn O. Pearce
2008-08-10  8:46     ` Shawn O. Pearce [this message]
2008-08-10  8:46       ` [EGIT PATCH 04/11] Allow AbstractTreeIterator subclasses to supply their own path array Shawn O. Pearce
2008-08-10  8:46         ` [EGIT PATCH 05/11] Allow WorkingTreeIterators to define their prefix path when created Shawn O. Pearce
2008-08-10  8:46           ` [EGIT PATCH 06/11] Add getTree to TreeWalk for locating the current iterator instance Shawn O. Pearce
2008-08-10  8:46             ` [EGIT PATCH 07/11] Allow WorkingTreeIterator to track last modified time for entries Shawn O. Pearce
2008-08-10  8:46               ` [EGIT PATCH 08/11] Expose the current entry's length, last modified in WorkingTreeIterator Shawn O. Pearce
2008-08-10  8:46                 ` [EGIT PATCH 09/11] Expose idBuffer,idOffset in AbstractTreeIterator to applications Shawn O. Pearce
2008-08-10  8:46                   ` [EGIT PATCH 10/11] Add a TreeWalk iterator implementation for IContainer Shawn O. Pearce
2008-08-10  8:46                     ` [EGIT PATCH 11/11] Teach NB how to encode/decode an unsigned 16 bit integer Shawn O. Pearce
2008-08-13 20:41                     ` [EGIT PATCH 10/11] Add a TreeWalk iterator implementation for IContainer Robin Rosenberg
2008-08-14  4:19                       ` Shawn O. Pearce
2008-08-14  5:20                         ` Robin Rosenberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1218357986-19671-4-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=marek.zawirski@gmail.com \
    --cc=robin.rosenberg@dewire.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).