threads / discuss / 26072

html userdiff is not showing all my changes

Subject: html userdiff is not showing all my changes

## tl;dr

4 messages between Dec 15, 2010 and Dec 15, 2010.

replies: 3people: 3as markdown or json

Scott Johnson· Dec 15, 2010, 03:47 UTC · lore

I am attempting to do a word diff of an html source file. Part of the removed html is disappearing from the diff when I enable the fancy html word diff.

Here's the output from basic `git diff`:
diff --git a/adv_layout_source.html b/adv_layout_source.html
index 18a81dd..c4ed609 100644
--- a/adv_layout_source.html
+++ b/adv_layout_source.html
@@ -42,8 +42,8 @@
       <ul>
         <li class="ydn-patterns"><em></em><a href="#">ydn-patterns</a></li>
         <li class="ydn-mail"><em></em><a href="#">ydn-mail</a></li>
-        <li class="yws-maps"><em></em><a href="#">yws-maps</a></li>
-        <li class="ydn-delicious"><em></em><a href="#">ydn-delicious</a></li>
+        <li><em></em><a href="#">yws-maps</a></li>
+        <li><em></em><a href="#">ydn-delicious</a></li>
         <li class="yws-flickr"><em></em><a href="#">yws-flickr</a></li>
         <li class="yws-events"><em></em><a href="#">yws-events</a></li>
       </ul>


Here's the default `git diff --word-diff`:
diff --git a/adv_layout_source.html b/adv_layout_source.html
index 18a81dd..c4ed609 100644
--- a/adv_layout_source.html
+++ b/adv_layout_source.html
@@ -42,8 +42,8 @@
      <ul>
        <li class="ydn-patterns"><em></em><a href="#">ydn-patterns</a></li>
        <li class="ydn-mail"><em></em><a href="#">ydn-mail</a></li>
        [-<li class="yws-maps"><em></em><a-]{+<li><em></em><a+} 
href="#">yws-maps</a></li>
        [-<li class="ydn-delicious"><em></em><a-]{+<li><em></em><a+} 
href="#">ydn-delicious</a></li>
        <li class="yws-flickr"><em></em><a href="#">yws-flickr</a></li>
        <li class="yws-events"><em></em><a href="#">yws-events</a></li>
      </ul>

Which is correct, but less than ideal because it highlights much more than the 
actual changes.

So I create a .gitattributes file with one line:
*.html diff=html

And rerun `git diff --word-diff`:
diff --git a/adv_layout_source.html b/adv_layout_source.html
index 18a81dd..c4ed609 100644
--- a/adv_layout_source.html
+++ b/adv_layout_source.html
@@ -42,8 +42,8 @@
      <ul>
        <li class="ydn-patterns"><em></em><a href="#">ydn-patterns</a></li>
        <li class="ydn-mail"><em></em><a href="#">ydn-mail</a></li>
        <li[-class="yws-maps"-]><em></em><a href="#">yws-maps</a></li>
        <li><em></em><a href="#">ydn-delicious</a></li>
        <li class="yws-flickr"><em></em><a href="#">yws-flickr</a></li>
        <li class="yws-events"><em></em><a href="#">yws-events</a></li>
      </ul>

Yikes! What happened to the second line of changes? The removed code is not 
displayed at all.

This is running git 1.7.3.3.

I suspect the problem is in the html patterns in userdiff.c, but I don't 
understand the word-diff-regex well enough to fix it.
Michael J Gruber· Dec 15, 2010, 09:06 UTC · re: Scott Johnson · lore

Re: html userdiff is not showing all my changes

