[EGIT PATCH 05/26] Allow AbstractTreeIterators to find out about StopWalkExceptions

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

 



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 <spearce@xxxxxxxxxxx>
---
 .../jgit/treewalk/AbstractTreeIterator.java        |   11 +++++++++++
 .../spearce/jgit/treewalk/EmptyTreeIterator.java   |    6 ++++++
 .../src/org/spearce/jgit/treewalk/TreeWalk.java    |    2 ++
 3 files changed, 19 insertions(+), 0 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 6d7159c..98fec09 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.
+	 * <p>
+	 * 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 09d2bde..c5dc4ad 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 d4050ec..1d842bc 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;
 		}
 	}
-- 
1.6.0.rc2.22.g71b99

--
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