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

Re: v1.5.4 plans

From
Jeff King <peff@peff.net>
Date
Dec 11, 2007, 06:27 UTC
Message-ID
<20071211062733.GA21768@coredump.intra.peff.net>
In-Reply-To
<20071211061743.GA21718@coredump.intra.peff.net>
Subject: [PATCH 1/2] Support GIT_PAGER_IN_USE environment variable

When deciding whether or not to turn on automatic color support, git_config_colorbool checks whether stdout is a tty. However, because we run a pager, if stdout is not a tty, we must check whether it is because we started the pager. This used to be done by checking the pager_in_use variable.

This variable was set only when the git program being run started the pager; there was no way for an external program running git indicate that it had already started a pager. This patch allows a program to set GIT_PAGER_IN_USE to a true value to indicate that even though stdout is not a tty, it is because a pager is being used.

Signed-off-by: Jeff King <peff@peff.net>
---
A few notes:

We could also just put the color.pager logic in git-svn, or in Git.pm, and have it impact the stdout_is_tty argument; but the whole point of --get-colorbool is to consolidate that logic.

We convert pager_in_use to a function; we could also just set the variable early on, but I think this lazy evaluation is more robust.

This might have uses besides --get-colorbool (e.g., wrapper scripts which start their own pager can still have git sub-commands understand whether to turn on color).

 cache.h       |    2 +-
 color.c       |    2 +-
 environment.c |    1 -
 pager.c       |   15 ++++++++++++++-
 4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/cache.h b/cache.h
index 1bcb3df..27d90fe 100644
--- a/cache.h
+++ b/cache.h
@@ -608,7 +608,7 @@ extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char
 /* pager.c */
 extern void setup_pager(void);
 extern char *pager_program;
-extern int pager_in_use;
+extern int pager_in_use(void);
 extern int pager_use_color;
 
 extern char *editor_program;
diff --git a/color.c b/color.c
index 7bd424a..7f66c29 100644
--- a/color.c
+++ b/color.c
@@ -135,7 +135,7 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
  auto_color:
 	if (stdout_is_tty < 0)
 		stdout_is_tty = isatty(1);
