diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-09-11 11:35:26 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-09-11 11:36:05 -0700 |
commit | 34f5130af84f7a37fba327d5a5be4f4427dc6886 (patch) | |
tree | 1f8836fe7fb70566e31b3f4f5d1475fabd95981b /builtin/merge-base.c | |
parent | Merge branch 'nd/i18n-index-pack' (diff) | |
parent | reduce_heads(): reimplement on top of remove_redundant() (diff) | |
download | tgif-34f5130af84f7a37fba327d5a5be4f4427dc6886.tar.xz |
Merge branch 'jc/merge-bases'
Optimise the "merge-base" computation a bit, and also update its
users that do not need the full merge-base information to call a
cheaper subset.
* jc/merge-bases:
reduce_heads(): reimplement on top of remove_redundant()
merge-base: "--is-ancestor A B"
get_merge_bases_many(): walk from many tips in parallel
in_merge_bases(): use paint_down_to_common()
merge_bases_many(): split out the logic to paint history
in_merge_bases(): omit unnecessary redundant common ancestor reduction
http-push: use in_merge_bases() for fast-forward check
receive-pack: use in_merge_bases() for fast-forward check
in_merge_bases(): support only one "other" commit
Diffstat (limited to 'builtin/merge-base.c')
-rw-r--r-- | builtin/merge-base.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 2f223a6646..1bc7991048 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -26,6 +26,7 @@ static const char * const merge_base_usage[] = { N_("git merge-base [-a|--all] <commit> <commit>..."), N_("git merge-base [-a|--all] --octopus <commit>..."), N_("git merge-base --independent <commit>..."), + N_("git merge-base --is-ancestor <commit> <commit>"), NULL }; @@ -70,6 +71,20 @@ static int handle_octopus(int count, const char **args, int reduce, int show_all return 0; } +static int handle_is_ancestor(int argc, const char **argv) +{ + struct commit *one, *two; + + if (argc != 2) + die("--is-ancestor takes exactly two commits"); + one = get_commit_reference(argv[0]); + two = get_commit_reference(argv[1]); + if (in_merge_bases(one, two)) + return 0; + else + return 1; +} + int cmd_merge_base(int argc, const char **argv, const char *prefix) { struct commit **rev; @@ -77,11 +92,14 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix) int show_all = 0; int octopus = 0; int reduce = 0; + int is_ancestor = 0; struct option options[] = { OPT_BOOLEAN('a', "all", &show_all, N_("output all common ancestors")), OPT_BOOLEAN(0, "octopus", &octopus, N_("find ancestors for a single n-way merge")), OPT_BOOLEAN(0, "independent", &reduce, N_("list revs not reachable from others")), + OPT_BOOLEAN(0, "is-ancestor", &is_ancestor, + N_("is the first one ancestor of the other?")), OPT_END() }; @@ -89,6 +107,10 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0); if (!octopus && !reduce && argc < 2) usage_with_options(merge_base_usage, options); + if (is_ancestor && (show_all | octopus | reduce)) + die("--is-ancestor cannot be used with other options"); + if (is_ancestor) + return handle_is_ancestor(argc, argv); if (reduce && (show_all || octopus)) die("--independent cannot be used with other options"); |