diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-01-20 20:28:50 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-01-20 20:28:50 -0800 |
commit | fcb2a7e4a3c7899a3432f5804889fa3ea5779220 (patch) | |
tree | 0f0785d427c23c7b8dbaae1afcdbd370ea3b639c /builtin-merge.c | |
parent | e98f80f50bf9b78aab8cea6184fd708259d0c3b3 (diff) | |
parent | 566c511195adc0ce88559853f2f00933e241d862 (diff) | |
download | git-fcb2a7e4a3c7899a3432f5804889fa3ea5779220.tar.gz |
Merge branch 'ap/merge-backend-opts'
* ap/merge-backend-opts:
Document that merge strategies can now take their own options
Extend merge-subtree tests to test -Xsubtree=dir.
Make "subtree" part more orthogonal to the rest of merge-recursive.
pull: Fix parsing of -X<option>
Teach git-pull to pass -X<option> to git-merge
git merge -X<option>
git-merge-file --ours, --theirs
Conflicts:
git-compat-util.h
Diffstat (limited to 'builtin-merge.c')
-rw-r--r-- | builtin-merge.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/builtin-merge.c b/builtin-merge.c index 9f60ffa2cd..3aaec7bed7 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -51,6 +51,8 @@ static struct commit_list *remoteheads; static unsigned char head[20], stash[20]; static struct strategy **use_strategies; static size_t use_strategies_nr, use_strategies_alloc; +static const char **xopts; +static size_t xopts_nr, xopts_alloc; static const char *branch; static int verbosity; static int allow_rerere_auto; @@ -148,6 +150,17 @@ static int option_parse_strategy(const struct option *opt, return 0; } +static int option_parse_x(const struct option *opt, + const char *arg, int unset) +{ + if (unset) + return 0; + + ALLOC_GROW(xopts, xopts_nr + 1, xopts_alloc); + xopts[xopts_nr++] = xstrdup(arg); + return 0; +} + static int option_parse_n(const struct option *opt, const char *arg, int unset) { @@ -175,6 +188,8 @@ static struct option builtin_merge_options[] = { OPT_RERERE_AUTOUPDATE(&allow_rerere_auto), OPT_CALLBACK('s', "strategy", &use_strategies, "strategy", "merge strategy to use", option_parse_strategy), + OPT_CALLBACK('X', "strategy-option", &xopts, "option=value", + "option for selected merge strategy", option_parse_x), OPT_CALLBACK('m', "message", &merge_msg, "message", "message to be used for the merge commit (if any)", option_parse_message), @@ -537,7 +552,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, const char *head_arg) { const char **args; - int i = 0, ret; + int i = 0, x = 0, ret; struct commit_list *j; struct strbuf buf = STRBUF_INIT; int index_fd; @@ -566,7 +581,20 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, init_merge_options(&o); if (!strcmp(strategy, "subtree")) - o.subtree_merge = 1; + o.subtree_shift = ""; + + 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 + die("Unknown option for merge-recursive: -X%s", xopts[x]); + } o.branch1 = head_arg; o.branch2 = remoteheads->item->util; @@ -584,10 +612,16 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, rollback_lock_file(lock); return clean ? 0 : 1; } else { - args = xmalloc((4 + commit_list_count(common) + + args = xmalloc((4 + xopts_nr + commit_list_count(common) + commit_list_count(remoteheads)) * sizeof(char *)); strbuf_addf(&buf, "merge-%s", strategy); args[i++] = buf.buf; + for (x = 0; x < xopts_nr; x++) { + char *s = xmalloc(strlen(xopts[x])+2+1); + strcpy(s, "--"); + strcpy(s+2, xopts[x]); + args[i++] = s; + } for (j = common; j; j = j->next) args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1)); args[i++] = "--"; @@ -598,6 +632,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, ret = run_command_v_opt(args, RUN_GIT_CMD); strbuf_release(&buf); i = 1; + for (x = 0; x < xopts_nr; x++) + free((void *)args[i++]); for (j = common; j; j = j->next) free((void *)args[i++]); i += 2; |