config_with_options(cb, data, NULL, &opts);
}
-static struct config_set_element *configset_find_element(struct config_set *set, const char *key)
+RESULT_MUST_BE_USED
- static int configset_find_element(struct config_set *cs, const char *key,
++static int configset_find_element(struct config_set *set, const char *key,
+ struct config_set_element **dest)
{
struct config_set_element k;
struct config_set_element *found_entry;
hashmap_entry_init(&k.ent, strhash(normalized_key));
k.key = normalized_key;
- found_entry = hashmap_get_entry(&cs->config_hash, &k, ent, NULL);
+ found_entry = hashmap_get_entry(&set->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)
+ static int configset_add_value(struct config_reader *reader,
+ struct config_set *set, const char *key,
+ const char *value)
{
struct config_set_element *e;
struct string_list_item *si;
struct configset_list_item *l_item;
struct key_value_info *kv_info = xmalloc(sizeof(*kv_info));
+ int ret;
- ret = configset_find_element(cs, key, &e);
- e = configset_find_element(set, key);
++ ret = configset_find_element(set, 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.
return 0;
}
- int git_configset_add_file(struct config_set *cs, const char *filename)
+ int git_configset_add_file(struct config_set *set, const char *filename)
{
- return git_config_from_file(config_set_callback, filename, cs);
+ struct configset_add_data data = CONFIGSET_ADD_INIT;
+ data.config_reader = &the_reader;
+ data.config_set = set;
+ return git_config_from_file(config_set_callback, filename, &data);
}
- int git_configset_get_value(struct config_set *cs, const char *key, const char **value)
+ int git_configset_get_value(struct config_set *set, const char *key, const char **value)
{
const struct string_list *values = NULL;
+ int ret;
+
/*
* Follows "last one wins" semantic, i.e., if there are multiple matches for the
* queried key in the files of the configset, the value returned will be the last
* value in the value list for that key.
*/
- if ((ret = git_configset_get_value_multi(cs, key, &values)))
- values = git_configset_get_value_multi(set, key);
++ if ((ret = git_configset_get_value_multi(set, key, &values)))
+ return ret;
- if (!values)
- return 1;
assert(values->nr > 0);
*value = values->items[values->nr - 1].string;
return 0;
}
- int git_configset_get_value_multi(struct config_set *cs, const char *key,
-const struct string_list *git_configset_get_value_multi(struct config_set *set, const char *key)
++int git_configset_get_value_multi(struct config_set *set, const char *key,
+ const struct string_list **dest)
+{
+ struct config_set_element *e;
+ int ret;
+
- if ((ret = configset_find_element(cs, key, &e)))
++ if ((ret = configset_find_element(set, key, &e)))
+ return ret;
+ else if (!e)
+ return 1;
+ *dest = &e->value_list;
+
+ return 0;
+}
+
+static int check_multi_string(struct string_list_item *item, void *util)
+{
+ return item->string ? 0 : config_error_nonbool(util);
+}
+
+int git_configset_get_string_multi(struct config_set *cs, const char *key,
+ const struct string_list **dest)
+{
+ int ret;
+
+ if ((ret = git_configset_get_value_multi(cs, key, dest)))
+ return ret;
+ if ((ret = for_each_string_list((struct string_list *)*dest,
+ check_multi_string, (void *)key)))
+ return ret;
+
+ return 0;
+}
+
- int git_configset_get(struct config_set *cs, const char *key)
++int git_configset_get(struct config_set *set, const char *key)
{
- struct config_set_element *e = configset_find_element(set, key);
- return e ? &e->value_list : NULL;
+ struct config_set_element *e;
+ int ret;
+
- if ((ret = configset_find_element(cs, key, &e)))
++ if ((ret = configset_find_element(set, 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)
+ int git_configset_get_string(struct config_set *set, const char *key, char **dest)
{
const char *value;
- if (!git_configset_get_value(cs, key, &value))
+ if (!git_configset_get_value(set, key, &value))
return git_config_string((const char **)dest, key, value);
else
return 1;
void repo_config(struct repository *repo, config_fn_t fn, void *data)
{
git_config_check_init(repo);
- configset_iter(repo->config, fn, data);
+ configset_iter(&the_reader, 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)
{