assertEquals(db.resolve("b^1"), db.resolve("B-6-g7f82283^1"));
assertEquals(db.resolve("b~2"), db.resolve("B-6-g7f82283~2"));
}
+
+ public void testParseLookupPath() throws IOException {
+ ObjectId b2_txt = id("10da5895682013006950e7da534b705252b03be6");
+ ObjectId b3_b2_txt = id("e6bfff5c1d0f0ecd501552b43a1e13d8008abc31");
+ ObjectId b_root = id("acd0220f06f7e4db50ea5ba242f0dfed297b27af");
+ ObjectId master_txt = id("82b1d08466e9505f8666b778744f9a3471a70c81");
+
+ assertEquals(b2_txt, db.resolve("b:b/b2.txt"));
+ assertEquals(b_root, db.resolve("b:"));
+ assertEquals(master_txt, db.resolve(":master.txt"));
+ assertEquals(b3_b2_txt, db.resolve("b~3:b/b2.txt"));
+
+ assertNull("no FOO", db.resolve("b:FOO"));
+ assertNull("no b/FOO", db.resolve("b:b/FOO"));
+ assertNull("no b/FOO", db.resolve(":b/FOO"));
+ assertNull("no not-a-branch:", db.resolve("not-a-branch:"));
+ }
+
+ private static ObjectId id(String name) {
+ return ObjectId.fromString(name);
+ }
}
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
+import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.ReflogReader;
+import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
}
}
break;
+ case ':': {
+ RevTree tree;
+ if (ref == null) {
+ // We might not yet have parsed the left hand side.
+ ObjectId id;
+ try {
+ if (i == 0)
+ id = resolve(rw, Constants.HEAD);
+ else
+ id = resolve(rw, new String(rev, 0, i));
+ } catch (RevisionSyntaxException badSyntax) {
+ throw new RevisionSyntaxException(revstr);
+ }
+ if (id == null)
+ return null;
+ tree = rw.parseTree(id);
+ } else {
+ tree = rw.parseTree(ref);
+ }
+
+ if (i == rev.length - i)
+ return tree.copy();
+
+ TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(),
+ new String(rev, i + 1, rev.length - i - 1), tree);
+ return tw != null ? tw.getObjectId(0) : null;
+ }
default:
if (ref != null)