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

[PATCH/RFC 4/7] read_early_config(): special-case `init` and `clone`

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 8, 2016, 15:36 UTC
Message-ID
<fcc3262f1245b6fe846f434ae9d500aa953e39f7.1481211338.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1481211338.git.johannes.schindelin@gmx.de>

The `init` and `clone` commands create their own .git/ directory, therefore we must be careful not to read any repository config when determining the pager settings.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/am.c    |  2 +-
 builtin/blame.c |  2 +-
 builtin/grep.c  |  4 ++--
 builtin/log.c   |  4 ++--
 builtin/var.c   |  2 +-
 cache.h         |  9 +++++----
 config.c        |  4 ++--
 diff.c          |  4 ++--
 git.c           | 16 ++++++++--------
 pager.c         | 13 +++++++------
 10 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 6981f42ce9..e6c2ee01bc 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1791,7 +1791,7 @@ static int do_interactive(struct am_state *state)
 			}
 			strbuf_release(&msg);
 		} else if (*reply == 'v' || *reply == 'V') {
-			const char *pager = git_pager(1);
+			const char *pager = git_pager(1, 1);
 			struct child_process cp = CHILD_PROCESS_INIT;
 
 			if (!pager)
diff --git a/builtin/blame.c b/builtin/blame.c
index 4ddfadb71f..5b7daa3686 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2913,7 +2913,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 	assign_blame(&sb, opt);
 
 	if (!incremental)
-		setup_pager();
+		setup_pager(1);
 
 	free(final_commit_name);
 
diff --git a/builtin/grep.c b/builtin/grep.c
index 8887b6addb..363a753369 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -800,7 +800,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	}
 
 	if (show_in_pager == default_pager)
-		show_in_pager = git_pager(1);
+		show_in_pager = git_pager(1, 1);
 	if (show_in_pager) {
 		opt.color = 0;
 		opt.name_only = 1;
@@ -896,7 +896,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	}
 
 	if (!show_in_pager && !opt.status_only)
-		setup_pager();
+		setup_pager(1);
 
 	if (!use_index && (untracked || cached))
 		die(_("--cached or --untracked cannot be used with --no-index."));
diff --git a/builtin/log.c b/builtin/log.c
index 55d20cc2d8..96618d38cb 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -203,7 +203,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 	if (rev->line_level_traverse)
 		line_log_init(rev, line_cb.prefix, &line_cb.args);
 
-	setup_pager();
+	setup_pager(1);
 }
 
 static void cmd_log_init(int argc, const char **argv, const char *prefix,
@@ -1600,7 +1600,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	if (!use_stdout)
 		output_directory = set_outdir(prefix, output_directory);
 	else
-		setup_pager();
+		setup_pager(1);
 
 	if (output_directory) {
 		if (rev.diffopt.use_color != GIT_COLOR_ALWAYS)
diff --git a/builtin/var.c b/builtin/var.c
index aedbb53a2d..879867b842 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -19,7 +19,7 @@ static const char *editor(int flag)
 
 static const char *pager(int flag)
 {
-	const char *pgm = git_pager(1);
+	const char *pgm = git_pager(1, 1);
 
 	if (!pgm)
 		pgm = "cat";
diff --git a/cache.h b/cache.h
index 96e0cb2523..6627239de8 100644
--- a/cache.h
+++ b/cache.h
@@ -1325,7 +1325,7 @@ extern const char *fmt_name(const char *name, const char *email);
 extern const char *ident_default_name(void);
 extern const char *ident_default_email(void);
 extern const char *git_editor(void);
-extern const char *git_pager(int stdout_is_tty);
+extern const char *git_pager(int stdout_is_tty, int discover_git_dir);
 extern int git_ident_config(const char *, const char *, void *);
 extern void reset_ident_date(void);
 
@@ -1692,7 +1692,8 @@ extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
 					const char *name, const char *buf, size_t len, void *data);
 extern void git_config_push_parameter(const char *text);
 extern int git_config_from_parameters(config_fn_t fn, void *data);
-extern void read_early_config(config_fn_t cb, void *data);
+extern void read_early_config(config_fn_t cb, void *data,
+			      int discover_git_dir);
 extern void git_config(config_fn_t fn, void *);
 extern int git_config_with_options(config_fn_t fn, void *,
 				   struct git_config_source *config_source,
@@ -1888,12 +1889,12 @@ __attribute__((format (printf, 2, 3)))
 extern void write_file(const char *path, const char *fmt, ...);
 
 /* pager.c */
-extern void setup_pager(void);
+extern void setup_pager(int discover_git_dir);
 extern int pager_in_use(void);
 extern int pager_use_color;
 extern int term_columns(void);
 extern int decimal_width(uintmax_t);
-extern int check_pager_config(const char *cmd);
+extern int check_pager_config(const char *cmd, int discover_git_dir);
 extern void prepare_pager_args(struct child_process *, const char *pager);
 
 extern const char *editor_program;
diff --git a/config.c b/config.c
index 104c3c3dcd..4c756edca1 100644
--- a/config.c
+++ b/config.c
@@ -1385,7 +1385,7 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
 	}
 }
 
-void read_early_config(config_fn_t cb, void *data)
+void read_early_config(config_fn_t cb, void *data, int discover_git_dir)
 {
 	git_config_with_options(cb, data, NULL, 1);
 
@@ -1407,7 +1407,7 @@ void read_early_config(config_fn_t cb, void *data)
 	 * valid repository), and would rarely make things worse (i.e., you do
 	 * not generally have a .git/config file sitting around).
 	 */
-	if (!have_git_dir()) {
+	if (discover_git_dir && !have_git_dir()) {
 		struct git_config_source repo_config;
 
 		memset(&repo_config, 0, sizeof(repo_config));
diff --git a/diff.c b/diff.c
index ec8728362d..0769c0590a 100644
--- a/diff.c
+++ b/diff.c
@@ -5267,6 +5267,6 @@ void setup_diff_pager(struct diff_options *opt)
 	 * --exit-code" in hooks and other scripts, we do not do so.
 	 */
 	if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
-	    check_pager_config("diff") != 0)
-		setup_pager();
+	    check_pager_config("diff", 1) != 0)
+		setup_pager(1);
 }
