5 static struct commit *process_list(struct commit_list **list_p, int this_mark,
8 struct commit *item = (*list_p)->item;
10 if (item->object.flags & other_mark) {
13 pop_most_recent_commit(list_p, this_mark);
18 static struct commit *common_ancestor(struct commit *rev1, struct commit *rev2)
20 struct commit_list *rev1list = NULL;
21 struct commit_list *rev2list = NULL;
23 commit_list_insert(rev1, &rev1list);
24 rev1->object.flags |= 0x1;
25 commit_list_insert(rev2, &rev2list);
26 rev2->object.flags |= 0x2;
31 while (rev1list || rev2list) {
35 ret = process_list(&rev2list, 0x2, 0x1);
36 } else if (!rev2list) {
38 ret = process_list(&rev1list, 0x1, 0x2);
39 } else if (rev1list->item->date < rev2list->item->date) {
41 ret = process_list(&rev2list, 0x2, 0x1);
44 ret = process_list(&rev1list, 0x1, 0x2);
47 free_commit_list(rev1list);
48 free_commit_list(rev2list);
55 int main(int argc, char **argv)
57 struct commit *rev1, *rev2, *ret;
58 unsigned char rev1key[20], rev2key[20];
61 get_sha1(argv[1], rev1key) ||
62 get_sha1(argv[2], rev2key)) {
63 usage("git-merge-base <commit-id> <commit-id>");
65 rev1 = lookup_commit_reference(rev1key);
66 rev2 = lookup_commit_reference(rev2key);
67 ret = common_ancestor(rev1, rev2);
70 printf("%s\n", sha1_to_hex(ret->object.sha1));