git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* merge-recursive: do not rudely die on binary merge
@ 2007-08-14 22:33 Junio C Hamano
  2007-08-14 23:14 ` Chris Shoemaker
  0 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2007-08-14 22:33 UTC (permalink / raw)
  To: git; +Cc: Alex Riesen, Johannes Schindelin

When you try to merge a path that involves binary file-level
merge, merge-recursive died rudely without cleaning up its own
mess.  A files added by the merge were left in the working tree,
but the index was not written out (because it just punted and
died), so it was cumbersome for the user to retry it by first
running "git reset --hard".

This changes merge-recursive to still warn but do the "binary"
merge for such a path; leave the "our" version in the working
tree, but still keep the path unmerged so that the user can sort
it out.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 merge-recursive.c       |   51 +++++++++++++++++++----------------
 t/t6027-merge-binary.sh |   67 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 23 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index f7d1b84..5326d7c 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -677,6 +677,26 @@ struct ll_merge_driver {
 /*
  * Built-in low-levels
  */
+static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
+			   const char *path_unused,
+			   mmfile_t *orig,
+			   mmfile_t *src1, const char *name1,
+			   mmfile_t *src2, const char *name2,
+			   mmbuffer_t *result)
+{
+	/*
+	 * The tentative merge result is "ours" for the final round,
+	 * or common ancestor for an internal merge.  Still return
+	 * "conflicted merge" status.
+	 */
+	mmfile_t *stolen = index_only ? orig : src1;
+
+	result->ptr = stolen->ptr;
+	result->size = stolen->size;
+	stolen->ptr = NULL;
+	return 1;
+}
+
 static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
 			const char *path_unused,
 			mmfile_t *orig,
@@ -687,10 +707,15 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
 	xpparam_t xpp;
 
 	if (buffer_is_binary(orig->ptr, orig->size) ||
-			buffer_is_binary(src1->ptr, src1->size) ||
-			buffer_is_binary(src2->ptr, src2->size))
-		return error("Cannot merge binary files: %s vs. %s\n",
+	    buffer_is_binary(src1->ptr, src1->size) ||
+	    buffer_is_binary(src2->ptr, src2->size)) {
+		warning("Cannot merge binary files: %s vs. %s\n",
 			name1, name2);
+		return ll_binary_merge(drv_unused, path_unused,
+				       orig, src1, name1,
+				       src2, name2,
+				       result);
+	}
 
 	memset(&xpp, 0, sizeof(xpp));
 	return xdl_merge(orig,
@@ -743,26 +768,6 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
 	return 0;
 }
 
-static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
-			   const char *path_unused,
-			   mmfile_t *orig,
-			   mmfile_t *src1, const char *name1,
-			   mmfile_t *src2, const char *name2,
-			   mmbuffer_t *result)
-{
-	/*
-	 * The tentative merge result is "ours" for the final round,
-	 * or common ancestor for an internal merge.  Still return
-	 * "conflicted merge" status.
-	 */
-	mmfile_t *stolen = index_only ? orig : src1;
-
-	result->ptr = stolen->ptr;
-	result->size = stolen->size;
-	stolen->ptr = NULL;
-	return 1;
-}
-
 #define LL_BINARY_MERGE 0
 #define LL_TEXT_MERGE 1
 #define LL_UNION_MERGE 2
diff --git a/t/t6027-merge-binary.sh b/t/t6027-merge-binary.sh
new file mode 100755
index 0000000..a7358f7
--- /dev/null
+++ b/t/t6027-merge-binary.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+test_description='ask merge-recursive to merge binary files'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+	cat ../test4012.png >m &&
+	git add m &&
+	git ls-files -s | sed -e "s/ 0	/ 1	/" >E1 &&
+	test_tick &&
+	git commit -m "initial" &&
+
+	git branch side &&
+	echo frotz >a &&
+	git add a &&
+	echo nitfol >>m &&
+	git add a m &&
+	git ls-files -s a >E0 &&
+	git ls-files -s m | sed -e "s/ 0	/ 3	/" >E3 &&
+	test_tick &&
+	git commit -m "master adds some" &&
+
+	git checkout side &&
+	echo rezrov >>m &&
+	git add m &&
+	git ls-files -s m | sed -e "s/ 0	/ 2	/" >E2 &&
+	test_tick &&
+	git commit -m "side modifies" &&
+
+	git tag anchor &&
+
+	cat E0 E1 E2 E3 >expect
+'
+
+test_expect_success resolve '
+
+	rm -f a* m* &&
+	git reset --hard anchor &&
+
+	if git merge -s resolve master
+	then
+		echo Oops, should not have succeeded
+		false
+	else
+		git ls-files -s >current
+		diff -u current expect
+	fi
+'
+
+test_expect_success recursive '
+
+	rm -f a* m* &&
+	git reset --hard anchor &&
+
+	if git merge -s recursive master
+	then
+		echo Oops, should not have succeeded
+		false
+	else
+		git ls-files -s >current
+		diff -u current expect
+	fi
+'
+
+test_done

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2007-08-22  0:15 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-14 22:33 merge-recursive: do not rudely die on binary merge Junio C Hamano
2007-08-14 23:14 ` Chris Shoemaker
2007-08-15  0:07   ` Junio C Hamano
2007-08-15 11:19     ` Nikodemus Siivola
2007-08-15 11:50       ` Junio C Hamano
2007-08-20  3:36     ` [PATCH] Document what the stage numbers in the :$n:path syntax mean Steven Grimm
2007-08-20  5:52       ` Jeff King
2007-08-20  6:05         ` Shawn O. Pearce
2007-08-20  6:13           ` Shawn O. Pearce
2007-08-20  7:15             ` Florian Weimer
2007-08-20  8:04               ` Jeff King
2007-08-20  6:30           ` Junio C Hamano
2007-08-20  6:44             ` Jeff King
2007-08-22  0:14             ` Jakub Narebski
2007-08-20  6:37           ` Jeff King
2007-08-20  9:55         ` [PATCH] Document what the stage numbers in the :$n:path syntaxmean Johannes Sixt
2007-08-20  6:20       ` [PATCH] Document what the stage numbers in the :$n:path syntax mean Junio C Hamano
2007-08-20 18:08         ` Jan Hudec
2007-08-20 19:55           ` Junio C Hamano
2007-08-15  0:09   ` merge-recursive: do not rudely die on binary merge Junio C Hamano
2007-08-15  0:18     ` Chris Larson
2007-08-15  1:16     ` Chris Shoemaker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).