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

[PATCH 8/8] config: do not respect includes for single-file --list

From
Jeff King <peff@peff.net>
Date
Feb 16, 2012, 08:10 UTC
Message-ID
<20120216081001.GH11843@sigill.intra.peff.net>
In-Reply-To
<20120216080102.GA11793@sigill.intra.peff.net>

The original include implementation tried not to impact calls to "git config" that look at a single file. However, since we called into git_config in a few places (e.g., --list), our respect_includes flag was not supported.

This patch teaches git_config_with_options a flag to respect includes (instead of doing so by default), and teaches git-config to use it.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/config.c          |    7 ++++---
 cache.h                   |    3 ++-
 config.c                  |   14 ++++++++------
 t/t1305-config-include.sh |    8 ++++++++
 4 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index 8901dd9..d41a9bf 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -316,7 +316,7 @@ static void get_color(const char *def_color)
 	get_color_found = 0;
 	parsed_color[0] = '\0';
 	git_config_with_options(git_get_color_config, NULL,
-				given_config_file);
+				given_config_file, respect_includes);
 
 	if (!get_color_found && def_color)
 		color_parse(def_color, "command line", parsed_color);
@@ -344,7 +344,7 @@ static int get_colorbool(int print)
 	get_colorbool_found = -1;
 	get_diff_color_found = -1;
 	git_config_with_options(git_get_colorbool_config, NULL,
-				given_config_file);
+				given_config_file, respect_includes);
 
 	if (get_colorbool_found < 0) {
 		if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -441,7 +441,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	if (actions == ACTION_LIST) {
 		check_argc(argc, 0, 0);
 		if (git_config_with_options(show_all_config, NULL,
-					    given_config_file) < 0) {
+					    given_config_file,
+					    respect_includes) < 0) {
 			if (given_config_file)
 				die_errno("unable to read config file '%s'",
 					  given_config_file);
diff --git a/cache.h b/cache.h
index 411c60d..ff54d6f 100644
--- a/cache.h
+++ b/cache.h
@@ -1115,7 +1115,8 @@ extern int git_config_from_file(config_fn_t fn, const char *, void *);
 extern void git_config_push_parameter(const char *text);
 extern int git_config_from_parameters(config_fn_t fn, void *data);
 extern int git_config(config_fn_t fn, void *);
-extern int git_config_with_options(config_fn_t fn, void *, const char *filename);
+extern int git_config_with_options(config_fn_t fn, void *,
+				   const char *filename, int respect_includes);
 extern int git_config_early(config_fn_t fn, void *, const char *repo_config);
 extern int git_parse_ulong(const char *, unsigned long *);
 extern int git_config_int(const char *, const char *);
diff --git a/config.c b/config.c
index e1d6857..ad03908 100644
--- a/config.c
+++ b/config.c
@@ -976,16 +976,18 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
 }
 
 int git_config_with_options(config_fn_t fn, void *data,
-			    const char *filename)
+			    const char *filename, int respect_includes)
 {
 	char *repo_config = NULL;
 	int ret;
 	struct config_include_data inc = CONFIG_INCLUDE_INIT;
 
-	inc.fn = fn;
-	inc.data = data;
-	fn = git_config_include;
-	data = &inc;
+	if (respect_includes) {
+		inc.fn = fn;
+		inc.data = data;
+		fn = git_config_include;
+		data = &inc;
+	}
 
 	/*
 	 * If we have a specific filename, use it. Otherwise, follow the
@@ -1003,7 +1005,7 @@ int git_config_with_options(config_fn_t fn, void *data,
 
 int git_config(config_fn_t fn, void *data)
 {
-	return git_config_with_options(fn, data, NULL);
+	return git_config_with_options(fn, data, NULL, 1);
 }
 
 /*
diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh
index 0a27ec4..f3e03a0 100755
--- a/t/t1305-config-include.sh
+++ b/t/t1305-config-include.sh
@@ -59,6 +59,14 @@ test_expect_success 'single file lookup does not expand includes by default' '
 	test_cmp expect actual
 '
 
+test_expect_success 'single file list does not expand includes by default' '
+	echo "[test]one = 1" >one &&
+	echo "[include]path = one" >.gitconfig &&
+	echo "include.path=one" >expect &&
+	git config -f .gitconfig --list >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'writing config file does not expand includes' '
 	echo "[test]one = 1" >one &&
 	echo "[include]path = one" >.gitconfig &&
-- 
1.7.9.1.4.g8ffed
Previous: Jeff KingNext: Junio C Hamano
Message 14 of 23 in “What's cooking in git.git (Feb 2012, #05; Mon, 13)”
  1. Junio C HamanoFeb 13, 2012
  2. An incremental update to "What's cooking"Junio C Hamano, Feb 14, 2012
  3. Jeff KingFeb 14, 2012
  4. Junio C HamanoFeb 14, 2012
  5. Jeff KingFeb 14, 2012
  6. 0/8 config-include fixesJeff King, Feb 16, 2012
  7. 1/8 t1300: add missing &&-chainingJeff King, Feb 16, 2012
  8. 2/8 config: copy the return value of prefix_filenameJeff King, Feb 16, 2012
  9. 3/8 config: teach git_config_set_multivar_in_file a default pathJeff King, Feb 16, 2012
  10. 4/8 config: teach git_config_rename_section a file argumentJeff King, Feb 16, 2012
  11. 5/8 config: provide a version of git_config with more optionsJeff King, Feb 16, 2012
  12. 6/8 config: stop using config_exclusive_filenameJeff King, Feb 16, 2012
  13. 7/8 config: eliminate config_exclusive_filenameJeff King, Feb 16, 2012
  14. 8/8 config: do not respect includes for single-file --listJeff King, Feb 16, 2012
  15. Junio C HamanoFeb 16, 2012
  16. Jeff KingFeb 17, 2012
  17. Junio C HamanoFeb 17, 2012
  18. Jeff KingFeb 17, 2012
  19. Jeff KingFeb 17, 2012
  20. 0/2 api-config documentation leftoversJeff King, Feb 17, 2012
  21. Junio C HamanoFeb 17, 2012
  22. 1/2 docs/api-config: minor clarificationsJeff King, Feb 17, 2012
  23. 2/2 docs/api-config: describe git_config_with_optionsJeff King, Feb 17, 2012

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.