7 #define UNINTERESTING 4
9 static int interesting(struct commit_list
*list
)
12 struct commit
*commit
= list
->item
;
14 if (commit
->object
.flags
& UNINTERESTING
)
21 static struct commit
*common_ancestor(struct commit
*rev1
, struct commit
*rev2
)
23 struct commit_list
*list
= NULL
;
24 struct commit_list
*result
= NULL
;
32 rev1
->object
.flags
|= 1;
33 rev2
->object
.flags
|= 2;
34 insert_by_date(rev1
, &list
);
35 insert_by_date(rev2
, &list
);
37 while (interesting(list
)) {
38 struct commit
*commit
= list
->item
;
39 struct commit_list
*tmp
= list
, *parents
;
40 int flags
= commit
->object
.flags
& 7;
45 insert_by_date(commit
, &result
);
47 /* Mark children of a found merge uninteresting */
48 flags
|= UNINTERESTING
;
50 parents
= commit
->parents
;
52 struct commit
*p
= parents
->item
;
53 parents
= parents
->next
;
54 if ((p
->object
.flags
& flags
) == flags
)
57 p
->object
.flags
|= flags
;
58 insert_by_date(p
, &list
);
66 int main(int argc
, char **argv
)
68 struct commit
*rev1
, *rev2
, *ret
;
69 unsigned char rev1key
[20], rev2key
[20];
72 get_sha1(argv
[1], rev1key
) ||
73 get_sha1(argv
[2], rev2key
)) {
74 usage("git-merge-base <commit-id> <commit-id>");
76 rev1
= lookup_commit_reference(rev1key
);
77 rev2
= lookup_commit_reference(rev2key
);
80 ret
= common_ancestor(rev1
, rev2
);
83 printf("%s\n", sha1_to_hex(ret
->object
.sha1
));