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 <apenwarr@gmail.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 26, 2010 at 00:47 UTC
635a7bb1d807390bedfc1147d2052e8423bcd1e0
4 files changed
+26
-31
builtin/merge-recursive.c
+1
-13
@@ -37,19 +37,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
37
if (!prefixcmp(arg, "--")) {
38
if (!arg[2])
39
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))
41
die("Unknown option %s", arg);
42
continue;
43
}
builtin/merge.c
+2
-18
@@ -629,25 +629,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
629
630
o.renormalize = option_renormalize;
631
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]))
634
die("Unknown option for merge-recursive: -X%s", xopts[x]);
650
- }
635
636
o.branch1 = head_arg;
637
o.branch2 = remoteheads->item->util;
merge-recursive.c
+21
@@ -1499,3 +1499,24 @@ void init_merge_options(struct merge_options *o)
1499
memset(&o->current_directory_set, 0, sizeof(struct string_list));
1500
o->current_directory_set.strdup_strings = 1;
1501
}
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
+2
@@ -55,6 +55,8 @@ int merge_recursive_generic(struct merge_options *o,
55
void init_merge_options(struct merge_options *o);
56
struct tree *write_tree_from_memory(struct merge_options *o);
57
58
+int parse_merge_opt(struct merge_options *out, const char *s);
59
+
60
/* builtin/merge.c */
61
int try_merge_command(const char *strategy, struct commit_list *common, const char *head_arg, struct commit_list *remotes);
62