4 static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
6 struct commit_list *result = get_merge_bases(rev1, rev2, 0);
12 printf("%s\n", sha1_to_hex(result->item->object.sha1));
15 result = result->next;
21 static const char merge_base_usage[] =
22 "git-merge-base [--all] <commit-id> <commit-id>";
24 int cmd_merge_base(int argc, const char **argv, const char *prefix)
26 struct commit *rev1, *rev2;
27 unsigned char rev1key[20], rev2key[20];
30 git_config(git_default_config);
32 while (1 < argc && argv[1][0] == '-') {
33 const char *arg = argv[1];
34 if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
37 usage(merge_base_usage);
41 usage(merge_base_usage);
42 if (get_sha1(argv[1], rev1key))
43 die("Not a valid object name %s", argv[1]);
44 if (get_sha1(argv[2], rev2key))
45 die("Not a valid object name %s", argv[2]);
46 rev1 = lookup_commit_reference(rev1key);
47 rev2 = lookup_commit_reference(rev2key);
50 return show_merge_base(rev1, rev2, show_all);