[JGIT PATCH 2/7] Cleanup RevWalk.parseTree semantics

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

 



When we call parseAny we may have opened the ObjectLoader for the
tree we are going after.  If that worked we know the object exists
in the repository and is certainly recorded as type "tree" so we
do not need to open the object a second time before returning to
the caller.

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../src/org/spearce/jgit/revwalk/RevWalk.java      |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java
index 243d9b3..5a29dcf 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java
@@ -639,15 +639,21 @@ public RevTree parseTree(final AnyObjectId id)
 			c = ((RevTag) c).getObject();
 			parse(c);
 		}
-		if (c instanceof RevCommit) {
-			c = ((RevCommit) c).getTree();
-			parse(c);
-		} else if (!(c instanceof RevTree))
+		
+		final RevTree t;
+		if (c instanceof RevCommit)
+			t = ((RevCommit) c).getTree();
+		else if (!(c instanceof RevTree))
 			throw new IncorrectObjectTypeException(id.toObjectId(),
 					Constants.TYPE_TREE);
-		final RevTree t = (RevTree) c;
+		else
+			t = (RevTree) c;
+
+		if ((t.flags & PARSED) != 0)
+			return t;
 		if (db.openObject(t).getType() != Constants.OBJ_TREE)
 			throw new IncorrectObjectTypeException(t, Constants.TYPE_TREE);
+		t.flags |= PARSED;
 		return t;
 	}
 
@@ -685,10 +691,12 @@ public RevObject parseAny(final AnyObjectId id)
 			}
 			case Constants.OBJ_TREE: {
 				r = new RevTree(ldr.getId());
+				r.flags |= PARSED;
 				break;
 			}
 			case Constants.OBJ_BLOB: {
 				r = new RevBlob(ldr.getId());
+				r.flags |= PARSED;
 				break;
 			}
 			case Constants.OBJ_TAG: {
-- 
1.6.0.1.319.g9f32b

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