# [BUG] Possible issue with word-diff option

2 messages from 2014-10-23 to 2014-10-23. Participants: Éric Alber.
Thread: https://gitlist.dev/t/37789

## Éric Alber, 2014-10-23 18:54

Subject: [BUG] Possible issue with word-diff option
Message-ID: <CAGDZK6HVevTPXVcwhHvmwdv9LZKzcv-3j-tBNV60tvhMuMhKtQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAGDZK6HVevTPXVcwhHvmwdv9LZKzcv-3j-tBNV60tvhMuMhKtQ%40mail.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

```

## Éric Alber, 2014-10-23 20:01

Subject: Re: [BUG] Possible issue with word-diff option
Message-ID: <CAGDZK6ET+jG15FTCdg5GuxbBZS5Lt_gvnH1TitAtnH6-4KBOtA@mail.gmail.com>
URL: https://gitlist.dev/e/CAGDZK6ET%2BjG15FTCdg5GuxbBZS5Lt_gvnH1TitAtnH6-4KBOtA%40mail.gmail.com
In-Reply-To: <CAGDZK6HVevTPXVcwhHvmwdv9LZKzcv-3j-tBNV60tvhMuMhKtQ@mail.gmail.com>

```
I forgot to mention the version :
I tested with Ubuntu's git 1.9.1 and a 2.1.0 version I built myself

2014-10-23 20:54 GMT+02:00 Éric Alber <eric.alber@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

```
