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@xxxxxxxxxx> --- Peff, I hope you do not mind that I totally copied your commit message here. The patch takes a different approach though. If you like we can add a Commit-Message-by: Jeff King <peff@xxxxxxxx> here :-) Cheers Heiko config.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/config.c b/config.c index aefd80b..2c299dc 100644 --- a/config.c +++ b/config.c @@ -896,6 +896,28 @@ int git_default_config(const char *var, const char *value, void *dummy) return 0; } +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 +927,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 = ⊤ - - 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.2.rc0.26.gf7384c5 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html