On 05/06/2024 10:09, Jeff King wrote:
On Tue, Jun 04, 2024 at 08:32:04AM -0700, Junio C Hamano wrote:
Given that the main use case for "|" is for human viewing through a
pager, I think the colorful, filtered version meant for users is the
best default. And then the "bare" version can come from an alternate
command or a knob.
I think that's a very good point. It is hard to see what "|" can be used
for other than viewing the hunk as (a) git does not read the output so
it cannot be used to filter or edit the hunk that is applied and (b) we
pass an isolated hunk so the post-image offset in the hunk header is
likely to be wrong and there is no indication as to which file it comes
from so the program being run cannot apply the hunk itself. Having the
escape codes does make it harder to filter the hunk. For example to just
look at the post-image as one needs to do something like
grep '^[^-+ @]*[+ @]'
instead of just using '^[+ @]' as the pattern but the bonus is that the
output is colored.
Just to note some prior art, mutt's "<pipe-message>" faces a similar
problem. You might want the raw message (if you're going to poke at
headers, MIME parts, etc yourself) or you may want a decoded one (if you
just care about body text and don't want to deal with base64, qp, etc,
yourself). They provide a stateful config knob, but then you end up with
horrible macros that toggle the knob, like:
:set pipe_decode=yes<enter><pipe-message>my-script<enter>:set pipe_decode=no<enter>
I think having two separate commands for the two modes would be less
confusing.
That does sound simpler
Best Wishes
Phillip