-	if (stdout_is_tty || (pager_in_use && pager_use_color)) {
+	if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
 		char *term = getenv("TERM");
 		if (term && strcmp(term, "dumb"))
 			return 1;
diff --git a/environment.c b/environment.c
index f3e3d41..18a1c4e 100644
--- a/environment.c
+++ b/environment.c
@@ -31,7 +31,6 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
 size_t delta_base_cache_limit = 16 * 1024 * 1024;
 char *pager_program;
-int pager_in_use;
 int pager_use_color = 1;
 char *editor_program;
 char *excludes_file;
diff --git a/pager.c b/pager.c
index fb7a1a6..0376953 100644
--- a/pager.c
+++ b/pager.c
@@ -5,6 +5,8 @@
  * something different on Windows, for example.
  */
 
+static int spawned_pager;
+
 static void run_pager(const char *pager)
 {
 	/*
@@ -41,7 +43,7 @@ void setup_pager(void)
 	else if (!*pager || !strcmp(pager, "cat"))
 		return;
 
-	pager_in_use = 1; /* means we are emitting to terminal */
+	spawned_pager = 1; /* means we are emitting to terminal */
 
 	if (pipe(fd) < 0)
 		return;
@@ -70,3 +72,14 @@ void setup_pager(void)
 	die("unable to execute pager '%s'", pager);
 	exit(255);
 }
+
+int pager_in_use(void)
+{
+	const char *env;
+
+	if (spawned_pager)
+		return 1;
+
+	env = getenv("GIT_PAGER_IN_USE");
+	return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
+}
-- 
1.5.3.7.2230.g796d07-dirty
Previous: Jeff KingNext: Jeff King
Message 25 of 72 in “What's in git/spearce.git (stable)”
  1. Shawn O. PearceOct 22, 2007
  2. What's in git.git (stable)Junio C Hamano, Nov 1, 2007
  3. What's in git.git (stable)Junio C Hamano, Nov 4, 2007
  4. What's in git.git (stable)Junio C Hamano, Nov 8, 2007
  5. Pierre HabouzitNov 8, 2007
  6. What's in git.git (stable)Junio C Hamano, Nov 12, 2007
  7. What's in git.git (stable)Junio C Hamano, Nov 15, 2007
  8. What's in git.git (stable)Junio C Hamano, Nov 17, 2007
  9. What's in git.git (stable)Junio C Hamano, Nov 25, 2007
  10. What's in git.git (stable)Junio C Hamano, Dec 1, 2007
  11. What's in git.git (stable)Junio C Hamano, Dec 4, 2007
  12. What's in git.git (stable)Junio C Hamano, Dec 5, 2007
  13. What's in git.git (stable)Junio C Hamano, Dec 7, 2007
  14. What's in git.git (stable)Junio C Hamano, Dec 9, 2007
  15. v1.5.4 plansJunio C Hamano, Dec 10, 2007
  16. Jeff KingDec 10, 2007
  17. Junio C HamanoDec 11, 2007
  18. Junio C HamanoDec 11, 2007
  19. Jeff KingDec 11, 2007
  20. Junio C HamanoDec 11, 2007
  21. Jeff KingDec 11, 2007
  22. Junio C HamanoDec 11, 2007
  23. Jeff KingDec 11, 2007
  24. Jeff KingDec 11, 2007
  25. Jeff KingDec 11, 2007
  26. 2/2 git-svn: get color config from --get-colorboolJeff King, Dec 11, 2007
  27. Eric WongDec 12, 2007
  28. Jeff KingDec 11, 2007
  29. Andreas EricssonDec 11, 2007
  30. Jeff KingDec 11, 2007
  31. Nicolas PitreDec 11, 2007
  32. Johannes SchindelinDec 11, 2007
  33. Nicolas PitreDec 11, 2007
  34. Kristian HøgsbergDec 11, 2007
  35. Junio C HamanoDec 11, 2007
  36. Eric WongDec 12, 2007
  37. Junio C HamanoDec 12, 2007
  38. David D. KilzerDec 12, 2007
  39. David D. KilzerDec 31, 2007
  40. Fix race condition in t9119-git-svn-info.shDavid D. Kilzer, Dec 31, 2007
  41. Junio C HamanoDec 31, 2007
  42. Remove duplication in t9119-git-svn-info.shDavid D. Kilzer, Dec 31, 2007
  43. Eric WongJan 2, 2008
  44. David D. KilzerJan 2, 2008
  45. Junio C HamanoJan 2, 2008
  46. Junio C HamanoJan 2, 2008
  47. What's in git.git (stable frozen)Junio C Hamano, Dec 13, 2007
  48. git-commit: squelch needless message during an empty mergeJunio C Hamano, Dec 13, 2007
  49. Jeff KingDec 13, 2007
  50. Johannes SixtDec 13, 2007
  51. What's in git.git (stable frozen)Junio C Hamano, Dec 17, 2007
  52. What's in git.git (stable frozen)Junio C Hamano, Dec 23, 2007
  53. What's in git.git (stable frozen)Junio C Hamano, Jan 5, 2008
  54. Dan McGeeJan 5, 2008
  55. Junio C HamanoJan 6, 2008
  56. Junio C HamanoJan 6, 2008
  57. Dan McGeeJan 6, 2008
  58. Junio C HamanoJan 6, 2008
  59. Jeff KingJan 6, 2008
  60. Jeff KingJan 6, 2008
  61. Junio C HamanoJan 6, 2008
  62. Jeff KingJan 6, 2008
  63. Junio C HamanoJan 6, 2008
  64. Jeff KingJan 6, 2008
  65. Junio C HamanoJan 6, 2008
  66. Jeff KingJan 7, 2008
  67. Junio C HamanoJan 7, 2008
  68. Paul MackerrasJan 7, 2008
  69. Christian StimmingJan 7, 2008
  70. Junio C HamanoJan 7, 2008
  71. Steffen ProhaskaDec 17, 2007
  72. Junio C HamanoJan 5, 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.