Merge branch 'bm/merge-base-octopus-dedup' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 13 Feb 2014 21:38:59 +0000 (13:38 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Feb 2014 21:38:59 +0000 (13:38 -0800)
"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

1  2 
builtin/merge-base.c
diff --combined builtin/merge-base.c
index e88eb93f143ef5883b3e5f8f069fd13f70ff7abf,87f4dbccaeae39e7bd52e89f368357d58bc20037..57ac472716145d14d29421bf3469f9376295f3c6
@@@ -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()
        };
  
        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)