Skip to content

Commit 05c65cb

Browse files
committed
Merge branch 'tr/maint-word-diff-incomplete-line'
* tr/maint-word-diff-incomplete-line: word-diff: ignore '\ No newline at eof' marker
2 parents b63103e + c7c2bc0 commit 05c65cb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

diff.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,15 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
11131113
diff_words_append(line, len,
11141114
&ecbdata->diff_words->plus);
11151115
return;
1116+
} else if (!prefixcmp(line, "\\ ")) {
1117+
/*
1118+
* Eat the "no newline at eof" marker as if we
1119+
* saw a "+" or "-" line with nothing on it,
1120+
* and return without diff_words_flush() to
1121+
* defer processing. If this is the end of
1122+
* preimage, more "+" lines may come after it.
1123+
*/
1124+
return;
11161125
}
11171126
diff_words_flush(ecbdata);
11181127
if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {

t/t4034-diff-words.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,18 @@ test_expect_success 'word-diff with diff.sbe' '
334334
word_diff --word-diff=plain
335335
'
336336
337+
test_expect_success 'word-diff with no newline at EOF' '
338+
cat >expect <<-\EOF &&
339+
diff --git a/pre b/post
340+
index 7bf316e..3dd0303 100644
341+
--- a/pre
342+
+++ b/post
343+
@@ -1 +1 @@
344+
a a [-a-]{+ab+} a a
345+
EOF
346+
printf "%s" "a a a a a" >pre &&
347+
printf "%s" "a a ab a a" >post &&
348+
word_diff --word-diff=plain
349+
'
350+
337351
test_done

0 commit comments

Comments
 (0)