Commit 4efa3290 by Carlos Martín Nieto

config: get_multivar -> get_multivar_foreach

The plain function will return an iterator, so move this one out of
the way.
parent 84fec6f6
......@@ -328,7 +328,7 @@ GIT_EXTERN(int) git_config_get_bool(int *out, const git_config *cfg, const char
GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, const char *name);
/**
* Get each value of a multivar.
* Get each value of a multivar in a foreach callback
*
* The callback will be called on each variable found
*
......@@ -339,7 +339,7 @@ GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, c
* @param callback the function to be called on each value of the variable
* @param payload opaque pointer to pass to the callback
*/
GIT_EXTERN(int) git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload);
GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload);
/**
* Set the value of an integer config variable in the config file
......
......@@ -31,7 +31,7 @@ struct git_config_backend {
/* Open means open the file/database and parse if necessary */
int (*open)(struct git_config_backend *, git_config_level_t level);
int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
int (*get_multivar_foreach)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
int (*set)(struct git_config_backend *, const char *key, const char *value);
int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
int (*del)(struct git_config_backend *, const char *key);
......
......@@ -574,7 +574,7 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co
return config_error_notfound(name);
}
int git_config_get_multivar(
int git_config_get_multivar_foreach(
const git_config *cfg, const char *name, const char *regexp,
git_config_foreach_cb cb, void *payload)
{
......@@ -593,7 +593,7 @@ int git_config_get_multivar(
continue;
file = internal->file;
if (!(err = file->get_multivar(file, name, regexp, cb, payload)))
if (!(err = file->get_multivar_foreach(file, name, regexp, cb, payload)))
ret = 0;
else if (err != GIT_ENOTFOUND)
return err;
......
......@@ -413,7 +413,7 @@ static int config_get(const git_config_backend *cfg, const char *name, const git
return 0;
}
static int config_get_multivar(
static int config_get_multivar_foreach(
git_config_backend *cfg,
const char *name,
const char *regex_str,
......@@ -603,7 +603,7 @@ int git_config_file__ondisk(git_config_backend **out, const char *path)
backend->parent.open = config_open;
backend->parent.get = config_get;
backend->parent.get_multivar = config_get_multivar;
backend->parent.get_multivar_foreach = config_get_multivar_foreach;
backend->parent.set = config_set;
backend->parent.set_multivar = config_set_multivar;
backend->parent.del = config_delete;
......
......@@ -187,7 +187,7 @@ static int git_diff_driver_load(
git_buf_truncate(&name, namelen + strlen("diff.."));
git_buf_put(&name, "xfuncname", strlen("xfuncname"));
if ((error = git_config_get_multivar(
if ((error = git_config_get_multivar_foreach(
cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) {
if (error != GIT_ENOTFOUND)
goto done;
......@@ -196,7 +196,7 @@ static int git_diff_driver_load(
git_buf_truncate(&name, namelen + strlen("diff.."));
git_buf_put(&name, "funcname", strlen("funcname"));
if ((error = git_config_get_multivar(
if ((error = git_config_get_multivar_foreach(
cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) {
if (error != GIT_ENOTFOUND)
goto done;
......
......@@ -217,7 +217,7 @@ static int get_optional_config(
return -1;
if (cb != NULL)
error = git_config_get_multivar(config, key, NULL, cb, payload);
error = git_config_get_multivar_foreach(config, key, NULL, cb, payload);
else
error = git_config_get_string(payload, config, key);
......
......@@ -46,27 +46,27 @@ static int cb(const git_config_entry *entry, void *data)
return 0;
}
static void check_get_multivar(
static void check_get_multivar_foreach(
git_config *cfg, int expected, int expected_patterned)
{
int n = 0;
if (expected > 0) {
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert_equal_i(expected, n);
} else {
cl_assert_equal_i(GIT_ENOTFOUND,
git_config_get_multivar(cfg, _name, NULL, cb, &n));
git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
}
n = 0;
if (expected_patterned > 0) {
cl_git_pass(git_config_get_multivar(cfg, _name, "example", cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "example", cb, &n));
cl_assert_equal_i(expected_patterned, n);
} else {
cl_assert_equal_i(GIT_ENOTFOUND,
git_config_get_multivar(cfg, _name, "example", cb, &n));
git_config_get_multivar_foreach(cfg, _name, "example", cb, &n));
}
}
......@@ -75,31 +75,31 @@ void test_config_multivar__get(void)
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
check_get_multivar(cfg, 2, 1);
check_get_multivar_foreach(cfg, 2, 1);
/* add another that has the _name entry */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config9", GIT_CONFIG_LEVEL_SYSTEM, 1));
check_get_multivar(cfg, 3, 2);
check_get_multivar_foreach(cfg, 3, 2);
/* add another that does not have the _name entry */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config0", GIT_CONFIG_LEVEL_GLOBAL, 1));
check_get_multivar(cfg, 3, 2);
check_get_multivar_foreach(cfg, 3, 2);
/* add another that does not have the _name entry at the end */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config1", GIT_CONFIG_LEVEL_APP, 1));
check_get_multivar(cfg, 3, 2);
check_get_multivar_foreach(cfg, 3, 2);
/* drop original file */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config2", GIT_CONFIG_LEVEL_LOCAL, 1));
check_get_multivar(cfg, 1, 1);
check_get_multivar_foreach(cfg, 1, 1);
/* drop other file with match */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config3", GIT_CONFIG_LEVEL_SYSTEM, 1));
check_get_multivar(cfg, 0, 0);
check_get_multivar_foreach(cfg, 0, 0);
/* reload original file (add different place in order) */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config11", GIT_CONFIG_LEVEL_SYSTEM, 1));
check_get_multivar(cfg, 2, 1);
check_get_multivar_foreach(cfg, 2, 1);
git_config_free(cfg);
}
......@@ -113,11 +113,11 @@ void test_config_multivar__add(void)
cl_git_pass(git_config_set_multivar(cfg, _name, "nonexistant", "git://git.otherplace.org/libgit2"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 3);
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, "otherplace", cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert(n == 1);
git_config_free(cfg);
......@@ -127,11 +127,11 @@ void test_config_multivar__add(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 3);
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, "otherplace", cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert(n == 1);
git_config_free(cfg);
......@@ -147,7 +147,7 @@ void test_config_multivar__add_new(void)
cl_git_pass(git_config_set_multivar(cfg, var, "", "variable"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, var, NULL, cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, var, NULL, cb, &n));
cl_assert(n == 1);
git_config_free(cfg);
......@@ -161,13 +161,13 @@ void test_config_multivar__replace(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 2);
cl_git_pass(git_config_set_multivar(cfg, _name, "github", "git://git.otherplace.org/libgit2"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 2);
git_config_free(cfg);
......@@ -175,7 +175,7 @@ void test_config_multivar__replace(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 2);
git_config_free(cfg);
......@@ -190,7 +190,7 @@ void test_config_multivar__replace_multiple(void)
cl_git_pass(git_config_set_multivar(cfg, _name, "git://", "git://git.otherplace.org/libgit2"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, "otherplace", cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert(n == 2);
git_config_free(cfg);
......@@ -198,7 +198,7 @@ void test_config_multivar__replace_multiple(void)
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar(cfg, _name, "otherplace", cb, &n));
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert(n == 2);
git_config_free(cfg);
......
......@@ -28,7 +28,7 @@ static void assert_invalid_config_key_name(const char *name)
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_delete_entry(cfg, name),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_get_multivar(cfg, name, "*", NULL, NULL),
cl_git_fail_with(git_config_get_multivar_foreach(cfg, name, "*", NULL, NULL),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_set_multivar(cfg, name, "*", "42"),
GIT_EINVALIDSPEC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment