Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit e2f5df4

Browse files
committed
merge-base: separate "--independent" codepath into its own helper
It piggybacks on an unrelated handle_octopus() function only because there are some similarities between the way they need to preprocess their input and output their result. There is nothing similar in the true logic between these two operations. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f93541 commit e2f5df4

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

builtin/merge-base.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,36 @@ static struct commit *get_commit_reference(const char *arg)
4444
return r;
4545
}
4646

47-
static int handle_octopus(int count, const char **args, int reduce, int show_all)
47+
static int handle_independent(int count, const char **args)
4848
{
4949
struct commit_list *revs = NULL;
5050
struct commit_list *result;
5151
int i;
5252

53-
if (reduce)
54-
show_all = 1;
53+
for (i = count - 1; i >= 0; i--)
54+
commit_list_insert(get_commit_reference(args[i]), &revs);
55+
56+
result = reduce_heads(revs);
57+
if (!result)
58+
return 1;
59+
60+
while (result) {
61+
printf("%s\n", sha1_to_hex(result->item->object.sha1));
62+
result = result->next;
63+
}
64+
return 0;
65+
}
66+
67+
static int handle_octopus(int count, const char **args, int show_all)
68+
{
69+
struct commit_list *revs = NULL;
70+
struct commit_list *result;
71+
int i;
5572

5673
for (i = count - 1; i >= 0; i--)
5774
commit_list_insert(get_commit_reference(args[i]), &revs);
5875

59-
result = reduce ? reduce_heads(revs) : get_octopus_merge_bases(revs);
76+
result = get_octopus_merge_bases(revs);
6077

6178
if (!result)
6279
return 1;
@@ -114,8 +131,10 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
114131
if (reduce && (show_all || octopus))
115132
die("--independent cannot be used with other options");
116133

117-
if (octopus || reduce)
118-
return handle_octopus(argc, argv, reduce, show_all);
134+
if (octopus)
135+
return handle_octopus(argc, argv, show_all);
136+
else if (reduce)
137+
return handle_independent(argc, argv);
119138

120139
rev = xmalloc(argc * sizeof(*rev));
121140
while (argc-- > 0)

0 commit comments

Comments
 (0)