X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=config.c;h=9b6b1df212252901b2e577009651ba8d26e4f25a;hb=127f04522292fc62152762405c92d6acca4dbcb5;hp=37385ce9d338ecbd2556cef9455000784ebab7e5;hpb=11a1a49a16a52ff9b684a430d68b8982ed313427;p=git.git diff --git a/config.c b/config.c index 37385ce9d..9b6b1df21 100644 --- a/config.c +++ b/config.c @@ -7,6 +7,7 @@ */ #include "cache.h" #include "exec_cmd.h" +#include "strbuf.h" #define MAXNAME (256) @@ -18,6 +19,48 @@ static int zlib_compression_seen; const char *config_exclusive_filename = NULL; +struct config_item +{ + struct config_item *next; + char *name; + char *value; +}; +static struct config_item *config_parameters; +static struct config_item **config_parameters_tail = &config_parameters; + +static void lowercase(char *p) +{ + for (; *p; p++) + *p = tolower(*p); +} + +int git_config_parse_parameter(const char *text) +{ + struct config_item *ct; + struct strbuf tmp = STRBUF_INIT; + struct strbuf **pair; + strbuf_addstr(&tmp, text); + pair = strbuf_split(&tmp, '='); + if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') + strbuf_setlen(pair[0], pair[0]->len - 1); + strbuf_trim(pair[0]); + if (!pair[0]->len) { + strbuf_list_free(pair); + return -1; + } + ct = xcalloc(1, sizeof(struct config_item)); + ct->name = strbuf_detach(pair[0], NULL); + if (pair[1]) { + strbuf_trim(pair[1]); + ct->value = strbuf_detach(pair[1], NULL); + } + strbuf_list_free(pair); + lowercase(ct->name); + *config_parameters_tail = ct; + config_parameters_tail = &ct->next; + return 0; +} + static int get_next_char(void) { int c; @@ -322,17 +365,30 @@ unsigned long git_config_ulong(const char *name, const char *value) return ret; } -int git_config_bool_or_int(const char *name, const char *value, int *is_bool) +int git_config_maybe_bool(const char *name, const char *value) { - *is_bool = 1; if (!value) return 1; if (!*value) return 0; - if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on")) + if (!strcasecmp(value, "true") + || !strcasecmp(value, "yes") + || !strcasecmp(value, "on")) return 1; - if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off")) + if (!strcasecmp(value, "false") + || !strcasecmp(value, "no") + || !strcasecmp(value, "off")) return 0; + return -1; +} + +int git_config_bool_or_int(const char *name, const char *value, int *is_bool) +{ + int v = git_config_maybe_bool(name, value); + if (0 <= v) { + *is_bool = 1; + return v; + } *is_bool = 0; return git_config_int(name, value); } @@ -518,6 +574,11 @@ static int git_default_core_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.sparsecheckout")) { + core_apply_sparse_checkout = git_config_bool(var, value); + return 0; + } + /* Add other config variables here and to Documentation/config.txt. */ return 0; } @@ -528,8 +589,7 @@ static int git_default_user_config(const char *var, const char *value) if (!value) return config_error_nonbool(var); strlcpy(git_default_name, value, sizeof(git_default_name)); - if (git_default_email[0]) - user_ident_explicitly_given = 1; + user_ident_explicitly_given |= IDENT_NAME_GIVEN; return 0; } @@ -537,8 +597,7 @@ static int git_default_user_config(const char *var, const char *value) if (!value) return config_error_nonbool(var); strlcpy(git_default_email, value, sizeof(git_default_email)); - if (git_default_name[0]) - user_ident_explicitly_given = 1; + user_ident_explicitly_given |= IDENT_MAIL_GIVEN; return 0; } @@ -680,7 +739,7 @@ const char *git_etc_gitconfig(void) return system_wide; } -static int git_env_bool(const char *k, int def) +int git_env_bool(const char *k, int def) { const char *v = getenv(k); return v ? git_config_bool(k, v) : def; @@ -696,6 +755,15 @@ int git_config_global(void) return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0); } +int git_config_from_parameters(config_fn_t fn, void *data) +{ + const struct config_item *ct; + for (ct = config_parameters; ct; ct = ct->next) + if (fn(ct->name, ct->value, data) < 0) + return -1; + return 0; +} + int git_config(config_fn_t fn, void *data) { int ret = 0, found = 0; @@ -727,6 +795,12 @@ int git_config(config_fn_t fn, void *data) found += 1; } free(repo_config); + + if (config_parameters) { + ret += git_config_from_parameters(fn, data); + found += 1; + } + if (found == 0) return -1; return ret;