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

Re: [PATCH 9/9] add -i: verify in the tests that colors can be overridden

From
Jeff King <peff@peff.net>
Date
Nov 17, 2020, 01:44 UTC
Message-ID
<20201117014435.GA19433@coredump.intra.peff.net>
In-Reply-To
<nycvar.QRO.7.76.6.2011160027480.18437@tvgsbejvaqbjf.bet>
On Mon, Nov 16, 2020 at 12:35:44AM +0100, Johannes Schindelin wrote:
Show 13 quoted lines
> > Whereas add-patch parses the colors off of the version and then
> > re-colors every hunk header. Which seems doubly weird to me. Even if we
> > were going to re-color every hunk (e.g., because we don't want to store
> > the original hunk line, but instead a parsed version of it), why bother
> > parsing the color version at all, and not just the machine-readable
> > version?
> 
> Let's continue on this distraction for a bit before I go back to fixing
> the patch series, which actually tries to fix a _different_ concern.
> 
> The reason why `add-patch.c` "parses the colors off" is that we want to
> show the rest of the hunk header, in color, even after splitting hunks
> (this will only be shown for the first hunk, of course).

OK, this is the part I didn't quite understand. My contention was: if we are regenerating a new hunk header after we split, why do we care what was in the old one?

This "rest of the hunk header" is what I didn't get. You are talking here about the funcname header. Which is not colored by default, but people can set color.diff.func.

