Skip to content

Commit ca4b5de

Browse files
hvoigtgitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b387c77 commit ca4b5de

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

config.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,32 @@ int git_default_config(const char *var, const char *value, void *dummy)
896896
return 0;
897897
}
898898

899+
/*
900+
* The fields f and name of top need to be initialized before calling
901+
* this function.
902+
*/
903+
static int do_config_from(struct config_file *top, config_fn_t fn, void *data)
904+
{
905+
int ret;
906+
907+
/* push config-file parsing state stack */
908+
top->prev = cf;
909+
top->linenr = 1;
910+
top->eof = 0;
911+
strbuf_init(&top->value, 1024);
912+
strbuf_init(&top->var, 1024);
913+
cf = top;
914+
915+
ret = git_parse_file(fn, data);
916+
917+
/* pop config-file parsing state stack */
918+
strbuf_release(&top->value);
919+
strbuf_release(&top->var);
920+
cf = top->prev;
921+
922+
return ret;
923+
}
924+
899925
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
900926
{
901927
int ret;
@@ -905,22 +931,10 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
905931
if (f) {
906932
config_file top;
907933

908-
/* push config-file parsing state stack */
909-
top.prev = cf;
910934
top.f = f;
911935
top.name = filename;
912-
top.linenr = 1;
913-
top.eof = 0;
914-
strbuf_init(&top.value, 1024);
915-
strbuf_init(&top.var, 1024);
916-
cf = &top;
917-
918-
ret = git_parse_file(fn, data);
919-
920-
/* pop config-file parsing state stack */
921-
strbuf_release(&top.value);
922-
strbuf_release(&top.var);
923-
cf = top.prev;
936+
937+
ret = do_config_from(&top, fn, data);
924938

925939
fclose(f);
926940
}

0 commit comments

Comments
 (0)