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

Re: [PATCH] diff: add --ignore-blank-lines option

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 17, 2013, 19:52 UTC
Message-ID
<7vd2rkcy6r.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CALWbr2zM=rD3GE9a=Xyrvz0E5mAMsDesJu8-Zs7JH7W4U4AbeA@mail.gmail.com>
Antoine Pelisse <apelisse@gmail.com> writes:
Show 10 quoted lines
>>> +     unsigned long changes = ULONG_MAX;
>
> Let me explain what "changes" means, as I know it will help the rest
> of the message:
> It counts the number of *added* blank lines we have ignored since
> "lxch" (needed to calculate the distance between lxch and xch)
> It also has the meaning of what was called "interesting" before.
> If changes == ULONG_MAX, we are still in interesting zone, otherwise
> it means we have ignored "changes" *added* blank lines (0 being a
> valid value).
OK.  That deserves a comment next to this variable.
> (Actually, After rereading this part, it looks like I could check that
> lxch == xchp rather than setting changes to ULONG_MAX).
Yeah, I think so.
Show 9 quoted lines
>>> +             if (distance < max_ignorable &&
>>> +                 (!xch->ignore || changes == ULONG_MAX)) {
>>> +                     lxch = xch;
>>> +                     changes = ULONG_MAX;
>>
> - If we are still in interesting zone, we take it, even if it's
> ignorable change. Because it's close enough.
> - Otherwise, only take real changes. We are close to another change,
> and we are still in the loop, so it must be interesting.
OK.
Show 10 quoted lines
>>> +             } else if (changes != ULONG_MAX &&
>>> +                        xch->i1 + changes - (lxch->i1 + lxch->chg1) > max_common) {
>>> +                     break;
>
> If we are no longer in "interesting zone" (changes != ULONG_MAX), it
> means we will stop if the distance is too big.
> "changes" is used in the calculation to consider the changes we have
> already ignored (xch->i1 - (lxch->i1 + lxch->chg1) will only work if
> xch and lxch are consecutive, we need to add the blank lines we
> ignored).

And this uses max_common that is much larger than max_ignorable because...?

The last interesting change, with its post context and inter hunk gap, together with precontext for this one, is close enough to the beginning of this one. So it is understandable if xch by itself is intereseting to use max_common. Even an interesting one, if that is so far from the last interesting one, should not be part of this hunk.

However, if the current one is by itself uninteresting, should we
still use the max_common, or should this be compared with
max_ignorable?
    
Show 21 quoted lines
>> Could you add comment to the "changes" variable and explain what the
>> variable means?
>>
>>> +             } else if (!xch->ignore) {
>>> +                     lxch = xch;
>>> +                     changes = ULONG_MAX;
>>
>> When this change by itself is interesting, it becomes the "last
>> interesting one" and the hunk continues.
>
> Exactly, and changes goes back to "interesting".
>
>>> +             } else {
>>> +                     if (changes == ULONG_MAX)
>>> +                             changes = 0;
>>> +                     changes += xch->chg2;
>>
>> Puzzled beyond guessing.  Also it is curious why here and only here
>> we look at chg2 side of the things, not i1/chg1 in this whole thing.
>
> chg2 being the number of blank line *additions*.

This is on the else side of if (!xch->ignore), so we are looking at ignored hunk, which means there is only blank line change. Can chg2 be 0 while chg1 is not zero, i.e. xch being a blank line removal?

What should happen in that case? Don't we want to show it, for the same reason we want to keep removal, as long as it is close enough to the interesting zone?

> Hope that makes things clearer,
Yes, it helped quite a bit.
Previous: Antoine PelisseNext: Antoine Pelisse
Message 22 of 26 in “diff: add --ignore-blank-lines option”
  1. diff: add --ignore-blank-lines optionAntoine Pelisse, May 26, 2013
  2. Johannes SixtMay 26, 2013
  3. Antoine PelisseMay 27, 2013
  4. Antoine PelisseJun 1, 2013
  5. Junio C HamanoJun 4, 2013
  6. Antoine PelisseJun 4, 2013
  7. Junio C HamanoJun 4, 2013
  8. Antoine PelisseJun 4, 2013
  9. diff: add --ignore-blank-lines optionAntoine Pelisse, Jun 8, 2013
  10. Eric SunshineJun 9, 2013
  11. Junio C HamanoJun 9, 2013
  12. Antoine PelisseJun 9, 2013
  13. Junio C HamanoJun 9, 2013
  14. Antoine PelisseJun 10, 2013
  15. Junio C HamanoJun 10, 2013
  16. Antoine PelisseJun 12, 2013
  17. Junio C HamanoJun 12, 2013
  18. diff: add --ignore-blank-lines optionAntoine Pelisse, Jun 15, 2013
  19. Junio C HamanoJun 17, 2013
  20. Antoine PelisseJun 17, 2013
  21. Antoine PelisseJun 17, 2013
  22. Junio C HamanoJun 17, 2013
  23. Antoine PelisseJun 17, 2013
  24. Junio C HamanoJun 17, 2013
  25. diff: add --ignore-blank-lines optionAntoine Pelisse, Jun 19, 2013
  26. Junio C HamanoJun 19, 2013

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.