You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
20 years ago
|
#include "cache.h"
|
||
20 years ago
|
#include "commit.h"
|
||
20 years ago
|
|
||
18 years ago
|
static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
|
||
19 years ago
|
{
|
||
19 years ago
|
struct commit_list *result = get_merge_bases(rev1, rev2, 0);
|
||
19 years ago
|
|
||
|
if (!result)
|
||
|
return 1;
|
||
|
|
||
20 years ago
|
while (result) {
|
||
19 years ago
|
printf("%s\n", sha1_to_hex(result->item->object.sha1));
|
||
20 years ago
|
if (!show_all)
|
||
|
return 0;
|
||
19 years ago
|
result = result->next;
|
||
20 years ago
|
}
|
||
19 years ago
|
|
||
20 years ago
|
return 0;
|
||
20 years ago
|
}
|
||
|
|
||
20 years ago
|
static const char merge_base_usage[] =
|
||
|
"git-merge-base [--all] <commit-id> <commit-id>";
|
||
|
|
||
18 years ago
|
int cmd_merge_base(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
20 years ago
|
struct commit *rev1, *rev2;
|
||
20 years ago
|
unsigned char rev1key[20], rev2key[20];
|
||
18 years ago
|
int show_all = 0;
|
||
20 years ago
|
|
||
19 years ago
|
git_config(git_default_config);
|
||
19 years ago
|
|
||
20 years ago
|
while (1 < argc && argv[1][0] == '-') {
|
||
18 years ago
|
const char *arg = argv[1];
|
||
20 years ago
|
if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
|
||
|
show_all = 1;
|
||
|
else
|
||
|
usage(merge_base_usage);
|
||
|
argc--; argv++;
|
||
|
}
|
||
19 years ago
|
if (argc != 3)
|
||
20 years ago
|
usage(merge_base_usage);
|
||
19 years ago
|
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]);
|
||
20 years ago
|
rev1 = lookup_commit_reference(rev1key);
|
||
|
rev2 = lookup_commit_reference(rev2key);
|
||
20 years ago
|
if (!rev1 || !rev2)
|
||
|
return 1;
|
||
18 years ago
|
return show_merge_base(rev1, rev2, show_all);
|
||
20 years ago
|
}
|