diff --git a/git.c b/git.c
index 61df78afc8..2b007b83ec 100644
--- a/git.c
+++ b/git.c
@@ -61,13 +61,13 @@ static void restore_env(int external_alias)
 	}
 }
 
-static void commit_pager_choice(void) {
+static void commit_pager_choice(int discover_git_dir) {
 	switch (use_pager) {
 	case 0:
 		setenv("GIT_PAGER", "cat", 1);
 		break;
 	case 1:
-		setup_pager();
+		setup_pager(discover_git_dir);
 		break;
 	default:
 		break;
@@ -261,7 +261,7 @@ static int handle_alias(int *argcp, const char ***argv)
 		if (alias_string[0] == '!') {
 			struct child_process child = CHILD_PROCESS_INIT;
 
-			commit_pager_choice();
+			commit_pager_choice(1);
 			restore_env(1);
 
 			child.use_shell = 1;
@@ -349,7 +349,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 		}
 
 		if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY))
-			use_pager = check_pager_config(p->cmd);
+			use_pager = check_pager_config(p->cmd, !(p->option & CREATES_GIT_DIR));
 		if (use_pager == -1 && p->option & USE_PAGER)
 			use_pager = 1;
 
@@ -357,7 +357,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 		    startup_info->have_repository) /* get_git_dir() may set up repo, avoid that */
 			trace_repo_setup(prefix);
 	}
-	commit_pager_choice();
+	commit_pager_choice(!(p->option & CREATES_GIT_DIR));
 
 	if (!help && get_super_prefix()) {
 		if (!(p->option & SUPPORT_SUPER_PREFIX))
@@ -584,8 +584,8 @@ static void execv_dashed_external(const char **argv)
 		die("%s doesn't support --super-prefix", argv[0]);
 
 	if (use_pager == -1)
-		use_pager = check_pager_config(argv[0]);
-	commit_pager_choice();
+		use_pager = check_pager_config(argv[0], 1);
+	commit_pager_choice(1);
 
 	strbuf_addf(&cmd, "git-%s", argv[0]);
 
@@ -688,7 +688,7 @@ int cmd_main(int argc, const char **argv)
 		skip_prefix(argv[0], "--", &argv[0]);
 	} else {
 		/* The user didn't specify a command; give them help */
-		commit_pager_choice();
+		commit_pager_choice(1);
 		printf("usage: %s\n\n", git_usage_string);
 		list_common_cmds_help();
 		printf("\n%s\n", _(git_more_info_string));
diff --git a/pager.c b/pager.c
index 73ca8bc3b1..16b3cbe232 100644
--- a/pager.c
+++ b/pager.c
@@ -43,7 +43,7 @@ static int core_pager_config(const char *var, const char *value, void *data)
 	return 0;
 }
 
-const char *git_pager(int stdout_is_tty)
+const char *git_pager(int stdout_is_tty, int discover_git_dir)
 {
 	const char *pager;
 
@@ -53,7 +53,8 @@ const char *git_pager(int stdout_is_tty)
 	pager = getenv("GIT_PAGER");
 	if (!pager) {
 		if (!pager_program)
-			read_early_config(core_pager_config, NULL);
+			read_early_config(core_pager_config, NULL,
+					  discover_git_dir);
 		pager = pager_program;
 	}
 	if (!pager)
@@ -100,9 +101,9 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager)
 	setup_pager_env(&pager_process->env_array);
 }
 
