Provide git_config with a callback-data parameter
[git/git.git] / builtin-merge-base.c
CommitLineData
baffc0e7 1#include "builtin.h"
6683463e 2#include "cache.h"
b5039db6 3#include "commit.h"
6683463e 4
71dfbf22 5static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
52cab8a0 6{
c0fa8255 7 struct commit_list *result = get_merge_bases(rev1, rev2, 0);
52cab8a0
JS
8
9 if (!result)
10 return 1;
11
9585e406 12 while (result) {
52cab8a0 13 printf("%s\n", sha1_to_hex(result->item->object.sha1));
9585e406
JH
14 if (!show_all)
15 return 0;
52cab8a0 16 result = result->next;
9585e406 17 }
52cab8a0 18
9585e406 19 return 0;
6683463e
LT
20}
21
9585e406
JH
22static const char merge_base_usage[] =
23"git-merge-base [--all] <commit-id> <commit-id>";
24
71dfbf22 25int cmd_merge_base(int argc, const char **argv, const char *prefix)
6683463e 26{
9585e406 27 struct commit *rev1, *rev2;
b5039db6 28 unsigned char rev1key[20], rev2key[20];
71dfbf22 29 int show_all = 0;
6683463e 30
ef90d6d4 31 git_config(git_default_config, NULL);
53228a5f 32
9585e406 33 while (1 < argc && argv[1][0] == '-') {
71dfbf22 34 const char *arg = argv[1];
9585e406
JH
35 if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
36 show_all = 1;
37 else
38 usage(merge_base_usage);
39 argc--; argv++;
40 }
31fff305 41 if (argc != 3)
9585e406 42 usage(merge_base_usage);
31fff305
DL
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]);
9b632be3
LT
47 rev1 = lookup_commit_reference(rev1key);
48 rev2 = lookup_commit_reference(rev2key);
4f7eb2e5
LT
49 if (!rev1 || !rev2)
50 return 1;
71dfbf22 51 return show_merge_base(rev1, rev2, show_all);
6683463e 52}