summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7610fa5)
raw | patch | inline | side by side (parent: 7610fa5)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Thu, 26 Aug 2010 05:47:58 +0000 (00:47 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 26 Aug 2010 16:05:02 +0000 (09:05 -0700) |
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>
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>
builtin/merge-recursive.c | patch | blob | history | |
builtin/merge.c | patch | blob | history | |
merge-recursive.c | patch | blob | history | |
merge-recursive.h | patch | blob | history |
index c2d4677fd3db9b4e1360e0c45fdd2d4a110b5629..5a52f3d0a23d12ed64fd49134cf94c8b0045eeb2 100644 (file)
if (!prefixcmp(arg, "--")) {
if (!arg[2])
break;
- if (!strcmp(arg+2, "ours"))
- o.recursive_variant = MERGE_RECURSIVE_OURS;
- else if (!strcmp(arg+2, "theirs"))
- o.recursive_variant = MERGE_RECURSIVE_THEIRS;
- else if (!strcmp(arg+2, "subtree"))
- o.subtree_shift = "";
- else if (!prefixcmp(arg+2, "subtree="))
- o.subtree_shift = arg + 10;
- else if (!strcmp(arg+2, "renormalize"))
- o.renormalize = 1;
- else if (!strcmp(arg+2, "no-renormalize"))
- o.renormalize = 0;
- else
+ if (parse_merge_opt(&o, arg + 2))
die("Unknown option %s", arg);
continue;
}
diff --git a/builtin/merge.c b/builtin/merge.c
index 037cd47e7016c24815841b69e77394520f4731c6..721c424e558329feff10e55456f15bf728b3b880 100644 (file)
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -629,25 +629,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
o.renormalize = option_renormalize;
- /*
- * NEEDSWORK: merge with table in builtin/merge-recursive
- */
- for (x = 0; x < xopts_nr; x++) {
- if (!strcmp(xopts[x], "ours"))
- o.recursive_variant = MERGE_RECURSIVE_OURS;
- else if (!strcmp(xopts[x], "theirs"))
- o.recursive_variant = MERGE_RECURSIVE_THEIRS;
- else if (!strcmp(xopts[x], "subtree"))
- o.subtree_shift = "";
- else if (!prefixcmp(xopts[x], "subtree="))
- o.subtree_shift = xopts[x]+8;
- else if (!strcmp(xopts[x], "renormalize"))
- o.renormalize = 1;
- else if (!strcmp(xopts[x], "no-renormalize"))
- o.renormalize = 0;
- else
+ for (x = 0; x < xopts_nr; x++)
+ if (parse_merge_opt(&o, xopts[x]))
die("Unknown option for merge-recursive: -X%s", xopts[x]);
- }
o.branch1 = head_arg;
o.branch2 = remoteheads->item->util;
diff --git a/merge-recursive.c b/merge-recursive.c
index 762b5494d216b6a3cfe7e79847071e61d9669732..44576b79278107534f40cb2d3c7712b50e91fdc3 100644 (file)
--- a/merge-recursive.c
+++ b/merge-recursive.c
memset(&o->current_directory_set, 0, sizeof(struct string_list));
o->current_directory_set.strdup_strings = 1;
}
+
+int parse_merge_opt(struct merge_options *o, const char *s)
+{
+ if (!s || !*s)
+ return -1;
+ if (!strcmp(s, "ours"))
+ o->recursive_variant = MERGE_RECURSIVE_OURS;
+ else if (!strcmp(s, "theirs"))
+ o->recursive_variant = MERGE_RECURSIVE_THEIRS;
+ else if (!strcmp(s, "subtree"))
+ o->subtree_shift = "";
+ else if (!prefixcmp(s, "subtree="))
+ o->subtree_shift = s + strlen("subtree=");
+ else if (!strcmp(s, "renormalize"))
+ o->renormalize = 1;
+ else if (!strcmp(s, "no-renormalize"))
+ o->renormalize = 0;
+ else
+ return -1;
+ return 0;
+}
diff --git a/merge-recursive.h b/merge-recursive.h
index c5fbe796bb799d02d115420d16657788acc1f0d8..37ff99a2981dc618acdd5c7b1197ba20b9a53f4b 100644 (file)
--- a/merge-recursive.h
+++ b/merge-recursive.h
void init_merge_options(struct merge_options *o);
struct tree *write_tree_from_memory(struct merge_options *o);
+int parse_merge_opt(struct merge_options *out, const char *s);
+
/* builtin/merge.c */
int try_merge_command(const char *strategy, struct commit_list *common, const char *head_arg, struct commit_list *remotes);