git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Martin Ågren" <martin.agren@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, hkleynhans@bloomberg.net,
	Thomas Gummerer <t.gummerer@gmail.com>
Subject: [PATCH 3/4] pager: introduce `pager.*.command` and `.enable`
Date: Sun,  5 Nov 2017 12:58:21 +0100	[thread overview]
Message-ID: <a49ddb791a5a716a340660a57d01138d5aff84ce.1509879269.git.martin.agren@gmail.com> (raw)
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


  parent reply	other threads:[~2017-11-05 11:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-01 16:36 Git Open Source Weekend London 11th/12th November Thomas Gummerer
2017-11-04  9:28 ` Jeff King
2017-11-04 17:15   ` Philip Oakley
2017-11-05 11:58   ` [PATCH/DONOTAPPLY 0/4] first steps towards pager.foo.{command,enable} Martin Ågren
2017-11-05 11:58     ` [PATCH 1/4] t7006: document that `pager.foo` can be partially preserved Martin Ågren
2017-11-05 11:58     ` [PATCH 2/4] pager: refactor `pager_command_config()` Martin Ågren
2017-11-05 11:58     ` Martin Ågren [this message]
2017-11-05 11:58     ` [PATCH 4/4] pager: make `pager.foo.command` imply `.enable=true` Martin Ågren
2017-11-06 10:48     ` [PATCH/DONOTAPPLY 0/4] first steps towards pager.foo.{command,enable} Jeff King
2017-11-07 20:46       ` Martin Ågren
2017-11-05 12:42 ` Git Open Source Weekend London 11th/12th November Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a49ddb791a5a716a340660a57d01138d5aff84ce.1509879269.git.martin.agren@gmail.com \
    --to=martin.agren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hkleynhans@bloomberg.net \
    --cc=peff@peff.net \
    --cc=t.gummerer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).