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

Re: the pager

From
Dale R. Worley <worley@alum.mit.edu>
Date
Sep 3, 2013, 02:27 UTC
Message-ID
<201309030227.r832RmBd013888@freeze.ariadne.com>
In-Reply-To
<vpqsixsv6dq.fsf@anie.imag.fr>
> From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Show 28 quoted lines
> >     const char *git_pager(int stdout_is_tty)
> >     {
> >             const char *pager;
> >
> >             if (!stdout_is_tty)
> >                     return NULL;
> >
> >             pager = getenv("GIT_PAGER");
> >             if (!pager) {
> >                     if (!pager_program)
> >                             git_config(git_default_config, NULL);
> >                     pager = pager_program;
> >             }
> >             if (!pager)
> >                     pager = getenv("PAGER");
> >             if (!pager)
> >                     pager = DEFAULT_PAGER;
> >             else if (!*pager || !strcmp(pager, "cat"))
> >                     pager = NULL;
> 
> I guess the "else" could and should be dropped. If you do so (and
> possibly insert a blank line between the DEFAULT_PAGER case and the
> "pager = NULL" case), you get a nice pattern
> 
> if (!pager)
> 	try_something();
> if (!pager)
> 	try_next_option();

That's true, but it would change the effect of using "cat" as a value: "cat" as a value of DEFAULT_PAGER would cause git_pager() to return NULL, whereas now it causes git_pager() to return "cat". (All other places where "cat" can be a value are translated to NULL already.)

This is why I want to know what the *intended* behavior is, because we might be changing Git's behavior, and I want to know that if we do that, we're changing it to what it should be. And I haven't seen anyone venture an opinion on what the intended behavior is.

Show 13 quoted lines
> I agree that a comment like this would help, though:
> 
> --- a/cache.h
> +++ b/cache.h
> @@ -1266,7 +1266,7 @@ static inline ssize_t write_str_in_full(int fd, const char *str)
>  
>  /* pager.c */
>  extern void setup_pager(void);
> -extern const char *pager_program;
> +extern const char *pager_program; /* value read from git_config() */
>  extern int pager_in_use(void);
>  extern int pager_use_color;
>  extern int term_columns(void);

First off, the wording is wrong, it should be "value set by git_config()".

But that doesn't tell the reader what the significance of the value is. I suspect that a number of global variables need to be marked:

Show 6 quoted lines
> /* The pager program name, or "cat" if there is no pager.
>  * Can be overridden by the pager.<cmd> configuration value for a
>  * single command, or suppressed by the --no-pager option.
>  * Set by calling git_config().
>  * NULL if hasn't been set yet by calling git_config(). */
> extern const char *pager_program;
Dale
Previous: Matthieu MoyNext: Jonathan Nieder
Message 7 of 18 in “the pager”
  1. Dale R. WorleyAug 26, 2013
  2. Junio C HamanoAug 27, 2013
  3. Dale R. WorleyAug 28, 2013
  4. Junio C HamanoAug 28, 2013
  5. Dale R. WorleyAug 29, 2013
  6. Matthieu MoyAug 29, 2013
  7. Dale R. WorleySep 3, 2013
  8. Jonathan NiederSep 3, 2013
  9. pager: turn on "cat" optimization for DEFAULT_PAGERJeff King, Sep 3, 2013
  10. Junio C HamanoSep 3, 2013
  11. Erik Faye-LundNov 20, 2013
  12. Jeff KingNov 20, 2013
  13. Erik Faye-LundNov 20, 2013
  14. Junio C HamanoNov 20, 2013
  15. Erik Faye-LundNov 20, 2013
  16. Jeff KingSep 3, 2013
  17. Dale R. WorleySep 3, 2013
  18. Jeff KingSep 3, 2013

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.