5 static int show_merge_base(struct commit
*rev1
, struct commit
*rev2
, int show_all
)
7 struct commit_list
*result
= get_merge_bases(rev1
, rev2
, 0);
13 printf("%s\n", sha1_to_hex(result
->item
->object
.sha1
));
16 result
= result
->next
;
22 static const char merge_base_usage
[] =
23 "git-merge-base [--all] <commit-id> <commit-id>";
25 int cmd_merge_base(int argc
, const char **argv
, const char *prefix
)
27 struct commit
*rev1
, *rev2
;
28 unsigned char rev1key
[20], rev2key
[20];
31 git_config(git_default_config
);
33 while (1 < argc
&& argv
[1][0] == '-') {
34 const char *arg
= argv
[1];
35 if (!strcmp(arg
, "-a") || !strcmp(arg
, "--all"))
38 usage(merge_base_usage
);
42 usage(merge_base_usage
);
43 if (get_sha1(argv
[1], rev1key
))
44 die("Not a valid object name %s", argv
[1]);
45 if (get_sha1(argv
[2], rev2key
))
46 die("Not a valid object name %s", argv
[2]);
47 rev1
= lookup_commit_reference(rev1key
);
48 rev2
= lookup_commit_reference(rev2key
);
51 return show_merge_base(rev1
, rev2
, show_all
);