5 static struct commit *common_ancestor(struct commit *rev1, struct commit *rev2)
7 struct commit_list *list = NULL;
8 struct commit_list *result = NULL;
16 rev1->object.flags |= 1;
17 rev2->object.flags |= 2;
18 insert_by_date(rev1, &list);
19 insert_by_date(rev2, &list);
22 struct commit *commit = list->item;
23 struct commit_list *tmp = list, *parents;
24 int flags = commit->object.flags & 3;
30 insert_by_date(commit, &result);
33 die("git-merge-base: commit without either parent?");
35 parents = commit->parents;
37 struct commit *p = parents->item;
38 parents = parents->next;
39 if ((p->object.flags & flags) == flags)
42 p->object.flags |= flags;
43 insert_by_date(p, &list);
51 int main(int argc, char **argv)
53 struct commit *rev1, *rev2, *ret;
54 unsigned char rev1key[20], rev2key[20];
57 get_sha1(argv[1], rev1key) ||
58 get_sha1(argv[2], rev2key)) {
59 usage("git-merge-base <commit-id> <commit-id>");
61 rev1 = lookup_commit_reference(rev1key);
62 rev2 = lookup_commit_reference(rev2key);
65 ret = common_ancestor(rev1, rev2);
68 printf("%s\n", sha1_to_hex(ret->object.sha1));