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
Aug 29, 2013, 15:41 UTC
Message-ID
<201308291541.r7TFfuJr023110@freeze.ariadne.com>
In-Reply-To
<xmqqr4dd8suz.fsf@gitster.dls.corp.google.com>

So I set out to verify in the code that the order of priority of pager specification is

    GIT_PAGER > core.pager > PAGER > default

I discovered that there is also a pager.<command> configuration variable.

I was expecting the code to be simple, uniform (with regard to the 5 sources), and reasonably well documented. The relevant parts of the code that I have located so far include:

in environment.c:
    const char *pager_program;
in config.c:
    int git_config_with_options(config_fn_t fn, void *data,
                                const char *filename,
                                const char *blob_ref,
                                int respect_includes)
    {
            char *repo_config = NULL;
            int ret;
            struct config_include_data inc = CONFIG_INCLUDE_INIT;
            if (respect_includes) {
                    inc.fn = fn;
                    inc.data = data;
                    fn = git_config_include;
                    data = &inc;
            }
            /*
             * If we have a specific filename, use it. Otherwise, follow the
             * regular lookup sequence.
             */
            if (filename)
                    return git_config_from_file(fn, filename, data);
            else if (blob_ref)
                    return git_config_from_blob_ref(fn, blob_ref, data);
            repo_config = git_pathdup("config");
            ret = git_config_early(fn, data, repo_config);
            if (repo_config)
                    free(repo_config);
            return ret;
    }
in pager.c:
    /* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
    int check_pager_config(const char *cmd)
    {
            struct pager_config c;
            c.cmd = cmd;
            c.want = -1;
            c.value = NULL;
            git_config(pager_command_config, &c);
            if (c.value)
                    pager_program = c.value;
            return c.want;
    }
    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;
            return pager;
    }

What's with the code? It's not simple, it's not uniform (e.g., setting env. var. PAGER to "cat" will cause git_pager() to return NULL, but setting preprocessor var. DEFAULT_PAGER to "cat" will cause it to return "cat"), and it's barely got any comments at all (a global variable has *no description whatsoever*).

I'd like to clean up the manual pages at least, but it would take me hours to figure out what the code *does*.

I know I'm griping here, but I thought that part of the reward for contributing to an open-source project was as a showcase of one's work. Commenting your code is what you learn first in programming.

Dale
Previous: Junio C HamanoNext: Matthieu Moy
Message 5 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.