threads / patch / 37019

patch, 2 partsgit-merge-file: do not add LF at EOF while applying unrelated change

Subject: [PATCH 0/2] git-merge-file: do not add LF at EOF while applying unrelated change

## tl;dr

3 messages between Jun 28, 2014 and Jun 28, 2014. Diffs are folded; open one to read it.

replies: 2people: 1as markdown or json

Max Kirillov· Jun 28, 2014, 19:37 UTC · lore
Hi.

I have noticed that cherry-pick adds trailing newlines when it is not expected to - the change does not contain its addition. Here is the fix for it.

The fix is quite debugging-driven, without detailed analysis of how exactly this "add_nl" parameter works in all cases. But it passes all tests. I have added some more where I felt there were not enough.

Also I have noticed that some tests in the t6023, which related to the behavior contain a mistake which makes them meaningless. I have fixed it and marked the tests as expected failure, because they are failing after that. Hopely they will be fixed some day.

Max Kirillov (2):
  t6023-merge-file.sh: fix and mark as broken invalid tests
  git-merge-file: do not add LF at EOF while applying unrelated change
 t/t6023-merge-file.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++---
 xdiff/xmerge.c        |  4 +--
 2 files changed, 71 insertions(+), 5 deletions(-)
-- 
2.0.0.526.g5318336
Max Kirillov· Jun 28, 2014, 19:37 UTC · re: Max Kirillov · lore

[PATCH 1/2] t6023-merge-file.sh: fix and mark as broken invalid tests

Tests "merge without conflict (missing LF at EOF" and "merge result added missing LF" are meaningless - the first one is identical to "merge without conflict" and the second compares results of those identical tests, which are always same.

This has been so since their addition in ba1f5f3537. Probably "new4.txt" was meant to be used instead of "new2.txt". Unfortunately, the current merge-file breaks with new4 - conflict is reported. They also fail at that revision if fixed.

Fix the file reference to "new4.txt" and mark the tests as failing - they look like legitimate expectations, just not satisfied at time being.

Signed-off-by: Max Kirillov <max@max630.net>
---
 t/t6023-merge-file.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to t/t6023-merge-file.sh +3 −3
diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh
index d9f3439..6da921c 100755
--- a/t/t6023-merge-file.sh
+++ b/t/t6023-merge-file.sh
@@ -77,10 +77,10 @@ test_expect_success "merge without conflict (--quiet)" \
 	"git merge-file --quiet test.txt orig.txt new2.txt"
 
 cp new1.txt test2.txt
-test_expect_success "merge without conflict (missing LF at EOF)" \
-	"git merge-file test2.txt orig.txt new2.txt"
+test_expect_failure "merge without conflict (missing LF at EOF)" \
+	"git merge-file test2.txt orig.txt new4.txt"
 
-test_expect_success "merge result added missing LF" \
+test_expect_failure "merge result added missing LF" \
 	"test_cmp test.txt test2.txt"
 
 cp test.txt backup.txt
-- 
2.0.0.526.g5318336
Max Kirillov· Jun 28, 2014, 19:37 UTC · re: Max Kirillov · lore

[PATCH 2/2] git-merge-file: do not add LF at EOF while applying unrelated change

If 'current-file' does not contain LF at EOF, and change between 'base-file' and 'other-file' does not change any line close to EOF, the 3-way merge should not add LF to EOF. This is what 'diff3 -m' does, and seems to be a reasonable expectation.

The change which introduced the behavior is cd1d61c44f and was about union merge. The union merges are tested in the t6026-merge-attr, and merge-file in general are tested in t6023-merge-file. Add tests "merge conflicting with --.." there, to verify that the fix does not break anything.

Also add tests "merge without conflict (missing LF at EOF, away from change in the other file)" and "merge does not add LF away of change", to demonstrate the changed behavior.

Signed-off-by: Max Kirillov <max@max630.net>
---
 t/t6023-merge-file.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 xdiff/xmerge.c        |  4 ++--
 2 files changed, 68 insertions(+), 2 deletions(-)
Show changes to 2 files +68 −2

t/t6023-merge-file.sh, xdiff/xmerge.c

diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh
index 6da921c..21d1b85 100755
--- a/t/t6023-merge-file.sh
+++ b/t/t6023-merge-file.sh
@@ -83,6 +83,23 @@ test_expect_failure "merge without conflict (missing LF at EOF)" \
 test_expect_failure "merge result added missing LF" \
 	"test_cmp test.txt test2.txt"
 
+cp new4.txt test3.txt
+test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \
+	"git merge-file --quiet test3.txt new2.txt new3.txt"
+
+cat > expect.txt << EOF
+DOMINUS regit me,
+et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+EOF
+printf "propter nomen suum." >> expect.txt
+
+test_expect_success "merge does not add LF away of change" \
+	"test_cmp test3.txt expect.txt"
+
 cp test.txt backup.txt
 test_expect_success "merge with conflicts" \
 	"test_must_fail git merge-file test.txt orig.txt new3.txt"
@@ -107,6 +124,55 @@ EOF
 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
 
 cp backup.txt test.txt
+
+cat > expect.txt << EOF
+Dominus regit me, et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+propter nomen suum.
+Nam et si ambulavero in medio umbrae mortis,
+non timebo mala, quoniam tu mecum es:
+virga tua et baculus tuus ipsa me consolata sunt.
+EOF
+test_expect_success "merge conflicting with --ours" \
+	"git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
+cp backup.txt test.txt
+
+cat > expect.txt << EOF
+DOMINUS regit me,
+et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+propter nomen suum.
+Nam et si ambulavero in medio umbrae mortis,
+non timebo mala, quoniam tu mecum es:
+virga tua et baculus tuus ipsa me consolata sunt.
+EOF
+test_expect_success "merge conflicting with --theirs" \
+	"git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
+cp backup.txt test.txt
+
+cat > expect.txt << EOF
+Dominus regit me, et nihil mihi deerit.
+DOMINUS regit me,
+et nihil mihi deerit.
+In loco pascuae ibi me collocavit,
+super aquam refectionis educavit me;
+animam meam convertit,
+deduxit me super semitas jusitiae,
+propter nomen suum.
+Nam et si ambulavero in medio umbrae mortis,
+non timebo mala, quoniam tu mecum es:
+virga tua et baculus tuus ipsa me consolata sunt.
+EOF
+test_expect_success "merge conflicting with --union" \
+	"git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
+cp backup.txt test.txt
+
 test_expect_success "merge with conflicts, using -L" \
 	"test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
 
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 9e13b25..5f7a95a 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -245,11 +245,11 @@ static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
 					      dest ? dest + size : NULL);
 			/* Postimage from side #1 */
 			if (m->mode & 1)
-				size += xdl_recs_copy(xe1, m->i1, m->chg1, 1,
+				size += xdl_recs_copy(xe1, m->i1, m->chg1, 0,
 						      dest ? dest + size : NULL);
 			/* Postimage from side #2 */
 			if (m->mode & 2)
-				size += xdl_recs_copy(xe2, m->i2, m->chg2, 1,
+				size += xdl_recs_copy(xe2, m->i2, m->chg2, 0,
 						      dest ? dest + size : NULL);
 		} else
 			continue;
-- 
2.0.0.526.g5318336

← back to recent threads