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

[BUG] diff --word-diff inconsistently places removed words

From
Lucian Poston <lucian.poston@gmail.com>
Date
Oct 27, 2015, 01:40 UTC
Message-ID
<1445910013-13382-1-git-send-email-lucian.poston@gmail.com>

In the output generated by diff --word-diff, if the first word of a line was removed, it may appear at the end of the previous line. For example, compare the following two diffs on the same files, the first diff without --word-diff and the second with it.

$ git diff
diff --git a/smallest-test b/smallest-test
index bc5f07a..d9116b1 100644
--- a/smallest-test
+++ b/smallest-test
@@ -1,7 +1,7 @@
 
-111 aaa
-111 aaa
+ aaa
+ aaa
 
 111 aaa
-111 aaa
+ aaa
 


$ git diff --word-diff=plain

diff --git a/smallest-test b/smallest-test
index bc5f07a..d9116b1 100644
--- a/smallest-test
+++ b/smallest-test
@@ -1,7 +1,7 @@

[-111-] aaa[-111-]
 aaa

111 aaa
[-111-] aaa


I would expect every [-111-] to be on the line where it was removed. Instead
it appears on the previous line in the case where the previous line also has a
removal.

Is this expected behavior?

There is also a patch in this email thread that contains a test to further
illustrate the issue. Running the test fails with the following diff between
the expected result and actual result.

--- expect	2015-10-27 01:08:05.415252713 +0000
+++ output.decrypted	2015-10-27 01:08:05.418252766 +0000
@@ -6,5 +6,5 @@
 11aa<RESET>
 <RED>11<RESET>aa
 
-<RED>11<RESET>aa
-<RED>11<RESET>aa
+<RED>11<RESET>aa<RED>11<RESET>
+aa


Lucian Poston (1):
  t4034: Test parsing words following newline

 t/t4034-diff-words.sh | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
-- 
2.4.10
Next: Lucian Poston
Message 1 of 2 in “[BUG] diff --word-diff inconsistently places removed words”
  1. Lucian PostonOct 27, 2015
  2. t4034: Test parsing words following newlineLucian Poston, Oct 27, 2015

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.