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

[PATCH 1/3] cherry-pick: handle root commits with external strategies

From
Jeff King <peff@peff.net>
Date
May 12, 2011, 11:09 UTC
Message-ID
<20110512110946.GA5292@sigill.intra.peff.net>
In-Reply-To
<20110512110855.GA5240@sigill.intra.peff.net>

The merge-recursive strategy already handles root commits; it cherry-picks the difference between the empty tree and the root commit's tree.

However, for external strategies, we dereference NULL and segfault while building the argument list. Instead, let's handle this by passing the empty tree sha1 to the merge script.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/merge.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 9661c8f..5098bf6 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -599,6 +599,14 @@ static void write_tree_trivial(unsigned char *sha1)
 		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 +627,11 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
 		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);
-- 
1.7.5.1.12.ga7abed
Previous: Jeff KingNext: Sebastian Schuberth
Message 4 of 12 in “git cherry-pick --strategy=resolve segfaults if picking a root commit”
  1. Sebastian SchuberthMay 12, 2011
  2. Jeff KingMay 12, 2011
  3. Jeff KingMay 12, 2011
  4. 1/3 cherry-pick: handle root commits with external strategiesJeff King, May 12, 2011
  5. Sebastian SchuberthMay 12, 2011
  6. 2/3 revert: allow reverting a root commitJeff King, May 12, 2011
  7. Sebastian SchuberthMay 12, 2011
  8. 3/3 t3503: test cherry picking and reverting root commitsJeff King, May 12, 2011
  9. Johannes SixtMay 12, 2011
  10. Jeff KingMay 12, 2011
  11. Jeff KingMay 16, 2011
  12. Junio C HamanoMay 16, 2011

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.