git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 5/5] revert: add "--strategy" option to choose merge strategy

From
Christian Couder <chriscool@tuxfamily.org>
Date
Mar 25, 2010, 04:58 UTC
Message-ID
<20100325045818.14832.74751.chriscool@tuxfamily.org>
In-Reply-To
<20100325045519.14832.65964.chriscool@tuxfamily.org>

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>
---
 builtin/revert.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 054f442..808eb53 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -43,6 +43,7 @@ static const char *commit_name;
 static int allow_rerere_auto;
 
 static const char *me;
+static const char *strategy;
 
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
@@ -60,6 +61,7 @@ static void parse_args(int argc, const char **argv)
 		OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
 		OPT_INTEGER('m', "mainline", &mainline, "parent number"),
 		OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
+		OPT_STRING(0, "strategy", &strategy, "strategy", "merge strategy"),
 		OPT_END(),
 		OPT_END(),
 		OPT_END(),
@@ -459,7 +461,24 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 		}
 	}
 
-	do_recursive_merge(base, next, head, oneline, &msgbuf, defmsg);
+	if (!strategy || !strcmp(strategy, "recursive") || action == REVERT)
+		do_recursive_merge(base, next, head, oneline, &msgbuf, defmsg);
+	else {
+		int res;
+		struct commit_list *common = NULL;
+		struct commit_list *remotes = NULL;
+		write_message(&msgbuf, defmsg);
+		commit_list_insert(base, &common);
+		commit_list_insert(next, &remotes);
+		res = try_merge_command(strategy, common,
+					sha1_to_hex(head), remotes);
+		if (res) {
+			fprintf(stderr, "Automatic %s with strategy %s failed.%s\n",
+				me, strategy, help_msg(commit_name));
+			rerere(allow_rerere_auto);
+			exit(1);
+		}
+	}
 
 	/*
 	 *
-- 
1.7.0.2.398.g89bc8ce
Previous: Christian Couder
Message 6 of 6 in “add a --strategy option to "git cherry-pick"”
  1. 0/5 add a --strategy option to "git cherry-pick"Christian Couder, Mar 25, 2010
  2. 1/5 revert: use strbuf to refactor the code that writes the merge messageChristian Couder, Mar 25, 2010
  3. 2/5 revert: refactor merge recursive code into its own functionChristian Couder, Mar 25, 2010
  4. 3/5 merge: refactor code that calls "git merge-STRATEGY"Christian Couder, Mar 25, 2010
  5. 4/5 merge: make function try_merge_command non staticChristian Couder, Mar 25, 2010
  6. 5/5 revert: add "--strategy" option to choose merge strategyChristian Couder, Mar 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.