# pager config for external commands

4 messages from 2010-11-19 to 2010-11-19. Participants: Jeffrey Middleton, Jeff King.
Thread: https://gitlist.dev/t/25788

## Jeffrey Middleton, 2010-11-19 15:26

Subject: pager config for external commands
Message-ID: <AANLkTimMSp8XVzoaax2mW-jYP26B+zF2QSJFcy4TUi60@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimMSp8XVzoaax2mW-jYP26B%2BzF2QSJFcy4TUi60%40mail.gmail.com
In-Reply-To: <AANLkTimtjR0O3K8iGOVVVaFJS2+2wHcHhWf45tFYXjRQ@mail.gmail.com>

```
External commands don't appear to support the pager.<cmd> config
setting. It's implemented for builtins via the call to
check_pager_config and associated code in run_builtin, but there's
nothing like that in execv_dashed_external. Is there a reason not to
implement this for external commands? I can't see one, since the
--no-pager option does apply to them.

Thanks,
Jeffrey

```

## Jeff King, 2010-11-19 16:00

Subject: Re: pager config for external commands
Message-ID: <20101119160058.GA7967@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20101119160058.GA7967%40sigill.intra.peff.net
In-Reply-To: <AANLkTimMSp8XVzoaax2mW-jYP26B+zF2QSJFcy4TUi60@mail.gmail.com>

```
On Fri, Nov 19, 2010 at 09:26:59AM -0600, Jeffrey Middleton wrote:

> External commands don't appear to support the pager.<cmd> config
> setting. It's implemented for builtins via the call to
> check_pager_config and associated code in run_builtin, but there's
> nothing like that in execv_dashed_external. Is there a reason not to
> implement this for external commands? I can't see one, since the
> --no-pager option does apply to them.

See 4e10738 (Allow per-command pager config, 2008-07-03) for some
discussion.

Basically the problem is that we just call execv("git-<cmd>"). If it
works, then we are running an external, but we no longer have an
opportunity to start the pager. If it doesn't, then we don't necessarily
want to commit our pager choice. We may be running an alias, or we may
simply barf with "no such command".

Later on, we started to use run_command instead of execv, but I don't
think that changes the situation.

I think what we really want to do is split out the "look up in PATH" bit
from run_command, actually find out if we have an external command, and
then commit to running it if it exists. If you're interested in working
on that, I think it would be great.

-Peff

```

## Jeffrey Middleton, 2010-11-19 17:16

Subject: Re: pager config for external commands
Message-ID: <AANLkTikE6=At-BV22myZtM4nuNL6z4hoJ-kS=O1LkBXo@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikE6%3DAt-BV22myZtM4nuNL6z4hoJ-kS%3DO1LkBXo%40mail.gmail.com
In-Reply-To: <20101119160058.GA7967@sigill.intra.peff.net>

```
On Fri, Nov 19, 2010 at 10:00 AM, Jeff King <peff@peff.net> wrote:
> Basically the problem is that we just call execv("git-<cmd>"). If it
> works, then we are running an external, but we no longer have an
> opportunity to start the pager. If it doesn't, then we don't necessarily
> want to commit our pager choice. We may be running an alias, or we may
> simply barf with "no such command".

Okay, that makes sense, I think. But execv_dashed_external does
currently commit the pager choice, just without looking it up from the
config. This means that, for example, git --paginate
<nonexistent-command> does invoke the pager. Is that intended? I don't
think I see any tests covering the combination of pager.<cmd> for
anything but builtins.

Also, instead of having git implement "look up in PATH" internally,
would it make sense to simply commit the pager choice, try the execv,
then uncommit the pager choice if the command was not found?

Jeffrey

```

## Jeff King, 2010-11-19 17:29

Subject: Re: pager config for external commands
Message-ID: <20101119172901.GA9747@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20101119172901.GA9747%40sigill.intra.peff.net
In-Reply-To: <AANLkTikE6=At-BV22myZtM4nuNL6z4hoJ-kS=O1LkBXo@mail.gmail.com>

```
On Fri, Nov 19, 2010 at 11:16:53AM -0600, Jeffrey Middleton wrote:

> Okay, that makes sense, I think. But execv_dashed_external does
> currently commit the pager choice, just without looking it up from the
> config. This means that, for example, git --paginate
> <nonexistent-command> does invoke the pager. Is that intended? I don't
> think I see any tests covering the combination of pager.<cmd> for
> anything but builtins.

Hmm. You're right, I should have looked at the current code instead of
digging in the history. :)

Looks like it was part of some pager work Jonathan did this summer. I
think there may have been issues in the past, too, with actually looking
at config before exec'ing the external, but those seem cleared up, too.

So in theory you just need this:

diff --git a/git.c b/git.c
index 0409ac9..bb2c726 100644
--- a/git.c
+++ b/git.c
@@ -438,6 +438,8 @@ static void execv_dashed_external(const char **argv)
 	const char *tmp;
 	int status;
 
+	if (use_pager == -1)
+		use_pager = check_pager_config(argv[0]);
 	commit_pager_choice();
 
 	strbuf_addf(&cmd, "git-%s", argv[0]);

But beyond seeing that it does in fact turn on the pager for an external
command, I've done no testing.

As far as "git -p bogus", I guess we have accepted that it will start
a pager. These days we at least send stderr to the pager, too, so the
error message won't go unseen.

> Also, instead of having git implement "look up in PATH" internally,
> would it make sense to simply commit the pager choice, try the execv,
> then uncommit the pager choice if the command was not found?

No. The reason we push commit_pager_choice off to the last minute is
that you can't uncommit it gracefully. It actually execs the pager,
which may then do things to the terminal outside of our control.

-Peff

```
