Skip to content

Commit 91e5259

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c674d05 commit 91e5259

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

builtin/revert.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static const char *commit_name;
4242
static int allow_rerere_auto;
4343

4444
static const char *me;
45+
static const char *strategy;
4546

4647
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
4748

@@ -61,6 +62,7 @@ static void parse_args(int argc, const char **argv)
6162
OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
6263
OPT_INTEGER('m', "mainline", &mainline, "parent number"),
6364
OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
65+
OPT_STRING(0, "strategy", &strategy, "strategy", "merge strategy"),
6466
OPT_END(),
6567
};
6668

@@ -444,8 +446,27 @@ static int revert_or_cherry_pick(int argc, const char **argv)
444446
}
445447
}
446448

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+
}
449470

450471
/*
451472
*

0 commit comments

Comments
 (0)