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

[PATCH] merge-recur: if there is no common ancestor, fake empty one

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 9, 2006, 16:43 UTC
Message-ID
<Pine.LNX.4.63.0608091842210.1800@wbgn013.biozentrum.uni-wuerzburg.de>
This fixes the coolest merge ever.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	This was a forgotten part from the python version.
 merge-recursive.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 7a93dd9..f5b547b 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1223,6 +1223,18 @@ int merge(struct commit *h1,
 		output_commit_title(iter->item);
 
 	merged_common_ancestors = pop_commit(&ca);
+	if (merged_common_ancestors == NULL) {
+		/* if there is no common ancestor, make an empty tree */
+		struct tree *tree = xcalloc(1, sizeof(struct tree));
+		char buffer[40];
+		int hdrlen;
+
+		tree->object.parsed = 1;
+		tree->object.type = OBJ_TREE;
+		*write_sha1_file_prepare(NULL, 0, tree_type, &tree->object.sha1,
+				buffer, &hdrlen);
+		merged_common_ancestors = make_virtual_commit(tree, "ancestor");
+	}
 
 	for (iter = ca; iter; iter = iter->next) {
 		output_indent = call_depth + 1;
-- 
1.4.2.rc3.g29d0-dirty
Next: Johannes Schindelin
Message 1 of 3 in “merge-recur: if there is no common ancestor, fake empty one”
  1. merge-recur: if there is no common ancestor, fake empty oneJohannes Schindelin, Aug 9, 2006
  2. Johannes SchindelinAug 9, 2006
  3. Alex RiesenAug 9, 2006

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.