git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xmerge.c: fix xdl_merge to conform with the manual
@ 2015-03-03 17:37 Anton Trunov
  2015-03-03 20:17 ` Torsten Bögershausen
  2015-03-03 20:32 ` Junio C Hamano
  0 siblings, 2 replies; 13+ messages in thread
From: Anton Trunov @ 2015-03-03 17:37 UTC (permalink / raw)
  To: git; +Cc: jrnieder, charles, Johannes.Schindelin, Anton Trunov

The git-merge manual says that the ignore-space-change,
ignore-all-space, ignore-space-at-eol options preserve our version
if their version only introduces whitespace changes to a line.

So far if there is whitespace-only changes to both sides
in *all* lines their version will be used.

This commit fixes merge behavior in this case by checking
change for their version first.

Signed-off-by: Anton Trunov <anton.a.trunov <at> gmail.com>
---
 t/t3032-merge-recursive-options.sh | 43 ++++++++++++++++++++++++++++++++++++++
 xdiff/xmerge.c                     | 10 ++++-----
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/t/t3032-merge-recursive-options.sh b/t/t3032-merge-recursive-options.sh
index 4029c9c..4cbedb4 100755
--- a/t/t3032-merge-recursive-options.sh
+++ b/t/t3032-merge-recursive-options.sh
@@ -204,4 +204,47 @@ test_expect_success '--ignore-space-at-eol' '
 	test_cmp expected actual
 '
 
+# Setup for automerging with whitespace-only changes
+# on both sides and in *all* lines
+
+test_expect_success 'setup: w/s only changes in all lines on both sides' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init
+
+	echo " two words" >text.txt &&
+	git add text.txt &&
+	test_tick &&
+	git commit -m "Initial revision" &&
+
+	git checkout -b remote &&
+	echo " \t\ttwo     words  " >text.txt &&
+	git commit -a -m "remote: insert whitespace only" &&
+
+	git checkout master &&
+	echo "    two words" >text.txt &&
+	git commit -a -m "master: insert whitespace only"
+'
+
+test_expect_success 'w/s only in all lines: --ignore-space-change preserves ours' '
+	echo "    two words" >expected &&
+	git read-tree --reset -u HEAD &&
+	git merge-recursive --ignore-space-change HEAD^ -- HEAD remote &&
+	test_cmp expected text.txt
+'
+
+test_expect_success 'w/s only in all lines: --ignore-all-space preserves ours' '
+	echo "    two words" >expected &&
+	git read-tree --reset -u HEAD &&
+	git merge-recursive --ignore-all-space HEAD^ -- HEAD remote &&
+	test_cmp expected text.txt
+'
+
+test_expect_success 'w/s only in all lines: --ignore-space-at-eol fails' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --ignore-space-at-eol HEAD^ -- HEAD remote &&
+	grep "<<<<<<" text.txt
+'
+
 test_done
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 625198e..2c7db26 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -596,14 +596,14 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
 		return -1;
 	}
 	status = 0;
-	if (!xscr1) {
-		result->ptr = xdl_malloc(mf2->size);
-		memcpy(result->ptr, mf2->ptr, mf2->size);
-		result->size = mf2->size;
-	} else if (!xscr2) {
+	if (!xscr2) {
 		result->ptr = xdl_malloc(mf1->size);
 		memcpy(result->ptr, mf1->ptr, mf1->size);
 		result->size = mf1->size;
+	} else if (!xscr1) {
+		result->ptr = xdl_malloc(mf2->size);
+		memcpy(result->ptr, mf2->ptr, mf2->size);
+		result->size = mf2->size;
 	} else {
 		status = xdl_do_merge(&xe1, xscr1,
 				      &xe2, xscr2,
-- 
2.3.1.167.g7f4ba4b

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

end of thread, other threads:[~2015-03-09 10:07 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-03 17:37 [PATCH] xmerge.c: fix xdl_merge to conform with the manual Anton Trunov
2015-03-03 20:17 ` Torsten Bögershausen
2015-03-04  7:07   ` Eric Sunshine
2015-03-04  9:55     ` Anton Trunov
2015-03-04 10:01       ` Eric Sunshine
2015-03-04  9:59   ` Anton Trunov
2015-03-03 20:32 ` Junio C Hamano
2015-03-04  9:43   ` Anton Trunov
2015-03-04 20:01     ` Junio C Hamano
2015-03-05  9:50       ` Anton Trunov
2015-03-06  8:02       ` Anton Trunov
2015-03-08  8:06         ` Junio C Hamano
2015-03-09 10:07           ` Anton Trunov

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).