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

Re: make git diff output easier to read - use better diff heuristics

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Feb 13, 2018, 22:41 UTC
Message-ID
<CAMy9T_FHhXMJTTHR3jg-SGab-1Rgy3FScMxeCUcUjnPfCZEJiw@mail.gmail.com>
In-Reply-To
<CAOmC-AnXD=eSphS=TK4v72tSYDYEV2cgu_EsP4kgNGR=7yre8w@mail.gmail.com>
On Tue, Feb 13, 2018 at 7:25 PM, Σπύρος Βαζαίος <sbazaios@gmail.com> wrote:
Show 6 quoted lines
> While I din't have the experience to express an opinion on this
> matter, I have to say that the --no-indent-heuristic that Jeff
> suggested worked great.
> There were more than a handful of cases that this issue happened in my
> diff file (all were the same: #endif followed by #ifdef).
> Oh, and the language is C indeed.

The "indent heuristic" algorithm that Git now uses by default is nothing more than that—a heuristic—so it can be fooled. It bases its decision on the locations of blank lines and the indentations of non-blank lines. In the vast majority of cases it gives the same or better results than the old algorithm, but there are some cases, like yours, where it gives aesthetically less pleasing (though still correct) results.

The algorithm usually handles C code well, but it tends to be confused by preprocessor directives, because they are not indented like typical code. It might be possible to tweak the weights to get it to handle preprocessor directives better, but that causes it to do worse on other, more common things like Python code (where blocks are preceded but not followed by a line with lesser indentation).

Doing significantly better probably would require some amount of language-awareness, but that's a bigger job than I was willing to take on.

Michael
Previous: Σπύρος Βαζαίος
Message 5 of 5 in “make git diff output easier to read - use better diff heuristics”
  1. Σπύρος ΒαζαίοςFeb 13, 2018
  2. Jeff KingFeb 13, 2018
  3. Stefan BellerFeb 13, 2018
  4. Σπύρος ΒαζαίοςFeb 13, 2018
  5. Michael HaggertyFeb 13, 2018

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.