From: Junio C Hamano Date: Thu, 13 Feb 2014 21:38:59 +0000 (-0800) Subject: Merge branch 'bm/merge-base-octopus-dedup' into maint X-Git-Tag: v1.8.5.5~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2cd861672e1021012f40597b9b68cc3a9af62e10?ds=inline;hp=-c Merge branch 'bm/merge-base-octopus-dedup' into maint "git merge-base --octopus" used to leave cleaning up suboptimal result to the caller, but now it does the clean-up itself. * bm/merge-base-octopus-dedup: merge-base --octopus: reduce the result from get_octopus_merge_bases() merge-base: separate "--independent" codepath into its own helper --- 2cd861672e1021012f40597b9b68cc3a9af62e10 diff --combined builtin/merge-base.c index e88eb93f14,87f4dbccae..57ac472716 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@@ -44,19 -44,36 +44,36 @@@ static struct commit *get_commit_refere return r; } - static int handle_octopus(int count, const char **args, int reduce, int show_all) + static int handle_independent(int count, const char **args) { struct commit_list *revs = NULL; struct commit_list *result; int i; - if (reduce) - show_all = 1; + for (i = count - 1; i >= 0; i--) + commit_list_insert(get_commit_reference(args[i]), &revs); + + result = reduce_heads(revs); + if (!result) + return 1; + + while (result) { + printf("%s\n", sha1_to_hex(result->item->object.sha1)); + result = result->next; + } + return 0; + } + + static int handle_octopus(int count, const char **args, int show_all) + { + struct commit_list *revs = NULL; + struct commit_list *result; + int i; for (i = count - 1; i >= 0; i--) commit_list_insert(get_commit_reference(args[i]), &revs); - result = reduce ? reduce_heads(revs) : get_octopus_merge_bases(revs); + result = reduce_heads(get_octopus_merge_bases(revs)); if (!result) return 1; @@@ -95,11 -112,11 +112,11 @@@ int cmd_merge_base(int argc, const cha 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_BOOL('a', "all", &show_all, N_("output all common ancestors")), + OPT_BOOL(0, "octopus", &octopus, N_("find ancestors for a single n-way merge")), + OPT_BOOL(0, "independent", &reduce, N_("list revs not reachable from others")), + OPT_BOOL(0, "is-ancestor", &is_ancestor, + N_("is the first one ancestor of the other?")), OPT_END() }; @@@ -114,8 -131,10 +131,10 @@@ if (reduce && (show_all || octopus)) die("--independent cannot be used with other options"); - if (octopus || reduce) - return handle_octopus(argc, argv, reduce, show_all); + if (octopus) + return handle_octopus(argc, argv, show_all); + else if (reduce) + return handle_independent(argc, argv); rev = xmalloc(argc * sizeof(*rev)); while (argc-- > 0)