`pager.foo` conflates two concepts: how and whether `git foo` should
page. In particular, it can not be used to change *how* to page without
possibly also affecting *whether*.

Teach Git about two new config items, `pager.foo.command` and
`pager.foo.enable`.

Make this interact sanely with the existing `pager.foo`. For example,
make sure that `pager.foo=false` does not cause us to forget about a
command already configured through `pager.foo.command`, so that the
given pager command can be "re-activated" using
`pager.foo[.enable]=true`.

Where Documentation/ refers to `pager.tag`, write "the `pager.tag[.*]`
configuration options". In config.txt, `pager.blame` is mentioned more
as an example and it describes precisely the situation where one will
want to use the old mechanism, so leave that instance unchanged.

For symmetry with how `--paginate` disrespects any pager that might have
been configured with `pager.foo`, do the same for `pager.foo.command`.

Signed-off-by: Martin Ågren <martin.ag...@gmail.com>
---
 Documentation/config.txt  | 17 +++++++++++
 Documentation/git-tag.txt |  3 +-
 Documentation/git.txt     |  2 +-
 t/t7006-pager.sh          | 73 +++++++++++++++++++++++++++++++++++++++++++++++
 pager.c                   |  5 ++++
 5 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1ac0ae6ad..72558cc74 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2460,6 +2460,23 @@ pager.<cmd>::
        or `--no-pager` is specified on the command line, it takes
        precedence over this option.  To disable pagination for all
        commands, set `core.pager` or `GIT_PAGER` to `cat`.
++
+This is a less flexible alternative to `pager.<cmd>.command` and
+`pager.<cmd>.enable`. Using it with a boolean does the same as using
+`pager.<cmd>.enable`. Using it with a command does the same as using
+`pager.<cmd>.command` and `pager.<cmd>.enable=true`.
+
+pager.<cmd>.command::
+       Specifies the pager to use for the subcommand.
+       Whether the pager should be used is configured using
+       `pager.<cmd>.enable` or `pager.<cmd>=<boolean>`.
+
+pager.<cmd>.enable::
+       A boolean which turns on or off pagination of the output of a
+       particular Git subcommand when writing to a tty. If `--paginate`
+       or `--no-pager` is specified on the command line, it takes
+       precedence over this option.  To disable pagination for all
+       commands, set `core.pager` or `GIT_PAGER` to `cat`.
 
 pretty.<name>::
        Alias for a --pretty= format string, as specified in
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 956fc019f..9f9f33409 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -210,7 +210,8 @@ it in the repository configuration as follows:
     signingKey = <gpg-keyid>
 -------------------------------------
 
-`pager.tag` is only respected when listing tags, i.e., when `-l` is
+The `pager.tag[.*]` configuration options are only
+respected when listing tags, i.e., when `-l` is
 used or implied. The default is to use a pager.
 See linkgit:git-config[1].
 
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 7a1d629ca..0a2eff7a6 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -99,7 +99,7 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git 
config
 -p::
 --paginate::
        Pipe all output into 'less' (or if set, $PAGER) if standard
-       output is a terminal.  This overrides the `pager.<cmd>`
+       output is a terminal.  This overrides the `pager.<cmd>[.*]`
        configuration options (see the "Configuration Mechanism" section
        below).
 
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index e890b2f64..6966627dd 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -588,4 +588,77 @@ test_expect_success 'command with underscores does not 
complain' '
        test_cmp expect actual
 '
 
+test_expect_success 'setup' '
+       sane_unset PAGER GIT_PAGER GIT_PAGER_IN_USE &&
+       test_unconfig core.pager &&
+
+       git rev-list HEAD >rev-list &&
+       sed "s/^/foo:/" rev-list >expect &&
+
+       PAGER="cat >paginated.out" &&
+       export PAGER &&
+
+       test_unconfig pager.log &&
+       test_unconfig pager.rev-list
+'
+
+test_expect_success TTY 'configuration with .enable works' '
+       rm -f paginated.out &&
+       test_terminal git -c pager.log.enable=false log &&
+       ! test -e paginated.out
+'
+
+test_expect_success TTY '--paginate overrides .enable+.command' '
+       rm -f paginated.out &&
+       test_terminal git -c pager.log.command=bad -c pager.log.enable=false \
+                         --paginate log &&
+       test -e paginated.out
+'
+
+test_expect_success TTY '--no-pager overrides .enable' '
+       rm -f paginated.out &&
+       test_terminal git -c pager.rev-list.enable --no-pager rev-list HEAD &&
+       ! test -e paginated.out
+'
+
+test_expect_success TTY '.enable discards non-boolean' '
+       test_must_fail git -c pager.log.enable=bad log
+'
+
+test_expect_success TTY 'configuration remembers .command as .enable flips' '
+       >actual &&
+       test_terminal git -c pager.rev-list.command="sed s/^/foo:/ >actual" \
+                         -c pager.rev-list.enable=false \
+                         -c pager.rev-list.enable \
+                         rev-list HEAD &&
+       test_cmp expect actual
+'
+
+test_expect_success TTY 'configuration remembers old-style command as .enable 
flips' '
+       >actual &&
+       test_terminal git -c pager.rev-list="sed s/^/foo:/ >actual" \
+                         -c pager.rev-list.enable=false \
+                         -c pager.rev-list.enable \
+                         rev-list HEAD &&
+       test_cmp expect actual
+'
+
+test_expect_success TTY 'old-style config can override .enable' '
+       >actual &&
+       test_terminal git -c pager.rev-list.command="sed s/^/foo:/ >actual" \
+                         -c pager.rev-list.enable=false \
+                         -c pager.rev-list \
+                         rev-list HEAD &&
+       test_cmp expect actual
+'
+
+test_expect_success TTY 'old style config can override .command+.enable' '
+       >actual &&
+       test_terminal git -c pager.rev-list.command=bad \
+                         -c pager.rev-list.enable=false \
+                         -c pager.rev-list="sed s/^/foo:/ >actual" \
+                         rev-list HEAD &&
+       test_cmp expect actual
+'
+
 test_done
diff --git a/pager.c b/pager.c
index 8968f26f1..c8a6a01d8 100644
--- a/pager.c
+++ b/pager.c
@@ -206,6 +206,11 @@ static int pager_command_config(const char *var, const 
char *value, void *vdata)
                        free(data->value);
                        data->value = xstrdup(value);
                }
+       } else if (!strcmp(remainder, ".command")) {
+               free(data->value);
+               data->value = xstrdup(value);
+       } else if (!strcmp(remainder, ".enable")) {
+               data->want = git_config_bool(var, value);
        }
 
        return 0;
-- 
2.15.0.415.gac1375d7e

Reply via email to