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

[PATCH 3/4] pager: introduce `pager.*.command` and `.enable`

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Nov 5, 2017, 11:58 UTC
Message-ID
<a49ddb791a5a716a340660a57d01138d5aff84ce.1509879269.git.martin.agren@gmail.com>
In-Reply-To
<cover.1509879269.git.martin.agren@gmail.com>

`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.agren@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
Previous: Martin ÅgrenNext: Martin Ågren
Message 7 of 11 in “Git Open Source Weekend London 11th/12th November”
  1. Thomas GummererNov 1, 2017
  2. Jeff KingNov 4, 2017
  3. Philip OakleyNov 4, 2017
  4. 0/4 first steps towards pager.foo.{command,enable}Martin Ågren, Nov 5, 2017
  5. 1/4 t7006: document that `pager.foo` can be partially preservedMartin Ågren, Nov 5, 2017
  6. 2/4 pager: refactor `pager_command_config()`Martin Ågren, Nov 5, 2017
  7. 3/4 pager: introduce `pager.*.command` and `.enable`Martin Ågren, Nov 5, 2017
  8. 4/4 pager: make `pager.foo.command` imply `.enable=true`Martin Ågren, Nov 5, 2017
  9. Jeff KingNov 6, 2017
  10. Martin ÅgrenNov 7, 2017
  11. Patrick SteinhardtNov 5, 2017

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.