-void setup_pager(void)
+void setup_pager(int discover_git_dir)
 {
-	const char *pager = git_pager(isatty(1));
+	const char *pager = git_pager(isatty(1), discover_git_dir);
 
 	if (!pager)
 		return;
@@ -208,7 +209,7 @@ static int pager_command_config(const char *var, const char *value, void *vdata)
 }
 
 /* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
-int check_pager_config(const char *cmd)
+int check_pager_config(const char *cmd, int discover_git_dir)
 {
 	struct pager_command_config_data data;
 
@@ -216,7 +217,7 @@ int check_pager_config(const char *cmd)
 	data.want = -1;
 	data.value = NULL;
 
-	read_early_config(pager_command_config, &data);
+	read_early_config(pager_command_config, &data, discover_git_dir);
 
 	if (data.value)
 		pager_program = data.value;
-- 
2.11.0.rc3.windows.1
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 5 of 123 in “Pie-in-the-sky attempt to fix the early config”
  1. 0/7 Pie-in-the-sky attempt to fix the early configJohannes Schindelin, Dec 8, 2016
  2. 3/7 Mark builtins that create .git/ directoriesJohannes Schindelin, Dec 8, 2016
  3. 1/7 Make read_early_config() reusableJohannes Schindelin, Dec 8, 2016
  4. 2/7 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Dec 8, 2016
  5. 4/7 read_early_config(): special-case `init` and `clone`Johannes Schindelin, Dec 8, 2016
  6. 5/7 read_early_config(): really discover .git/Johannes Schindelin, Dec 8, 2016
  7. 7/7 WIP: read_early_config(): add testsJohannes Schindelin, Dec 8, 2016
  8. 6/7 WIP read_config_early(): respect ceiling directoriesJohannes Schindelin, Dec 8, 2016
  9. Jeff KingDec 8, 2016
  10. Johannes SchindelinDec 9, 2016
  11. Jeff KingDec 9, 2016
  12. Duy NguyenDec 9, 2016
  13. Johannes SchindelinDec 9, 2016
  14. 0/9 Fix the early configJohannes Schindelin, Mar 3, 2017
  15. 3/9 setup_git_directory(): avoid changing global state during discoveryJohannes Schindelin, Mar 3, 2017
  16. Jeff KingMar 3, 2017
  17. Johannes SchindelinMar 3, 2017
  18. 4/9 Export the discover_git_directory() functionJohannes Schindelin, Mar 3, 2017
  19. Jeff KingMar 3, 2017
  20. Johannes SchindelinMar 3, 2017
  21. 2/9 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 3, 2017
  22. Jeff KingMar 3, 2017
  23. Johannes SchindelinMar 3, 2017
  24. Jeff KingMar 3, 2017
  25. Johannes SchindelinMar 3, 2017
  26. 1/9 t7006: replace dubious testJohannes Schindelin, Mar 3, 2017
  27. Jeff KingMar 3, 2017
  28. Johannes SchindelinMar 3, 2017
  29. 5/9 Make read_early_config() reusableJohannes Schindelin, Mar 3, 2017
  30. Jeff KingMar 3, 2017
  31. Johannes SchindelinMar 3, 2017
  32. 6/9 read_early_config(): special-case builtins that create a repositoryJohannes Schindelin, Mar 3, 2017
  33. Jeff KingMar 3, 2017
  34. Johannes SchindelinMar 3, 2017
  35. 7/9 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 3, 2017
  36. Jeff KingMar 3, 2017
  37. 9/9 Test read_early_config()Johannes Schindelin, Mar 3, 2017
  38. Jeff KingMar 3, 2017
  39. Johannes SchindelinMar 3, 2017
  40. 8/9 read_early_config(): really discover .git/Johannes Schindelin, Mar 3, 2017
  41. Jeff KingMar 3, 2017
  42. Johannes SchindelinMar 3, 2017
  43. Jeff KingMar 3, 2017
  44. Johannes SchindelinMar 3, 2017
  45. 0/9 Fix the early configJohannes Schindelin, Mar 3, 2017
  46. 1/9 t7006: replace dubious testJohannes Schindelin, Mar 3, 2017
  47. 2/9 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 3, 2017
  48. 3/9 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 3, 2017
  49. 4/9 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 3, 2017
  50. 7/9 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 3, 2017
  51. 5/9 Export the discover_git_directory() functionJohannes Schindelin, Mar 3, 2017
  52. 6/9 Make read_early_config() reusableJohannes Schindelin, Mar 3, 2017
  53. 9/9 Test read_early_config()Johannes Schindelin, Mar 3, 2017
  54. 8/9 read_early_config(): really discover .git/Johannes Schindelin, Mar 3, 2017
  55. Junio C HamanoMar 3, 2017
  56. Johannes SchindelinMar 7, 2017
  57. Johannes SchindelinMar 7, 2017
  58. Jeff KingMar 4, 2017
  59. Junio C HamanoMar 5, 2017
  60. Johannes SchindelinMar 7, 2017
  61. Jeff KingMar 8, 2017
  62. Johannes SchindelinMar 8, 2017
  63. Jeff KingMar 8, 2017
  64. Junio C HamanoMar 8, 2017
  65. Jeff KingMar 8, 2017
  66. Junio C HamanoMar 8, 2017
  67. Johannes SchindelinMar 9, 2017
  68. Jeff KingMar 9, 2017
  69. Junio C HamanoMar 10, 2017
  70. 00/10 Fix the early configJohannes Schindelin, Mar 7, 2017
  71. 01/10 t7006: replace dubious testJohannes Schindelin, Mar 7, 2017
  72. 02/10 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 7, 2017
  73. 03/10 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 7, 2017
  74. 04/10 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 7, 2017
  75. Junio C HamanoMar 7, 2017
  76. Brandon WilliamsMar 7, 2017
  77. Johannes SchindelinMar 8, 2017
  78. Brandon WilliamsMar 8, 2017
  79. 05/10 Introduce the discover_git_directory() functionJohannes Schindelin, Mar 7, 2017
  80. 06/10 Make read_early_config() reusableJohannes Schindelin, Mar 7, 2017
  81. 08/10 read_early_config(): really discover .git/Johannes Schindelin, Mar 7, 2017
  82. 10/10 setup_git_directory_gently_1(): avoid die()ingJohannes Schindelin, Mar 7, 2017
  83. 09/10 Test read_early_config()Johannes Schindelin, Mar 7, 2017
  84. 07/10 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 7, 2017
  85. 00/11 Fix the early configJohannes Schindelin, Mar 9, 2017
  86. 01/11 t7006: replace dubious testJohannes Schindelin, Mar 9, 2017
  87. 02/11 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 9, 2017
  88. 03/11 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 9, 2017
  89. 04/11 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 9, 2017
  90. Junio C HamanoMar 10, 2017
  91. 05/11 Introduce the discover_git_directory() functionJohannes Schindelin, Mar 9, 2017
  92. 07/11 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 9, 2017
  93. 08/11 read_early_config(): really discover .git/Johannes Schindelin, Mar 9, 2017
  94. 06/11 Make read_early_config() reusableJohannes Schindelin, Mar 9, 2017
  95. 09/11 Test read_early_config()Johannes Schindelin, Mar 9, 2017
  96. Junio C HamanoMar 10, 2017
  97. Johannes SchindelinMar 13, 2017
  98. Junio C HamanoMar 13, 2017
  99. 10/11 setup_git_directory_gently_1(): avoid die()ingJohannes Schindelin, Mar 9, 2017
  100. Junio C HamanoMar 10, 2017
  101. Johannes SchindelinMar 13, 2017
  102. Junio C HamanoMar 13, 2017
  103. Junio C HamanoMar 13, 2017
  104. Johannes SchindelinMar 13, 2017
  105. Junio C HamanoMar 13, 2017
  106. 11/11 t1309: document cases where we would want early config not to die()Johannes Schindelin, Mar 9, 2017
  107. 00/12 Fix the early configJohannes Schindelin, Mar 13, 2017
  108. 01/12 t7006: replace dubious testJohannes Schindelin, Mar 13, 2017
  109. 02/12 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 13, 2017
  110. 03/12 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 13, 2017
  111. Junio C HamanoMar 13, 2017
  112. Johannes SchindelinMar 13, 2017
  113. 04/12 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 13, 2017
  114. 05/12 Introduce the discover_git_directory() functionJohannes Schindelin, Mar 13, 2017
  115. 08/12 read_early_config(): really discover .git/Johannes Schindelin, Mar 13, 2017
  116. 07/12 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 13, 2017
  117. 06/12 Make read_early_config() reusableJohannes Schindelin, Mar 13, 2017
  118. 09/12 Add t1309 to test read_early_config()Johannes Schindelin, Mar 13, 2017
  119. 10/12 setup_git_directory_gently_1(): avoid die()ingJohannes Schindelin, Mar 13, 2017
  120. 11/12 t1309: document cases where we would want early config not to die()Johannes Schindelin, Mar 13, 2017
  121. 12/12 setup.c: mention unresolved problemsJohannes Schindelin, Mar 13, 2017
  122. Junio C HamanoMar 13, 2017
  123. Jeff KingMar 14, 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.