Skip to content

Commit 635a7bb

Browse files
jrngitster
authored andcommitted
merge-recursive: expose merge options for builtin merge
There are two very similar blocks of code that recognize options for the "recursive" merge strategy. Unify them. No functional change intended. Cc: Avery Pennarun <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7610fa5 commit 635a7bb

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

builtin/merge-recursive.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
3737
if (!prefixcmp(arg, "--")) {
3838
if (!arg[2])
3939
break;
40-
if (!strcmp(arg+2, "ours"))
41-
o.recursive_variant = MERGE_RECURSIVE_OURS;
42-
else if (!strcmp(arg+2, "theirs"))
43-
o.recursive_variant = MERGE_RECURSIVE_THEIRS;
44-
else if (!strcmp(arg+2, "subtree"))
45-
o.subtree_shift = "";
46-
else if (!prefixcmp(arg+2, "subtree="))
47-
o.subtree_shift = arg + 10;
48-
else if (!strcmp(arg+2, "renormalize"))
49-
o.renormalize = 1;
50-
else if (!strcmp(arg+2, "no-renormalize"))
51-
o.renormalize = 0;
52-
else
40+
if (parse_merge_opt(&o, arg + 2))
5341
die("Unknown option %s", arg);
5442
continue;
5543
}

builtin/merge.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -629,25 +629,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
629629

630630
o.renormalize = option_renormalize;
631631

632-
/*
633-
* NEEDSWORK: merge with table in builtin/merge-recursive
634-
*/
635-
for (x = 0; x < xopts_nr; x++) {
636-
if (!strcmp(xopts[x], "ours"))
637-
o.recursive_variant = MERGE_RECURSIVE_OURS;
638-
else if (!strcmp(xopts[x], "theirs"))
639-
o.recursive_variant = MERGE_RECURSIVE_THEIRS;
640-
else if (!strcmp(xopts[x], "subtree"))
641-
o.subtree_shift = "";
642-
else if (!prefixcmp(xopts[x], "subtree="))
643-
o.subtree_shift = xopts[x]+8;
644-
else if (!strcmp(xopts[x], "renormalize"))
645-
o.renormalize = 1;
646-
else if (!strcmp(xopts[x], "no-renormalize"))
647-
o.renormalize = 0;
648-
else
632+
for (x = 0; x < xopts_nr; x++)
633+
if (parse_merge_opt(&o, xopts[x]))
649634
die("Unknown option for merge-recursive: -X%s", xopts[x]);
650-
}
651635

652636
o.branch1 = head_arg;
653637
o.branch2 = remoteheads->item->util;

merge-recursive.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,3 +1499,24 @@ void init_merge_options(struct merge_options *o)
14991499
memset(&o->current_directory_set, 0, sizeof(struct string_list));
15001500
o->current_directory_set.strdup_strings = 1;
15011501
}
1502+
1503+
int parse_merge_opt(struct merge_options *o, const char *s)
1504+
{
1505+
if (!s || !*s)
1506+
return -1;
1507+
if (!strcmp(s, "ours"))
1508+
o->recursive_variant = MERGE_RECURSIVE_OURS;
1509+
else if (!strcmp(s, "theirs"))
1510+
o->recursive_variant = MERGE_RECURSIVE_THEIRS;
1511+
else if (!strcmp(s, "subtree"))
1512+
o->subtree_shift = "";
1513+
else if (!prefixcmp(s, "subtree="))
1514+
o->subtree_shift = s + strlen("subtree=");
1515+
else if (!strcmp(s, "renormalize"))
1516+
o->renormalize = 1;
1517+
else if (!strcmp(s, "no-renormalize"))
1518+
o->renormalize = 0;
1519+
else
1520+
return -1;
1521+
return 0;
1522+
}

merge-recursive.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ int merge_recursive_generic(struct merge_options *o,
5555
void init_merge_options(struct merge_options *o);
5656
struct tree *write_tree_from_memory(struct merge_options *o);
5757

58+
int parse_merge_opt(struct merge_options *out, const char *s);
59+
5860
/* builtin/merge.c */
5961
int try_merge_command(const char *strategy, struct commit_list *common, const char *head_arg, struct commit_list *remotes);
6062

0 commit comments

Comments
 (0)