From b6ba9739d5e10e18ecff13095204d71e95837392 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 23 Jun 2010 17:26:43 -0700 Subject: [PATCH] Rewrite resolve in terms of RevWalk We want to eventually get rid of the mapCommit, mapTree APIs on Repository and force everyone into the faster parsers that exist in RevWalk. Rewriting resolve in terms of the faster parsers is a good first step. It actually simplifies the code a bit, as we no longer need to keep track of an ObjectId and an Object (the parsed form), since all RevObjects implicitly have their ObjectId readily available. Change-Id: I4d234630195616e2c263e7e70038b55a1be4e7a3 Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/lib/Repository.java | 202 +++++++----------- 1 file changed, 83 insertions(+), 119 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 350d11f43b..e0f0a6c892 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -67,6 +67,10 @@ import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.RevisionSyntaxException; +import org.eclipse.jgit.revwalk.RevBlob; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevObject; +import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.RawParseUtils; @@ -745,36 +749,37 @@ public class Repository { * * Currently supported is combinations of these. * * - * Not supported is + * Not supported is: * * - * @param revstr A git object references expression + * @param revstr + * A git object references expression * @return an ObjectId or null if revstr can't be resolved to any ObjectId - * @throws IOException on serious errors + * @throws IOException + * on serious errors */ public ObjectId resolve(final String revstr) throws IOException { char[] rev = revstr.toCharArray(); - Object ref = null; - ObjectId refId = null; + RevObject ref = null; + RevWalk rw = new RevWalk(this); for (int i = 0; i < rev.length; ++i) { switch (rev[i]) { case '^': - if (refId == null) { - String refstr = new String(rev,0,i); - refId = resolveSimple(refstr); - if (refId == null) + if (ref == null) { + ref = parseSimple(rw, new String(rev, 0, i)); + if (ref == null) return null; } if (i + 1 < rev.length) { @@ -790,19 +795,12 @@ public class Repository { case '8': case '9': int j; - ref = mapObject(refId, null); - while (ref instanceof Tag) { - Tag tag = (Tag)ref; - refId = tag.getObjId(); - ref = mapObject(refId, null); - } - if (!(ref instanceof Commit)) - throw new IncorrectObjectTypeException(refId, Constants.TYPE_COMMIT); - for (j=i+1; j parents.length) - refId = null; + RevCommit commit = (RevCommit) ref; + if (pnum > commit.getParentCount()) + ref = null; else - refId = parents[pnum - 1]; + ref = commit.getParent(pnum - 1); } i = j - 1; break; case '{': int k; String item = null; - for (k=i+2; k 0) { - final ObjectId[] parents = ((Commit) ref).getParentIds(); - if (parents.length == 0) { - refId = null; + RevCommit commit = (RevCommit) ref; + if (commit.getParentCount() == 0) { + ref = null; break; } - refId = parents[0]; - ref = mapCommit(refId); + commit = commit.getParent(0); + rw.parseHeaders(commit); + ref = commit; --dist; } i = l - 1; @@ -951,30 +910,35 @@ public class Repository { case '@': int m; String time = null; - for (m=i+2; m