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 static struct commit
*get_commit_reference(const char *arg
)
27 unsigned char revkey
[20];
30 if (get_sha1(arg
, revkey
))
31 die("Not a valid object name %s", arg
);
32 r
= lookup_commit_reference(revkey
);
34 die("Not a valid commit name %s", arg
);
39 int cmd_merge_base(int argc
, const char **argv
, const char *prefix
)
41 struct commit
*rev1
, *rev2
;
44 git_config(git_default_config
, NULL
);
46 while (1 < argc
&& argv
[1][0] == '-') {
47 const char *arg
= argv
[1];
48 if (!strcmp(arg
, "-a") || !strcmp(arg
, "--all"))
51 usage(merge_base_usage
);
55 usage(merge_base_usage
);
56 rev1
= get_commit_reference(argv
[1]);
57 rev2
= get_commit_reference(argv
[2]);
59 return show_merge_base(rev1
, rev2
, show_all
);