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

Re: To page or not to page

From
Jeff King <peff@peff.net>
Date
May 2, 2008, 15:36 UTC
Message-ID
<20080502153628.GA6294@sigill.intra.peff.net>
In-Reply-To
<20080502060930.GA1079@sigill.intra.peff.net>
On Fri, May 02, 2008 at 02:09:30AM -0400, Jeff King wrote:
Show 7 quoted lines
> > I agree with you; I don't like it at all. Probably whether or not to use
> > a pager for a given command should be controlled by a "pager.<cmd>"
> > config variable.
> 
> Here is a quick and dirty patch to do that. It should probably be split
> into two (there is a big code movement of the commands array), and it
> needs documentation and tests. But I'm going to sleep for now.

Here is a cleaner patch. Rather than looking at all of pager.*, it waits until we see which command to execute, and just looks up pager.cmd (we end up having to parse the config the same number of times). And we don't have to munge the static global commands array, which just feels a little cleaner.

Still no documentation, and still not a "real" patch; I am curious to see the list reaction on the issues I raised elsewhere in the thread (like the user-facing inconsistencies).

---
 git.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/git.c b/git.c
index 89b431f..68d8b37 100644
--- a/git.c
+++ b/git.c
@@ -230,6 +230,25 @@ struct cmd_struct {
 	int option;
 };
 
+static const char *pager_command_key;
+static int pager_command_value;
+
+int pager_command_config(const char *var, const char *value)
+{
+	if (!prefixcmp(var, "pager.") && !strcmp(var + 6, pager_command_key))
+		pager_command_value = git_config_bool(var, value);
+	return 0;
+}
+
+/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
+int check_pager_config(const char *cmd)
+{
+	pager_command_key = cmd;
+	pager_command_value = -1;
+	git_config(pager_command_config);
+	return pager_command_value;
+}
+
 static int run_command(struct cmd_struct *p, int argc, const char **argv)
 {
 	int status;
@@ -239,8 +258,17 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
 	prefix = NULL;
 	if (p->option & RUN_SETUP)
 		prefix = setup_git_directory();
-	if (p->option & USE_PAGER)
+	switch (check_pager_config(p->cmd)) {
+	case 0:
+		break;
+	case 1:
 		setup_pager();
+		break;
+	default:
+		if (p->option & USE_PAGER)
+			setup_pager();
+		break;
+	}
 	if (p->option & NEED_WORK_TREE)
 		setup_work_tree();
 
-- 
1.5.5.1.221.ga481.dirty
Previous: Jeff King
Message 31 of 31 in “To page or not to page”
  1. Kevin BallardMay 2, 2008
  2. Jeff KingMay 2, 2008
  3. Junio C HamanoMay 2, 2008
  4. Kevin BallardMay 2, 2008
  5. Junio C HamanoMay 2, 2008
  6. Bart TrojanowskiMay 2, 2008
  7. Pedro MeloMay 2, 2008
  8. Kevin BallardMay 2, 2008
  9. Wincent ColaiutaMay 2, 2008
  10. Jeff KingMay 2, 2008
  11. Pedro MeloMay 2, 2008
  12. Aidan Van DykMay 2, 2008
  13. Wincent ColaiutaMay 2, 2008
  14. Kevin BallardMay 2, 2008
  15. Wincent ColaiutaMay 2, 2008
  16. Jeff KingMay 2, 2008
  17. Johannes SchindelinMay 2, 2008
  18. Jeff KingMay 2, 2008
  19. Junio C HamanoMay 2, 2008
  20. Jeff KingMay 2, 2008
  21. Junio C HamanoMay 2, 2008
  22. Jeff KingMay 5, 2008
  23. Jeff KingMay 6, 2008
  24. Jeff KingMay 6, 2008
  25. Junio C HamanoMay 11, 2008
  26. Jeff KingMay 16, 2008
  27. Jeff KingMay 16, 2008
  28. Johannes SchindelinMay 16, 2008
  29. Jakub NarebskiMay 2, 2008
  30. Jeff KingMay 2, 2008
  31. Jeff KingMay 2, 2008

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.