revert: add "--strategy" option to choose merge strategy
This patch makes it possible to use a different merge strategy when cherry-picking. This is usefull mainly for debugging purposes as it allows to see if some failures are caused by the merge strategy used or not. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Mar 31, 2010 at 21:22 UTC
91e525989665d69ace11b8f39618b1e8004fe19a
1 file changed
+23
-2
builtin/revert.c
+23
-2
@@ -42,6 +42,7 @@ static const char *commit_name;
42
static int allow_rerere_auto;
43
44
static const char *me;
45
+static const char *strategy;
46
47
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
48
@@ -61,6 +62,7 @@ static void parse_args(int argc, const char **argv)
62
OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
63
OPT_INTEGER('m', "mainline", &mainline, "parent number"),
64
OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
65
+ OPT_STRING(0, "strategy", &strategy, "strategy", "merge strategy"),
66
OPT_END(),
67
};
68
@@ -444,8 +446,27 @@ static int revert_or_cherry_pick(int argc, const char **argv)
446
}
447
}
448
447
- do_recursive_merge(base, next, base_label, next_label,
448
- head, &msgbuf, defmsg);
449
+ if (!strategy || !strcmp(strategy, "recursive") || action == REVERT)
450
+ do_recursive_merge(base, next, base_label, next_label,
451
+ head, &msgbuf, defmsg);
452
+ else {
453
+ int res;
454
+ struct commit_list *common = NULL;
455
+ struct commit_list *remotes = NULL;
456
+ write_message(&msgbuf, defmsg);
457
+ commit_list_insert(base, &common);
458
+ commit_list_insert(next, &remotes);
459
+ res = try_merge_command(strategy, common,
460
+ sha1_to_hex(head), remotes);
461
+ free_commit_list(common);
462
+ free_commit_list(remotes);
463
+ if (res) {
464
+ fprintf(stderr, "Automatic %s with strategy %s failed.%s\n",
465
+ me, strategy, help_msg(commit_name));
466
+ rerere(allow_rerere_auto);
467
+ exit(1);
468
+ }
469
+ }
470
471
/*
472
*