[EGIT PATCH 16/20] Support for RevSort.BOUNDARY in ObjectWalk

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

 



When RevSort.BOUNDARY strategy in enabled, ObjectWalk now includes in
nextObjects() all objects associated with boundary commits (trees,
blobs) and all other objects explictly marked as  uninteresting
(boundary).

This behavior is something more than original C git-rev-list offers in
this matter - it is impossible to get such a behavior (to include all
boundary objects, not only commits, at output) directly from:
$ git-rev-list --objects-edge
Here, it is added for compactness - callers usually need also boundary
objects (e.g. for preparing thin-pack). If not, they can still easily
filter out such objects from nextObject() by checking for UNINTERESTING
flag or just use next() if interested only in commits.

Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx>
---
 .../src/org/spearce/jgit/revwalk/ObjectWalk.java   |   26 +++++++++++++++----
 .../src/org/spearce/jgit/revwalk/RevSort.java      |    5 +++-
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java
index 68ed861..81cebbd 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java
@@ -66,8 +66,6 @@ import org.spearce.jgit.treewalk.TreeWalk;
  * commits that are returned first.
  */
 public class ObjectWalk extends RevWalk {
-	private static final int SEEN_OR_UNINTERESTING = SEEN | UNINTERESTING;
-
 	private final TreeWalk treeWalk;
 
 	private BlockObjQueue objects;
@@ -177,6 +175,8 @@ public class ObjectWalk extends RevWalk {
 			IncorrectObjectTypeException, IOException {
 		while (o instanceof RevTag) {
 			o.flags |= UNINTERESTING;
+			if (hasRevSort(RevSort.BOUNDARY))
+				addObject(o);
 			o = ((RevTag) o).getObject();
 			parse(o);
 		}
@@ -187,6 +187,10 @@ public class ObjectWalk extends RevWalk {
 			markTreeUninteresting((RevTree) o);
 		else
 			o.flags |= UNINTERESTING;
+
+		if (o.getType() != Constants.OBJ_COMMIT && hasRevSort(RevSort.BOUNDARY)) {
+			addObject(o);
+		}
 	}
 
 	@Override
@@ -198,8 +202,10 @@ public class ObjectWalk extends RevWalk {
 				return null;
 			if ((r.flags & UNINTERESTING) != 0) {
 				markTreeUninteresting(r.getTree());
-				if (hasRevSort(RevSort.BOUNDARY))
+				if (hasRevSort(RevSort.BOUNDARY)) {
+					objects.add(r.getTree());
 					return r;
+				}
 				continue;
 			}
 			objects.add(r.getTree());
@@ -237,17 +243,23 @@ public class ObjectWalk extends RevWalk {
 			switch (sType) {
 			case Constants.OBJ_BLOB: {
 				final RevObject o = lookupAny(treeWalk.getObjectId(0), sType);
-				if ((o.flags & SEEN_OR_UNINTERESTING) != 0)
+				if ((o.flags & SEEN) != 0)
 					continue;
 				o.flags |= SEEN;
+				if ((o.flags & UNINTERESTING) != 0
+						&& !hasRevSort(RevSort.BOUNDARY))
+					continue;
 				fromTreeWalk = true;
 				return o;
 			}
 			case Constants.OBJ_TREE: {
 				final RevObject o = lookupAny(treeWalk.getObjectId(0), sType);
-				if ((o.flags & SEEN_OR_UNINTERESTING) != 0)
+				if ((o.flags & SEEN) != 0)
 					continue;
 				o.flags |= SEEN;
+				if ((o.flags & UNINTERESTING) != 0
+						&& !hasRevSort(RevSort.BOUNDARY))
+					continue;
 				enterSubtree = true;
 				fromTreeWalk = true;
 				return o;
@@ -265,9 +277,11 @@ public class ObjectWalk extends RevWalk {
 			final RevObject o = objects.next();
 			if (o == null)
 				return null;
-			if ((o.flags & SEEN_OR_UNINTERESTING) != 0)
+			if ((o.flags & SEEN) != 0)
 				continue;
 			o.flags |= SEEN;
+			if ((o.flags & UNINTERESTING) != 0 && !hasRevSort(RevSort.BOUNDARY))
+				continue;
 			if (o instanceof RevTree) {
 				currentTree = (RevTree) o;
 				treeWalk.reset(new ObjectId[] { currentTree });
diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevSort.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevSort.java
index 8688f7f..b0a03ad 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevSort.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevSort.java
@@ -37,7 +37,7 @@
 
 package org.spearce.jgit.revwalk;
 
-/** Sorting strategies supported by {@link RevWalk}. */
+/** Sorting strategies supported by {@link RevWalk} and {@link ObjectWalk}. */
 public enum RevSort {
 	/**
 	 * No specific sorting is requested.
@@ -83,6 +83,9 @@ public enum RevSort {
 
 	/**
 	 * Include {@link RevFlag#UNINTERESTING} boundary commits after all others.
+	 * In {@link ObjectWalk}, objects associated with such commits (trees,
+	 * blobs), and all other objects marked explicitly as UNINTERESTING are also
+	 * included.
 	 * <p>
 	 * A boundary commit is a UNINTERESTING parent of an interesting commit that
 	 * was previously output.
-- 
1.5.5.1

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