aboutsummaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/config.c b/config.c
index c058b2c70c..5d3e84f85a 100644
--- a/config.c
+++ b/config.c
@@ -2275,23 +2275,29 @@ void read_very_early_config(config_fn_t cb, void *data)
config_with_options(cb, data, NULL, &opts);
}
-static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)
+RESULT_MUST_BE_USED
+static int configset_find_element(struct config_set *cs, const char *key,
+ struct config_set_element **dest)
{
struct config_set_element k;
struct config_set_element *found_entry;
char *normalized_key;
+ int ret;
+
/*
* `key` may come from the user, so normalize it before using it
* for querying entries from the hashmap.
*/
- if (git_config_parse_key(key, &normalized_key, NULL))
- return NULL;
+ ret = git_config_parse_key(key, &normalized_key, NULL);
+ if (ret)
+ return ret;
hashmap_entry_init(&k.ent, strhash(normalized_key));
k.key = normalized_key;
found_entry = hashmap_get_entry(&cs->config_hash, &k, ent, NULL);
free(normalized_key);
- return found_entry;
+ *dest = found_entry;
+ return 0;
}
static int configset_add_value(struct config_set *cs, const char *key, const char *value)
@@ -2300,8 +2306,11 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
struct string_list_item *si;
struct configset_list_item *l_item;
struct key_value_info *kv_info = xmalloc(sizeof(*kv_info));
+ int ret;
- e = configset_find_element(cs, key);
+ ret = configset_find_element(cs, key, &e);
+ if (ret)
+ return ret;
/*
* Since the keys are being fed by git_config*() callback mechanism, they
* are already normalized. So simply add them without any further munging.
@@ -2411,8 +2420,25 @@ int git_configset_get_value(struct config_set *cs, const char *key, const char *
const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key)
{
- struct config_set_element *e = configset_find_element(cs, key);
- return e ? &e->value_list : NULL;
+ struct config_set_element *e;
+
+ if (configset_find_element(cs, key, &e))
+ return NULL;
+ else if (!e)
+ return NULL;
+ return &e->value_list;
+}
+
+int git_configset_get(struct config_set *cs, const char *key)
+{
+ struct config_set_element *e;
+ int ret;
+
+ if ((ret = configset_find_element(cs, key, &e)))
+ return ret;
+ else if (!e)
+ return 1;
+ return 0;
}
int git_configset_get_string(struct config_set *cs, const char *key, char **dest)
@@ -2551,6 +2577,12 @@ void repo_config(struct repository *repo, config_fn_t fn, void *data)
configset_iter(repo->config, fn, data);
}
+int repo_config_get(struct repository *repo, const char *key)
+{
+ git_config_check_init(repo);
+ return git_configset_get(repo->config, key);
+}
+
int repo_config_get_value(struct repository *repo,
const char *key, const char **value)
{
@@ -2665,6 +2697,11 @@ void git_config_clear(void)
repo_config_clear(the_repository);
}
+int git_config_get(const char *key)
+{
+ return repo_config_get(the_repository, key);
+}
+
int git_config_get_value(const char *key, const char **value)
{
return repo_config_get_value(the_repository, key, value);