5 static int show_merge_base(struct commit
**rev
, int rev_nr
, int show_all
)
7 struct commit_list
*result
;
9 result
= get_merge_bases_many(rev
[0], rev_nr
- 1, rev
+ 1, 0);
15 printf("%s\n", sha1_to_hex(result
->item
->object
.sha1
));
18 result
= result
->next
;
24 static const char merge_base_usage
[] =
25 "git merge-base [--all] <commit-id> <commit-id>...";
27 static struct commit
*get_commit_reference(const char *arg
)
29 unsigned char revkey
[20];
32 if (get_sha1(arg
, revkey
))
33 die("Not a valid object name %s", arg
);
34 r
= lookup_commit_reference(revkey
);
36 die("Not a valid commit name %s", arg
);
41 int cmd_merge_base(int argc
, const char **argv
, const char *prefix
)
47 git_config(git_default_config
, NULL
);
49 while (1 < argc
&& argv
[1][0] == '-') {
50 const char *arg
= argv
[1];
51 if (!strcmp(arg
, "-a") || !strcmp(arg
, "--all"))
54 usage(merge_base_usage
);
58 usage(merge_base_usage
);
60 rev
= xmalloc((argc
- 1) * sizeof(*rev
));
63 rev
[rev_nr
++] = get_commit_reference(argv
[1]);
67 return show_merge_base(rev
, rev_nr
, show_all
);