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
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 15, 2020, 23:35 UTC
Message-ID
<nycvar.QRO.7.76.6.2011160027480.18437@tvgsbejvaqbjf.bet>
In-Reply-To
<20201112182925.GA701197@coredump.intra.peff.net>
Hi Peff,
On Thu, 12 Nov 2020, Jeff King wrote:
Show 25 quoted lines
> On Thu, Nov 12, 2020 at 03:04:01PM +0100, Johannes Schindelin wrote:
>
> > > Hmm. Right, I knew about that weirdness. But I assumed that the builtin
> > > add-interactive was doing the diffs in-core. Otherwise, why would we
> > > have seen the failure to load diff.color.frag in the first place?
> >
> > Oh, that's easy to explain: as you can verify reading
> > https://github.com/git/git/blob/e31aba42fb12/git-add--interactive.perl#L885-L898
> > the Perl version of `git add -p` insists on (re-)constructing the hunk
> > headers manually, and obviously it needs to color them manually, too. And
> > https://github.com/git/git/blob/e31aba42fb12/add-patch.c#L649-L672 shows
> > that the built-in version of `git add -p` slavishly follows that practice.
>
> But that is only when we split hunks (your link to the perl script is in
> split_hunks()). I agree we must color manually there when creating our
> own hunk header. But outside of that and patch-editing, the perl script
> does not otherwise recolor or rewrite (nor even really parse beyond
> line-splitting) what it gets from the colorized version.
>
> 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).

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.

Show 41 quoted lines
> > > The answer seems to be that render_hunk() always _replaces_ the colors
> > > we got from running the external diff. Whereas the perl version only
> > > applied coloring when reading back in the results of an edit operation
> > > (and likewise used the frag color when generating a split hunk header).
> >
> > No, the Perl version also insists on applying `fraginfo_color`, see
> > https://github.com/git/git/blob/e31aba42fb12/git-add--interactive.perl#L885-L898
>
> Only when we split. Try this to give different colors between the
> interactive script and diff:
>
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index e713fe3d02..862a21ff1f 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -28,8 +28,9 @@
>  my $diff_use_color = $repo->get_colorbool('color.diff');
>  my ($fraginfo_color) =
>  	$diff_use_color ? (
> -		$repo->get_color('color.diff.frag', 'cyan'),
> +		$repo->get_color('color.diff.nonsense', 'yellow'),
>  	) : ();
> +# noop to create split hunk
>  my ($diff_plain_color) =
>  	$diff_use_color ? (
>  		$repo->get_color('color.diff.plain', ''),
>
> Running "git add -p" does not result in yellow hunk headers. But issuing
> a split command does.
>
> The distinction is mostly academic, because diff-tree and the
> interactive patch code should be using the same colors, so the result
> should look the same. It could matter if the diff-filter chooses
> different colors, though then the split headers will not match the
> originals in style. We _could_ run the newly created hunk header
> individually through the diff-filter, though I'm not sure how various
> filters would handle that.
>
> That's true of the perl version as well as the builtin one, but I think
> the builtin one's insistence on parsing the colored output is taking us
> in the wrong direction to eventually fix that.

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.

Anyway. I stand by what I said above: I do not want to spend any further time on this tangent, at least not right now. There are more pressing challenges waiting for me, and I expect those other challenge to have a much bigger "return on investment".

Ciao, Dscho

Show 21 quoted lines
> > > I'm not sure that what the builtin version is doing is wrong, but it
> > > seems like it's putting a lot of extra effort into parsing colors off of
> > > the colorized version. Whereas the perl version just assumes the lines
> > > match up. I do wonder if there are corner cases we might hit around
> > > filters here, though. The lines we get from a filter might bear no
> > > resemblance at all to diff lines. The only thing we require in the perl
> > > version is that they have correspond 1-to-1 with the unfiltered diff
> > > lines in meaning.
> >
> > They do have to correspond 1-to-1 because the assumption is that the
> > individual lines will then correspond one-to-one, too. This does not need
> > to be true, of course, but then the filter is probably less useful than
> > the user wants it to be.
>
> Right, I'm not disputing the 1-to-1 thing (I was after all the one who
> implemented interactive.diffilter, and added the "complain if the counts
> don't line up" check). But in the perl script they only need to
> correspond _semantically_, not syntactically.
>
> -Peff
>
Previous: Jeff KingNext: Jeff King
Message 12 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.