And here the builtin does differ from the perl script quite a bit. The perl script generates the split hunk headers from scratch, and does not bother to include the funcname in the split header:

  $ git show :foo.c
  void foo()
  {
  	call();
  	some();
  	functions();
  }
  
  $ cat foo.c
  void foo()
  {
  	call();
  	some();
  	more();
  	functions();
  	return;
  }
  $ git add -p
  diff --git a/foo.c b/foo.c
  index 270ccc7..0365419 100644
  --- a/foo.c
  +++ b/foo.c
  @@ -2,5 +2,7 @@ void foo()
   {
   	call();
   	some();
  +	more();
   	functions();
  +	return;
   }
  (1/1) Stage this hunk [y,n,q,a,d,s,e,?]? s
  Split into 2 hunks.
  @@ -2,4 +2,5 @@
   {
   	call();
   	some();
  +	more();
   	functions();
  (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? n
  @@ -5,2 +6,3 @@
   	functions();
  +	return;
   }
  (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? n

So it does not appear at all after the split, colored or otherwise. I think the behavior of the builtin version is better in this case.

It does place more restrictions on what the diffFilter can do, as we've been discussing. The same thing could be accomplished by retaining the uncolored func header, and then coloring it on the fly within add-patch.c (exactly the same way we color the numeric part of the hunk header).

It may also be worth covering this with a test (it was a surprise to me that the builtin version was handling this, though as I said I do agree it's an improvement).

> But given that `git add -p` is somewhat of a fringe use, and using
> `diffFilter` is _even_ more fringe, I do not really want to spend any
> further time on this tangent.

I agree that diffFilter is quite fringe. And as I said before, I'm fine punting on it for now. Mostly this was just the first I had found out about the difference, and because it is user-visible, it may be something that comes up later. So I wanted to record a description of the problem for later.

> My thinking back then was: what if _I_ want to use a diffFilter? For what
> would I use it? Probably to emphasize certain hunk headers more, by adding
> more color to the part after the line range.

Yes, that's what I use it for. I wrote it mostly to pipe through diff-highlight, though also it was to help diff-so-fancy folks (which I don't use myself, but they build on diff-highlight). However, it does seem that they haven't really worked out the problems in the meantime.

-Peff
Previous: Johannes SchindelinNext: Johannes Schindelin via GitGitGadget
Message 13 of 66 in “Fix color handling in git add -i”
  1. 0/9 Fix color handling in git add -iJohannes Schindelin via GitGitGadget, Nov 10, 2020
  2. 1/9 add -i (built-in): do show an error message for incorrect inputsJohannes Schindelin via GitGitGadget, Nov 10, 2020
  3. 2/9 add -i (built-in): send error messages to stderrJohannes Schindelin via GitGitGadget, Nov 10, 2020
  4. 7/9 add -i (built-in): use the same indentation as the Perl versionJohannes Schindelin via GitGitGadget, Nov 10, 2020
  5. 8/9 add -i (Perl version): include indentation in the colored headerJohannes Schindelin via GitGitGadget, Nov 10, 2020
  6. 9/9 add -i: verify in the tests that colors can be overriddenJohannes Schindelin via GitGitGadget, Nov 10, 2020
  7. Jeff KingNov 11, 2020
  8. Johannes SchindelinNov 11, 2020
  9. Jeff KingNov 11, 2020
  10. Johannes SchindelinNov 12, 2020
  11. Jeff KingNov 12, 2020
  12. Johannes SchindelinNov 15, 2020
  13. Jeff KingNov 17, 2020
  14. 5/9 add -i (built-in): use correct names to load color.diff.* configJohannes Schindelin via GitGitGadget, Nov 10, 2020
  15. 3/9 add -i: use `reset_color` consistentlyJohannes Schindelin via GitGitGadget, Nov 10, 2020
  16. 6/9 add -p (built-in): do not color the progress indicator separatelyJohannes Schindelin via GitGitGadget, Nov 10, 2020
  17. 4/9 add -i (built-in): prevent the `reset` "color" from being configuredJohannes Schindelin via GitGitGadget, Nov 10, 2020
  18. Jeff KingNov 11, 2020
  19. 00/11 Fix color handling in git add -iJohannes Schindelin via GitGitGadget, Nov 11, 2020
  20. 01/11 add -i (built-in): do show an error message for incorrect inputsJohannes Schindelin via GitGitGadget, Nov 11, 2020
  21. 07/11 add -p (built-in): do not color the progress indicator separatelyJohannes Schindelin via GitGitGadget, Nov 11, 2020
  22. Phillip WoodNov 13, 2020
  23. Johannes SchindelinNov 13, 2020
  24. Phillip WoodNov 13, 2020
  25. Johannes SchindelinNov 15, 2020
  26. 08/11 add -i (built-in): use the same indentation as the Perl versionJohannes Schindelin via GitGitGadget, Nov 11, 2020
  27. 10/11 add -p: prefer color.diff.context over color.diff.plainJohannes Schindelin via GitGitGadget, Nov 11, 2020
  28. Philippe BlainNov 13, 2020
  29. Johannes SchindelinNov 15, 2020
  30. Phillip WoodNov 13, 2020
  31. Johannes SchindelinNov 16, 2020
  32. 09/11 add -i (Perl version): include indentation in the colored headerJohannes Schindelin via GitGitGadget, Nov 11, 2020
  33. Phillip WoodNov 13, 2020
  34. Johannes SchindelinNov 13, 2020
  35. Phillip WoodNov 13, 2020
  36. Johannes SchindelinNov 15, 2020
  37. 06/11 add -i (built-in): use correct names to load color.diff.* configJohannes Schindelin via GitGitGadget, Nov 11, 2020
  38. 11/11 add -i: verify in the tests that colors can be overriddenJohannes Schindelin via GitGitGadget, Nov 11, 2020
  39. 05/11 add -i (built-in): prevent the `reset` "color" from being configuredJohannes Schindelin via GitGitGadget, Nov 11, 2020
  40. 02/11 add -i (built-in): send error messages to stderrJohannes Schindelin via GitGitGadget, Nov 11, 2020
  41. 03/11 add -p (built-in): imitate `xdl_format_hunk_hdr()` generating hunk headersJohannes Schindelin via GitGitGadget, Nov 11, 2020
  42. 04/11 add -i: use `reset_color` consistentlyJohannes Schindelin via GitGitGadget, Nov 11, 2020
  43. Phillip WoodNov 13, 2020
  44. Johannes SchindelinNov 13, 2020
  45. Phillip WoodNov 13, 2020
  46. Johannes SchindelinNov 15, 2020
  47. Jeff KingNov 11, 2020
  48. Johannes SchindelinNov 12, 2020
  49. Jeff KingNov 12, 2020
  50. Johannes SchindelinNov 15, 2020
  51. Jeff KingNov 17, 2020
  52. 00/11 Fix color handling in git add -iJohannes Schindelin via GitGitGadget, Nov 16, 2020
  53. 01/11 add -i (built-in): do show an error message for incorrect inputsJohannes Schindelin via GitGitGadget, Nov 16, 2020
  54. 02/11 add -i (built-in): send error messages to stderrJohannes Schindelin via GitGitGadget, Nov 16, 2020
  55. 03/11 add -p (built-in): imitate `xdl_format_hunk_hdr()` generating hunk headersJohannes Schindelin via GitGitGadget, Nov 16, 2020
  56. 04/11 add -i: use `reset_color` consistentlyJohannes Schindelin via GitGitGadget, Nov 16, 2020
  57. 05/11 add -i (built-in): prevent the `reset` "color" from being configuredJohannes Schindelin via GitGitGadget, Nov 16, 2020
  58. 06/11 add -i (built-in): use correct names to load color.diff.* configJohannes Schindelin via GitGitGadget, Nov 16, 2020
  59. 08/11 add -i (built-in): use the same indentation as the Perl versionJohannes Schindelin via GitGitGadget, Nov 16, 2020
  60. 07/11 add -p (built-in): do not color the progress indicator separatelyJohannes Schindelin via GitGitGadget, Nov 16, 2020
  61. 11/11 add -i: verify in the tests that colors can be overriddenJohannes Schindelin via GitGitGadget, Nov 16, 2020
  62. 09/11 add -i (Perl version): color header to match the C versionJohannes Schindelin via GitGitGadget, Nov 16, 2020
  63. 10/11 add -p: prefer color.diff.context over color.diff.plainJohannes Schindelin via GitGitGadget, Nov 16, 2020
  64. Jeff KingNov 17, 2020
  65. Jeff KingNov 17, 2020
  66. Junio C HamanoNov 25, 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.