2005-04-18 22:39:48 +04:00
|
|
|
#include <stdlib.h>
|
2005-04-17 23:18:17 +04:00
|
|
|
#include "cache.h"
|
2005-04-18 22:39:48 +04:00
|
|
|
#include "commit.h"
|
2005-04-17 23:18:17 +04:00
|
|
|
|
2006-08-15 21:23:48 +04:00
|
|
|
static int show_all;
|
2006-06-29 17:16:46 +04:00
|
|
|
|
|
|
|
static int merge_base(struct commit *rev1, struct commit *rev2)
|
|
|
|
{
|
2006-07-02 13:49:38 +04:00
|
|
|
struct commit_list *result = get_merge_bases(rev1, rev2, 0);
|
2006-06-29 17:16:46 +04:00
|
|
|
|
|
|
|
if (!result)
|
|
|
|
return 1;
|
|
|
|
|
2005-08-24 08:08:59 +04:00
|
|
|
while (result) {
|
2006-06-29 17:16:46 +04:00
|
|
|
printf("%s\n", sha1_to_hex(result->item->object.sha1));
|
2005-08-24 08:08:59 +04:00
|
|
|
if (!show_all)
|
|
|
|
return 0;
|
2006-06-29 17:16:46 +04:00
|
|
|
result = result->next;
|
2005-08-24 08:08:59 +04:00
|
|
|
}
|
2006-06-29 17:16:46 +04:00
|
|
|
|
2005-08-24 08:08:59 +04:00
|
|
|
return 0;
|
2005-04-17 23:18:17 +04:00
|
|
|
}
|
|
|
|
|
2005-08-24 08:08:59 +04:00
|
|
|
static const char merge_base_usage[] =
|
|
|
|
"git-merge-base [--all] <commit-id> <commit-id>";
|
|
|
|
|
2005-04-17 23:18:17 +04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2005-08-24 08:08:59 +04:00
|
|
|
struct commit *rev1, *rev2;
|
2005-04-18 22:39:48 +04:00
|
|
|
unsigned char rev1key[20], rev2key[20];
|
2005-04-17 23:18:17 +04:00
|
|
|
|
2005-11-26 11:50:02 +03:00
|
|
|
setup_git_directory();
|
2006-03-24 10:41:18 +03:00
|
|
|
git_config(git_default_config);
|
2005-11-26 11:50:02 +03:00
|
|
|
|
2005-08-24 08:08:59 +04:00
|
|
|
while (1 < argc && argv[1][0] == '-') {
|
|
|
|
char *arg = argv[1];
|
|
|
|
if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
|
|
|
|
show_all = 1;
|
|
|
|
else
|
|
|
|
usage(merge_base_usage);
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
2006-05-09 01:43:38 +04:00
|
|
|
if (argc != 3)
|
2005-08-24 08:08:59 +04:00
|
|
|
usage(merge_base_usage);
|
2006-05-09 01:43:38 +04:00
|
|
|
if (get_sha1(argv[1], rev1key))
|
|
|
|
die("Not a valid object name %s", argv[1]);
|
|
|
|
if (get_sha1(argv[2], rev2key))
|
|
|
|
die("Not a valid object name %s", argv[2]);
|
2005-05-19 03:16:51 +04:00
|
|
|
rev1 = lookup_commit_reference(rev1key);
|
|
|
|
rev2 = lookup_commit_reference(rev2key);
|
2005-07-31 02:10:20 +04:00
|
|
|
if (!rev1 || !rev2)
|
|
|
|
return 1;
|
2005-08-24 08:08:59 +04:00
|
|
|
return merge_base(rev1, rev2);
|
2005-04-17 23:18:17 +04:00
|
|
|
}
|