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

Re: git-diff bug?

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 2, 2020, 22:00 UTC
Message-ID
<xmqqpn4vs9l9.fsf@gitster.c.googlers.com>
In-Reply-To
<72cfef26-e986-d34c-eea4-46ec0fda2688@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 14 quoted lines
>     $ diff --ignore-blank-lines -u 1 2
>     --- 1	2020-11-02 18:11:04.618133008 +0100
>     +++ 2	2020-11-02 18:11:04.618133008 +0100
>     @@ -1,4 +1,4 @@
>      aaa
>      bbb
>     -ccc
>
>     +ccc
>     $ diff --ignore-blank-lines -u 2 1
>
> This matches your results.  That the order makes a difference is a bit
> odd.  Both are valid diffs of the inputs and neither one changes blank
> lines, though, so it doesn't look like a bug.

Interesting. If "diff" happens to pick the line with "ccc" on it as the unchanging pair of lines between the preimage and the postimage, then another "valid diff of the inputs" would look like this:

     aaa
     bbb
    +
     ccc
    -

What such a patch would change consists only of blank lines. It is reasonable to expect "--ignore-blank-lines" would turn it into a no-op, provided if "diff" picks "ccc" as the matching line.

But if "diff" picks that the blank line at the end of the original file as unchanged line, then we'll see the diff quoted in the first part of this message. And that patch does not change any blank lines, so it is unreasonable to expect "--ignore-blank-lines" to turn it into a no-op.

So it all depends on which matching pair "diff" first picks, before the "are all the lines changed by the hunk blank ones?" kicks in.

One could argue that "diff" should work hard to enumerate all the possible combinations (we just saw two possible combinations above) to find one that allows "--ignore-blank-lines" to produce an empty patch, but I am not sure it is a sensible thing to do.

Show 9 quoted lines
>     $ git diff --ignore-blank-lines 1 2
>     $ git diff --ignore-blank-lines 2 1
>     $ git --version
>     git version 2.29.2
>
> This matches your expectation, but not your results.  Which version do
> you use?
>
> René
Previous: Junio C Hamano
Message 7 of 7 in “git-diff bug?”
  1. Eli BarzilayNov 2, 2020
  2. René ScharfeNov 2, 2020
  3. Eli BarzilayNov 2, 2020
  4. Junio C HamanoNov 2, 2020
  5. Eli BarzilayNov 3, 2020
  6. Junio C HamanoNov 3, 2020
  7. Junio C HamanoNov 2, 2020

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.