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

Re: [PATCH, RFC] diff: add option to show context between close chunks

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Oct 20, 2008, 18:06 UTC
Message-ID
<48FCC8A1.5090109@lsrfire.ath.cx>
In-Reply-To
<48FC9685.8030704@viscovery.net>
Johannes Sixt schrieb:
Show 5 quoted lines
> Why can't you just use -U6 instead instead of --inter-chunk-context=3? If
> this is intended for human consumption anyway, then you can just as well
> increase the overall number of context lines: You get extra context lines
> in the places where hunks are not fused, but this cannot be a disadvantage
> for the targeted audience.

The extra lines _are_ a disadvantage for me, since each chunk gets them while only close ones need them -- that's wasted space. The intent is to save time by not having to apply and rediff a patch on a mailing list in order to see the hidden text; part of the savings would be lost if the reader had to skip over extra lines.

Besides, this option is probably most useful if set by default on machines not controlled by me. E.g. I wouldn't want to change an option on a gitweb page, I'd want to get fused chunks by default. I wouldn't want to write "best viewed with -U6" in a patch description, I'd want it to just work (e.g. for gitk users).

I have to admit my main motivation was that one line gap, where a chunk header hid an interesting line of context. Showing it didn't change the length of the patch, so I found this to be a sad wastage.

Optimizing patches for readability makes sense since they are such an important part of our communication here. I think --i-c-c=1 results in an obvious win without much of a downside. I was surprised to find that almost 4% of the chunks in git 1.6.0 would be eliminated by that option:

   $ git log -p v1.6.0 | grep -c '^@@ '
   60544
   $ git log -p v1.6.0 --inter-chunk-context=1 | grep -c '^@@ '
   58471
But perhaps a higher value would be even better?
   $ git log v1.6.0 | wc -l
   225441
   $ git log -p v1.6.0 | wc -l
   1736188
   $ git log -p --inter-chunk-context=10 v1.6.0 | wc -l
   1779048
   $ git log -p -U8 v1.6.0 | wc -l
   2214448

Well, I don't know if those patches are easier to read (haven't looked at them), but I imagine that some related changes are presented with the full context between them (e.g. changes to loop header and footer, function signature and body). The numbers only show that it's affordable (3% more lines with -i-c-c=10, 30% more lines with the comparable -U8).

(Why 10? With the default of -U3, a chunk is 6 lines of context plus at least one line of actual change. Two chunks are at least 14 lines long, thus only 10 more fit into 24 lines, i.e. a terminal window..)

René
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 11 in “diff: add option to show context between close chunks”
  1. diff: add option to show context between close chunksRené Scharfe, Oct 19, 2008
  2. Johannes SixtOct 20, 2008
  3. René ScharfeOct 20, 2008
  4. Johannes SixtOct 21, 2008
  5. René ScharfeOct 21, 2008
  6. Junio C HamanoOct 20, 2008
  7. Johannes SixtOct 21, 2008
  8. Junio C HamanoOct 21, 2008
  9. Jeff KingOct 21, 2008
  10. René ScharfeOct 21, 2008
  11. Daniel BarkalowOct 21, 2008

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.