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

[PATCH v5 1/5] config: factor out config file stack management

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Jul 11, 2013, 22:40 UTC
Message-ID
<20130711224032.GB26477@book-mint>
In-Reply-To
<20130711223614.GA26477@book-mint>

Because a config callback may start parsing a new file, the global context regarding the current config file is stored as a stack. Currently we only need to manage that stack from git_config_from_file. Let's factor it out to allow new sources of config data.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
 config.c | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/config.c b/config.c
index d04e815..c165c85 100644
--- a/config.c
+++ b/config.c
@@ -906,6 +906,32 @@ int git_default_config(const char *var, const char *value, void *dummy)
 	return 0;
 }
 
+/*
+ * The fields f and name of top need to be initialized before calling
+ * this function.
+ */
+static int do_config_from(struct config_file *top, config_fn_t fn, void *data)
+{
+	int ret;
+
+	/* push config-file parsing state stack */
+	top->prev = cf;
+	top->linenr = 1;
+	top->eof = 0;
+	strbuf_init(&top->value, 1024);
+	strbuf_init(&top->var, 1024);
+	cf = top;
+
+	ret = git_parse_file(fn, data);
+
+	/* pop config-file parsing state stack */
+	strbuf_release(&top->value);
+	strbuf_release(&top->var);
+	cf = top->prev;
+
+	return ret;
+}
+
 int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 {
 	int ret;
@@ -915,22 +941,10 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 	if (f) {
 		config_file top;
 
-		/* push config-file parsing state stack */
-		top.prev = cf;
 		top.f = f;
 		top.name = filename;
-		top.linenr = 1;
-		top.eof = 0;
-		strbuf_init(&top.value, 1024);
-		strbuf_init(&top.var, 1024);
-		cf = &top;
-
-		ret = git_parse_file(fn, data);
-
-		/* pop config-file parsing state stack */
-		strbuf_release(&top.value);
-		strbuf_release(&top.var);
-		cf = top.prev;
+
+		ret = do_config_from(&top, fn, data);
 
 		fclose(f);
 	}
-- 
1.8.3.2.773.gcfaae5b
Previous: Heiko VoigtNext: Heiko Voigt
Message 2 of 8 in “allow more sources for config values”
  1. 0/5 allow more sources for config valuesHeiko Voigt, Jul 11, 2013
  2. 1/5 config: factor out config file stack managementHeiko Voigt, Jul 11, 2013
  3. 2/5 config: drop cf validity check in get_next_char()Heiko Voigt, Jul 11, 2013
  4. 3/5 config: make parsing stack struct independent from actual data sourceHeiko Voigt, Jul 11, 2013
  5. 4/5 teach config --blob option to parse config from databaseHeiko Voigt, Jul 11, 2013
  6. 5/5 do not die when error in config parsing of buf occursHeiko Voigt, Jul 11, 2013
  7. Junio C HamanoJul 11, 2013
  8. Jeff KingJul 12, 2013

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.