Re: [PATCH v3 0/6] use the pager in 'add -p'
- From
- Dragan Simic <dsimic@manjaro.org>
- Date
- Jun 10, 2024, 19:28 UTC
- Message-ID
- <1a9f8385377d3aadfeb07ad62810b2df@manjaro.org>
- In-Reply-To
- <9f1884ae-0f9f-4d9f-a262-b6929b81d7d8@gmail.com>
Hello Phillip,
On 2024-06-10 16:09, Phillip Wood wrote:
Show 43 quoted lines
> On 09/06/2024 08:44, Rubén Justo wrote: >> On Sat, Jun 08, 2024 at 07:54:34AM +0200, Dragan Simic wrote: >> >>> When "|xyz" is used instead, the version of the hunk with no coloring >>> escape sequences should be piped to xyz. >> >> That is a sane and conservative approach, and I'm not opposed. >> However, >> giving the colorful version though a custom pager is a good thing to >> have, I think, i.e: allowing a simple "head" without losing the >> coloring. >> >> Let's recap a bit. >> >> Initially, this series aimed to enable sending chunks to the pager >> during "add -p" sessions. >> >> To reduce the blast radius of spawning a pager for each chunk, we >> introduced a new command "P". >> >> Junio suggested opening up the command to allow specifying a custom >> pager, in the form of "P<program>". >> >> The "P" command started to resemble a lot to the common pipe operator. >> Thus, we shifted to "|<program>". >> >> Some concerns were raised about controlling when to send coloring >> escape >> sequences. > > I'm still not really convinced that the escape sequences are a > problem. As Peff has pointed out [1] this new command exists primarily > to display the current hunk. I've asked for concrete examples of > programs that it would be useful to run from "git add -p" where the > escape codes are a problem [2,3]. Sadly the replies talked in generic > terms about an imaginary program without any reference to displaying > or processing a hunk from "git add -p". Without a clear use case for > stripping the escape codes I think we should add a single command that > pipes the colored output to a user specified program. We can make it > clear in the documentation that the input to the user's command will > contain escape sequences unless they pass "-c color.diff=false" when > starting "git add -p". If it becomes clear that there is a use for the > plain output we can add that at a later stage.
Regarding examples, just have a look at less(1), [4] which is probably the most commonly used pager. It requires "-R" to be specified as one of its command-line parameters for the coloring escape sequences to be processed properly. The presence of "-R" is taken as granted these days, but it hasn't always been the case.
If you want to see an example of the garbled output, as a result of the coloring escape sequences not being processed correctly, just "cd" into your favorite Git repository and run the following commands (assuming you're using bash, if not, please adjust the first command):
export GIT_PAGER='less' git log --patch
I hope that will make more clear why I'm "advocating" for three separate new commands for "git add -p", i.e. "P", "|xyz" and ">xyz".
Show 6 quoted lines
> [1] > https://lore.kernel.org/git/20240605090935.GF2345232@coredump.intra.peff.net > [2] > https://lore.kernel.org/git/a2a59f5e-fd55-41d3-8472-b99256e1f428@gmail.com> > [3] > https://lore.kernel.org/git/1ae0715d-df76-4019-995e-f00f3506f2ac@gmail.com
[4] https://man.archlinux.org/man/less.1.en