Scott Johnson venit, vidit, dixit 15.12.2010 04:47:
Show 66 quoted lines
> I am attempting to do a word diff of an html source file. Part of the removed 
> html is disappearing from the diff when I enable the fancy html word diff.
> 
> Here's the output from basic `git diff`:
> diff --git a/adv_layout_source.html b/adv_layout_source.html
> index 18a81dd..c4ed609 100644
> --- a/adv_layout_source.html
> +++ b/adv_layout_source.html
> @@ -42,8 +42,8 @@
>        <ul>
>          <li class="ydn-patterns"><em></em><a href="#">ydn-patterns</a></li>
>          <li class="ydn-mail"><em></em><a href="#">ydn-mail</a></li>
> -        <li class="yws-maps"><em></em><a href="#">yws-maps</a></li>
> -        <li class="ydn-delicious"><em></em><a href="#">ydn-delicious</a></li>
> +        <li><em></em><a href="#">yws-maps</a></li>
> +        <li><em></em><a href="#">ydn-delicious</a></li>
>          <li class="yws-flickr"><em></em><a href="#">yws-flickr</a></li>
>          <li class="yws-events"><em></em><a href="#">yws-events</a></li>
>        </ul>
> 
> 
> Here's the default `git diff --word-diff`:
> diff --git a/adv_layout_source.html b/adv_layout_source.html
> index 18a81dd..c4ed609 100644
> --- a/adv_layout_source.html
> +++ b/adv_layout_source.html
> @@ -42,8 +42,8 @@
>       <ul>
>         <li class="ydn-patterns"><em></em><a href="#">ydn-patterns</a></li>
>         <li class="ydn-mail"><em></em><a href="#">ydn-mail</a></li>
>         [-<li class="yws-maps"><em></em><a-]{+<li><em></em><a+} 
> href="#">yws-maps</a></li>
>         [-<li class="ydn-delicious"><em></em><a-]{+<li><em></em><a+} 
> href="#">ydn-delicious</a></li>
>         <li class="yws-flickr"><em></em><a href="#">yws-flickr</a></li>
>         <li class="yws-events"><em></em><a href="#">yws-events</a></li>
>       </ul>
> 
> Which is correct, but less than ideal because it highlights much more than the 
> actual changes.
> 
> So I create a .gitattributes file with one line:
> *.html diff=html
> 
> And rerun `git diff --word-diff`:
> diff --git a/adv_layout_source.html b/adv_layout_source.html
> index 18a81dd..c4ed609 100644
> --- a/adv_layout_source.html
> +++ b/adv_layout_source.html
> @@ -42,8 +42,8 @@
>       <ul>
>         <li class="ydn-patterns"><em></em><a href="#">ydn-patterns</a></li>
>         <li class="ydn-mail"><em></em><a href="#">ydn-mail</a></li>
>         <li[-class="yws-maps"-]><em></em><a href="#">yws-maps</a></li>
>         <li><em></em><a href="#">ydn-delicious</a></li>
>         <li class="yws-flickr"><em></em><a href="#">yws-flickr</a></li>
>         <li class="yws-events"><em></em><a href="#">yws-events</a></li>
>       </ul>
> 
> Yikes! What happened to the second line of changes? The removed code is not 
> displayed at all.
> 
> This is running git 1.7.3.3.
> 
> I suspect the problem is in the html patterns in userdiff.c, but I don't 
> understand the word-diff-regex well enough to fix it.

The wordRegex should really only control what comprises a word, i.e. the granularity of --word-diff. (Where do we insert additional line-breaks before running ordinary diff?)

If a wordRegex can make parts of diff disappear than there is problem deeper in the diff machinery. Can you trim this down to a minimal example?

Michael
Matthijs Kooijman· Dec 15, 2010, 09:12 UTC · re: Michael J Gruber · lore

Re: html userdiff is not showing all my changes

Hi Michael,
> If a wordRegex can make parts of diff disappear than there is problem
> deeper in the diff machinery.

It can do exactly that. The word regex determines what is a word, but everything else is counted as "whitespace". The word diff view shows only differences in words, not in whitespace (which is intentional, since whitespace changes in things like LaTeX or HTML are not interesting). Note that it doesn't show whitespace _differences_, but it does show the whitespace itself (taken from the "new" version of the file).

So, if the word regex somehow doesn't match the second line at all (or at least not the differen part), the differences could get ignored.

> Can you trim this down to a minimal example?
That would be useful in any case.
Gr.
Matthijs
Michael J Gruber· Dec 15, 2010, 09:29 UTC · re: Matthijs Kooijman · lore

Re: html userdiff is not showing all my changes

Matthijs Kooijman venit, vidit, dixit 15.12.2010 10:12:
Show 11 quoted lines
> Hi Michael,
> 
>> If a wordRegex can make parts of diff disappear than there is problem
>> deeper in the diff machinery.
> It can do exactly that. The word regex determines what is a word, but
> everything else is counted as "whitespace". The word diff view shows
> only differences in words, not in whitespace (which is intentional,
> since whitespace changes in things like LaTeX or HTML are not
> interesting). Note that it doesn't show whitespace _differences_, but it
> does show the whitespace itself (taken from the "new" version of the
> file).

Yep, I just found out myself experimenting with a wordRegex for csv. Seems like quite a "Gimme rope" feature...

So, it's the regex.
Show 5 quoted lines
> So, if the word regex somehow doesn't match the second line at all (or
> at least not the differen part), the differences could get ignored.
> 
>> Can you trim this down to a minimal example?
> That would be useful in any case.

What strikes me is that both lines are semantically identical, yet one is treated correctly and the other isn't.

Michael

← back to recent threads