diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 58 |
1 files changed, 43 insertions, 15 deletions
@@ -16,6 +16,7 @@ #include "string-list.h" #include "utf8.h" #include "dir.h" +#include "color.h" struct config_source { struct config_source *prev; @@ -928,7 +929,7 @@ ssize_t git_config_ssize_t(const char *name, const char *value) return ret; } -int git_parse_maybe_bool(const char *value) +static int git_parse_maybe_bool_text(const char *value) { if (!value) return 1; @@ -945,9 +946,9 @@ int git_parse_maybe_bool(const char *value) return -1; } -int git_config_maybe_bool(const char *name, const char *value) +int git_parse_maybe_bool(const char *value) { - int v = git_parse_maybe_bool(value); + int v = git_parse_maybe_bool_text(value); if (0 <= v) return v; if (git_parse_int(value, &v)) @@ -955,9 +956,14 @@ int git_config_maybe_bool(const char *name, const char *value) return -1; } +int git_config_maybe_bool(const char *name, const char *value) +{ + return git_parse_maybe_bool(value); +} + int git_config_bool_or_int(const char *name, const char *value, int *is_bool) { - int v = git_parse_maybe_bool(value); + int v = git_parse_maybe_bool_text(value); if (0 <= v) { *is_bool = 1; return v; @@ -1350,6 +1356,9 @@ int git_default_config(const char *var, const char *value, void *dummy) if (starts_with(var, "advice.")) return git_default_advice_config(var, value); + if (git_color_config(var, value, dummy) < 0) + return -1; + if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { pager_use_color = git_config_bool(var,value); return 0; @@ -1460,9 +1469,9 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ return do_config_from(&top, fn, data); } -int git_config_from_blob_sha1(config_fn_t fn, +int git_config_from_blob_oid(config_fn_t fn, const char *name, - const unsigned char *sha1, + const struct object_id *oid, void *data) { enum object_type type; @@ -1470,7 +1479,7 @@ int git_config_from_blob_sha1(config_fn_t fn, unsigned long size; int ret; - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid->hash, &type, &size); if (!buf) return error("unable to load config blob object '%s'", name); if (type != OBJ_BLOB) { @@ -1488,11 +1497,11 @@ static int git_config_from_blob_ref(config_fn_t fn, const char *name, void *data) { - unsigned char sha1[20]; + struct object_id oid; - if (get_sha1(name, sha1) < 0) + if (get_oid(name, &oid) < 0) return error("unable to resolve config blob '%s'", name); - return git_config_from_blob_sha1(fn, name, sha1, data); + return git_config_from_blob_oid(fn, name, &oid, data); } const char *git_etc_gitconfig(void) @@ -1715,17 +1724,19 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha } static int config_set_element_cmp(const void *unused_cmp_data, - const struct config_set_element *e1, - const struct config_set_element *e2, + const void *entry, + const void *entry_or_key, const void *unused_keydata) { + const struct config_set_element *e1 = entry; + const struct config_set_element *e2 = entry_or_key; + return strcmp(e1->key, e2->key); } void git_configset_init(struct config_set *cs) { - hashmap_init(&cs->config_hash, (hashmap_cmp_fn)config_set_element_cmp, - NULL, 0); + hashmap_init(&cs->config_hash, config_set_element_cmp, NULL, 0); cs->hash_initialized = 1; cs->list.nr = 0; cs->list.alloc = 0; @@ -1846,7 +1857,7 @@ int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *de { const char *value; if (!git_configset_get_value(cs, key, &value)) { - *dest = git_config_maybe_bool(key, value); + *dest = git_parse_maybe_bool(value); if (*dest == -1) return -1; return 0; @@ -2053,6 +2064,23 @@ int git_config_get_pathname(const char *key, const char **dest) return repo_config_get_pathname(the_repository, key, dest); } +/* + * Note: This function exists solely to maintain backward compatibility with + * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should + * NOT be used anywhere else. + * + * Runs the provided config function on the '.gitmodules' file found in the + * working directory. + */ +void config_from_gitmodules(config_fn_t fn, void *data) +{ + if (the_repository->worktree) { + char *file = repo_worktree_path(the_repository, GITMODULES_FILE); + git_config_from_file(fn, file, data); + free(file); + } +} + int git_config_get_expiry(const char *key, const char **output) { int ret = git_config_get_string_const(key, output); |