X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=config.c;h=4b0a82040e7982ab936ed52b2bb3405bc85b80f8;hb=9d14017adafc4829efc9e1393653579ad1d8ed71;hp=cdcf5836c6c374eb59e80f89dbcf525fd6bf780f;hpb=bff6e86b3d01febaa2d73ff4e890f091999e9e28;p=git.git diff --git a/config.c b/config.c index cdcf5836c..4b0a82040 100644 --- a/config.c +++ b/config.c @@ -8,6 +8,7 @@ #include "cache.h" #include "exec_cmd.h" #include "strbuf.h" +#include "quote.h" #define MAXNAME (256) @@ -34,6 +35,19 @@ static void lowercase(char *p) *p = tolower(*p); } +void git_config_push_parameter(const char *text) +{ + struct strbuf env = STRBUF_INIT; + const char *old = getenv(CONFIG_DATA_ENVIRONMENT); + if (old) { + strbuf_addstr(&env, old); + strbuf_addch(&env, ' '); + } + sq_quote_buf(&env, text); + setenv(CONFIG_DATA_ENVIRONMENT, env.buf, 1); + strbuf_release(&env); +} + int git_config_parse_parameter(const char *text) { struct config_item *ct; @@ -61,6 +75,37 @@ int git_config_parse_parameter(const char *text) return 0; } +int git_config_parse_environment(void) { + const char *env = getenv(CONFIG_DATA_ENVIRONMENT); + char *envw; + const char **argv = NULL; + int nr = 0, alloc = 0; + int i; + + if (!env) + return 0; + /* sq_dequote will write over it */ + envw = xstrdup(env); + + if (sq_dequote_to_argv(envw, &argv, &nr, &alloc) < 0) { + free(envw); + return error("bogus format in " CONFIG_DATA_ENVIRONMENT); + } + + for (i = 0; i < nr; i++) { + if (git_config_parse_parameter(argv[i]) < 0) { + error("bogus config parameter: %s", argv[i]); + free(argv); + free(envw); + return -1; + } + } + + free(argv); + free(envw); + return 0; +} + static int get_next_char(void) { int c; @@ -560,6 +605,9 @@ static int git_default_core_config(const char *var, const char *value) if (!strcmp(var, "core.editor")) return git_config_string(&editor_program, var, value); + if (!strcmp(var, "core.askpass")) + return git_config_string(&askpass_program, var, value); + if (!strcmp(var, "core.excludesfile")) return git_config_pathname(&excludes_file, var, value); @@ -773,7 +821,14 @@ int git_config_global(void) int git_config_from_parameters(config_fn_t fn, void *data) { + static int loaded_environment; const struct config_item *ct; + + if (!loaded_environment) { + if (git_config_parse_environment() < 0) + return -1; + loaded_environment = 1; + } for (ct = config_parameters; ct; ct = ct->next) if (fn(ct->name, ct->value, data) < 0) return -1; @@ -812,10 +867,9 @@ int git_config(config_fn_t fn, void *data) } free(repo_config); - if (config_parameters) { - ret += git_config_from_parameters(fn, data); + ret += git_config_from_parameters(fn, data); + if (config_parameters) found += 1; - } if (found == 0) return -1;