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

[PATCH 2/2] fix merge-tree where two branches share no changes

From
Will Palmer <wmpalmer@gmail.com>
Date
Jul 10, 2010, 00:53 UTC
Message-ID
<1278723231-24802-3-git-send-email-wmpalmer@gmail.com>
In-Reply-To
<1278723231-24802-1-git-send-email-wmpalmer@gmail.com>
Here we fix a regression which was introduced by
15b4f7a68d8c3c8ee28424415b203f61202d65d1 /
	merge-tree: use ll_merge() not xdl_merge()

Which caused merge-tree to segfault in particular combinations of merging files which existed in one branch, but not in the other or in the merge-base. This was caused by referencing entry->path at a time when entry was known to be possibly-NULL.

To correct the problem, we save the path of the entry we came in with, as the path should be the same among all the stages no matter which sides are involved in the merge.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
---
 builtin/merge-tree.c  |    3 ++-
 t/t4300-merge-tree.sh |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index fc00d79..9b25ddc 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -60,6 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
 {
 	enum object_type type;
 	struct blob *base, *our, *their;
+	const char *path = entry->path;
 
 	if (!entry->stage)
 		return read_sha1_file(entry->blob->object.sha1, &type, size);
@@ -76,7 +77,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
 	their = NULL;
 	if (entry)
 		their = entry->blob;
-	return merge_file(entry->path, base, our, their, size);
+	return merge_file(path, base, our, their, size);
 }
 
 static void *origin(struct merge_list *entry, unsigned long *size)
diff --git a/t/t4300-merge-tree.sh b/t/t4300-merge-tree.sh
index afcb89d..97a3deb 100755
--- a/t/t4300-merge-tree.sh
+++ b/t/t4300-merge-tree.sh
@@ -30,7 +30,7 @@ test_expect_success 'both added conflict' '
 	git merge-tree initial diff-A diff-B
 '
 
-test_expect_failure 'nothing similar' '
+test_expect_success 'nothing similar' '
 	git reset --hard initial
 	test_commit "no-common-A" "ONE" "AAA" 
 
-- 
1.7.1.703.g42c01
Previous: Will Palmer
Message 3 of 3 in “merge-tree: fix (merge-base a b) b a”
  1. 0/2 merge-tree: fix (merge-base a b) b aWill Palmer, Jul 10, 2010
  2. 1/2 add basic tests for merge-treeWill Palmer, Jul 10, 2010
  3. 2/2 fix merge-tree where two branches share no changesWill Palmer, Jul 10, 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.