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

[BUG] Possible issue with word-diff option

From
ÉAÉric Alber <eric.alber@gmail.com>
Date
Oct 23, 2014, 18:54 UTC
Message-ID
<CAGDZK6HVevTPXVcwhHvmwdv9LZKzcv-3j-tBNV60tvhMuMhKtQ@mail.gmail.com>
Hi,

I'm currently developing a local web based GUI for git in the same fashion as mercurial's 'hg serve': git-webui (https://github.com/alberthier/git-webui) I tried to add word-diff highlighting in my diff visualization panels. I used the '--word-diff=porcelain' option of 'git show' and 'git diff'.

Unfortunately I ran into an issue so I want to make sure I understand
properly the format
Here is how I interpret this output:
- A line of the diff no longer corresponds to a line in the source
file. A line of the source file, is represented between two leading
'~' markers
- A line starting with a '+' or '-' is respectively an added or
removed line fragment
- A line starting with a ' ' (space) is an unchanged line fragment
The problem is visible with the git-webui repository itself:

git clone https://github.com/alberthier/git-webui git show --word-diff=porcelain ed934a7 # This is the head of the 'word-diff' branch # search for the first occurrence of 'fragment'

In the source code, several lines have been replaced with the following single line:

         var fragment = line.substr(1);

But in the diff, 'fragment' and 'line.substr(1);' don't apprear in the same '~' block. I get:

~
         var
-pre
+fragment
  =
-$('<pre class="diff-view-line">').appendTo(view)[0];
~
[ some removed lines....]
~
-        }
+line.substr(1);
~

By reading this output, it looks like 'var fragment = ' and 'line.substr(1);' aren't on the same line. I would have expected:

~
         var
-pre
+fragment
  =
-$('<pre class="diff-view-line">').appendTo(view)[0];
+line.substr(1);
~
[ some removed lines....]
Is there something I miss or is this a bug of git's word-diff algorithm ?
Regards,
Eric
Next: Éric Alber
Message 1 of 2 in “[BUG] Possible issue with word-diff option”
  1. Éric AlberOct 23, 2014
  2. Éric AlberOct 23, 2014

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.