- unsigned char rev1[20], rev2[20];
- struct revision *common;
-
- if (argc != 3 || get_sha1_hex(argv[1], rev1) || get_sha1_hex(argv[2], rev2))
- usage("merge-base <commit1> <commit2>");
-
- /*
- * We will eventually want to include a revision cache file
- * that "rev-tree.c" has generated, since this is going to
- * otherwise be quite expensive for big trees..
- *
- * That's some time off, though, and in the meantime we know
- * that we have a solution to the eventual expense.
- */
- common = common_parent(parse_commit(rev1), parse_commit(rev2));
- if (!common)
- die("no common parent found");
- printf("%s\n", sha1_to_hex(common->sha1));
+ struct commit *rev1, *rev2, *ret;
+ unsigned char rev1key[20], rev2key[20];
+
+ if (argc != 3 ||
+ get_sha1(argv[1], rev1key) ||
+ get_sha1(argv[2], rev2key)) {
+ usage("git-merge-base <commit-id> <commit-id>");
+ }
+ rev1 = lookup_commit_reference(rev1key);
+ rev2 = lookup_commit_reference(rev2key);
+ if (!rev1 || !rev2)
+ return 1;
+ ret = common_ancestor(rev1, rev2);
+ if (!ret)
+ return 1;
+ printf("%s\n", sha1_to_hex(ret->object.sha1));