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

Re: [PATCH] diff: setup pager only before diff contents truly ready

From
Jeff King <peff@peff.net>
Date
Oct 21, 2024, 19:00 UTC
Message-ID
<20241021190045.GB1219228@coredump.intra.peff.net>
In-Reply-To
<UZMh2lyzbLOgsf0PXfMnq6HnWVnCK3y36jY3IMKUykPi74ztNucf8bgywoeO0DdeApq31JDDGMZiEya99zAcI3l8y_zcVqiN8FpEnT1DRZU=@proton.me>
On Mon, Oct 21, 2024 at 12:11:33AM +0000, Philip Yung wrote:
Show 5 quoted lines
> > errors will likewise go to the pager. E.g., try "git log --foo".
> 
> Hope that I didn't take it the wrong way, but I don't think `git log --foo`
> starts a pager, where the routine `setup_pager()` is put after argv parsing.
> (checked by `strace`)

Hmm, this actually depends on config. If you have pager.log defined, we'll start it early in git.c, but otherwise not until the setup_pager() call.

I was mildly surprised that pager.diff would not have the same effect, even with your patch. But that's because we only handle pager config if RUN_SETUP is true, which it is not for diff (because we might be doing an out-of-repo --index diff). And the reason for that is mostly historical, as reading config early interferes with repo setup (though I'm even sure that's still the case, as check_pager_config() these days uses the "early" config mechanism which is supposed to address that).

What a horrid mess of inconsistency and hacks. ;)

Likewise, any builtin that sets USE_PAGER in git.c will turn on the pager early. So "git shortlog --foo" will go through the pager, as will range-diff. I was somewhat surprised those are the only two these days. Looks like 1fda91b511 (Fix 'git log' early pager startup error case, 2010-08-24) dropped many. And I think your patch is the spiritual successor to that.

So I think in an ideal world we'd:
  - convert those two commands to do the pager setup themselves and
    retire the USE_PAGER flag entirely
  - move configured pager handling down into more commands. So git-log
    should set DELAY_PAGER_CONFIG and then call setup_auto_pager()
    rather than setup_pager(). Ideally DELAY_PAGER_CONFIG would be the
    default, but we can't do that until every builtin makes its own call
    to setup_auto_pager() at the right moment.
  - push calls to setup_pager() (or setup_auto_pager()) as far down
    within commands as possible (right before we start generating
    output). Your patch does that for git-diff, but there may be other
    cases.
  - consistently handle pager config whether USE_SETUP is set or not.
    That means git-diff should set DELAY_PAGER_CONFIG, since it handles
    the pager itself.

And that would make things more consistent overall, and avoid pushing early errors into the pager (though of course it would still be possible to get some errors in the pager if they happen after we start it).

I don't blame you if you don't want to start down that rabbit hole. :) I think it would probably be OK to peck away at it incrementally, and your patch does that.

Show 7 quoted lines
> > would be missing a spot that needed a new setup_diff_pager() call, and I
> > suspect we don't have good test coverage here.
> 
> This is actually my concern as well when I was naively testing the coverage
> using GDB, which turned out to be quite tedious. Would you consider it's fine to
> add a pager consistency test for builtins, probably in another patch with regard
> to `t7006-pager.sh` OR a new test `t7007`?

TBH, I am not all that worried about adding tests just for your patch. You'd need to identify all of the possible diff code paths in order to add tests for them, which is the same thing you had to do to fix the code paths. I was mostly just commenting that we're not likely to be able to rely on existing tests to help us here.

It might be worth adding a test that shows off your improved diff behavior, though I would be OK if it was a representative command and not exhaustive. I think adding to t7006 should be fine.

If we fixed some of the bits I mentioned above, some of that should likewise be covered by tests.

-Peff
Previous: Philip YungNext: Taylor Blau
Message 6 of 12 in “diff: setup pager only before diff contents truly ready”
  1. diff: setup pager only before diff contents truly readyY5 via GitGitGadget, Oct 19, 2024
  2. Kristoffer HaugsbakkOct 19, 2024
  3. Philip YungOct 21, 2024
  4. Jeff KingOct 19, 2024
  5. Philip YungOct 21, 2024
  6. Jeff KingOct 21, 2024
  7. Taylor BlauOct 21, 2024
  8. Junio C HamanoNov 18, 2024
  9. Jeff KingNov 25, 2024
  10. Junio C HamanoDec 3, 2024
  11. Jeff KingDec 3, 2024
  12. Junio C HamanoDec 4, 2024

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.