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

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

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
May 11, 2013, 13:18 UTC
Message-ID
<20130511131852.GB17991@book-mint>
In-Reply-To
<20130511131721.GA17991@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 aefd80b..f0494f3 100644
--- a/config.c
+++ b/config.c
@@ -896,6 +896,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;
@@ -905,22 +931,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.rc1.53.g0126843
Previous: Heiko VoigtNext: Heiko Voigt
Message 2 of 11 in “allow more sources for config values”
  1. 0/5 allow more sources for config valuesHeiko Voigt, May 11, 2013
  2. 1/5 config: factor out config file stack managementHeiko Voigt, May 11, 2013
  3. 2/5 config: drop cf validity check in get_next_char()Heiko Voigt, May 11, 2013
  4. 3/5 config: make parsing stack struct independent from actual data sourceHeiko Voigt, May 11, 2013
  5. Junio C HamanoMay 13, 2013
  6. Heiko VoigtMay 13, 2013
  7. Junio C HamanoMay 13, 2013
  8. Jeff KingMay 14, 2013
  9. 4/5 teach config --blob option to parse config from databaseHeiko Voigt, May 11, 2013
  10. 5/5 do not die when error in config parsing of buf occursHeiko Voigt, May 11, 2013
  11. Junio C HamanoJul 1, 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.