From: Junio C Hamano Date: Thu, 26 May 2011 16:37:41 +0000 (-0700) Subject: Merge branch 'jk/cherry-pick-root-with-resolve' into maint X-Git-Tag: v1.7.5.3~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0e66f8722c18194665084e85180bd9f3276f3960?ds=inline;hp=-c Merge branch 'jk/cherry-pick-root-with-resolve' into maint * jk/cherry-pick-root-with-resolve: t3503: test cherry picking and reverting root commits revert: allow reverting a root commit cherry-pick: handle root commits with external strategies --- 0e66f8722c18194665084e85180bd9f3276f3960 diff --combined builtin/merge.c index 0f03dff116,8a0f6901f9..a437ecba29 --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -56,7 -56,6 +56,7 @@@ static size_t use_strategies_nr, use_st static const char **xopts; static size_t xopts_nr, xopts_alloc; static const char *branch; +static char *branch_mergeoptions; static int option_renormalize; static int verbosity; static int allow_rerere_auto; @@@ -504,34 -503,26 +504,34 @@@ cleanup strbuf_release(&bname); } +static void parse_branch_merge_options(char *bmo) +{ + const char **argv; + int argc; + + if (!bmo) + return; + argc = split_cmdline(bmo, &argv); + if (argc < 0) + die(_("Bad branch.%s.mergeoptions string: %s"), branch, + split_cmdline_strerror(argc)); + argv = xrealloc(argv, sizeof(*argv) * (argc + 2)); + memmove(argv + 1, argv, sizeof(*argv) * (argc + 1)); + argc++; + argv[0] = "branch.*.mergeoptions"; + parse_options(argc, argv, NULL, builtin_merge_options, + builtin_merge_usage, 0); + free(argv); +} + static int git_merge_config(const char *k, const char *v, void *cb) { if (branch && !prefixcmp(k, "branch.") && !prefixcmp(k + 7, branch) && !strcmp(k + 7 + strlen(branch), ".mergeoptions")) { - const char **argv; - int argc; - char *buf; - - buf = xstrdup(v); - argc = split_cmdline(buf, &argv); - if (argc < 0) - die(_("Bad branch.%s.mergeoptions string: %s"), branch, - split_cmdline_strerror(argc)); - argv = xrealloc(argv, sizeof(*argv) * (argc + 2)); - memmove(argv + 1, argv, sizeof(*argv) * (argc + 1)); - argc++; - parse_options(argc, argv, NULL, builtin_merge_options, - builtin_merge_usage, 0); - free(buf); + free(branch_mergeoptions); + branch_mergeoptions = xstrdup(v); + return 0; } if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) @@@ -599,6 -590,14 +599,14 @@@ static void write_tree_trivial(unsigne die(_("git write-tree failed to write a tree")); } + static const char *merge_argument(struct commit *commit) + { + if (commit) + return sha1_to_hex(commit->object.sha1); + else + return EMPTY_TREE_SHA1_HEX; + } + int try_merge_command(const char *strategy, size_t xopts_nr, const char **xopts, struct commit_list *common, const char *head_arg, struct commit_list *remotes) @@@ -619,11 -618,11 +627,11 @@@ args[i++] = s; } for (j = common; j; j = j->next) - args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1)); + args[i++] = xstrdup(merge_argument(j->item)); args[i++] = "--"; args[i++] = head_arg; for (j = remotes; j; j = j->next) - args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1)); + args[i++] = xstrdup(merge_argument(j->item)); args[i] = NULL; ret = run_command_v_opt(args, RUN_GIT_CMD); strbuf_release(&buf); @@@ -1019,8 -1018,6 +1027,8 @@@ int cmd_merge(int argc, const char **ar if (diff_use_color_default == -1) diff_use_color_default = git_use_color_default; + if (branch_mergeoptions) + parse_branch_merge_options(branch_mergeoptions); argc = parse_options(argc, argv, prefix, builtin_merge_options, builtin_merge_usage, 0);