From 873530a775847d2ed23a330779e93e93e9eb175a Mon Sep 17 00:00:00 2001 From: Marek Zawirski Date: Sun, 15 Jun 2008 23:45:45 +0200 Subject: [PATCH] Support for RevSort.BOUNDARY in ObjectWalk 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 Signed-off-by: Robin Rosenberg --- .../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 68ed8619..81cebbdc 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 8688f7fc..b0a03adc 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. *

* A boundary commit is a UNINTERESTING parent of an interesting commit that * was previously output. -- 2.11.4.GIT