summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorHeiko Voigt <hvoigt@hvoigt.net>2013-05-11 13:18:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-07-12 16:34:57 (GMT)
commitca4b5de28bad7d50b882794124ca4e57044a1cba (patch)
tree64a66c478baaad04ff0c1502eda4fb31a5f42fdf /config.c
parentb387c77b12953d543bf5efc3825b5be26d753f9c (diff)
downloadgit-ca4b5de28bad7d50b882794124ca4e57044a1cba.zip
git-ca4b5de28bad7d50b882794124ca4e57044a1cba.tar.gz
git-ca4b5de28bad7d50b882794124ca4e57044a1cba.tar.bz2
config: factor out config file stack management
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> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c42
1 files 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);
}