Commit 4efa32903adf131631d283c914e0a5bf29c49e4d

Carlos Martín Nieto 2013-08-08T13:41:18

config: get_multivar -> get_multivar_foreach The plain function will return an iterator, so move this one out of the way.

diff --git a/include/git2/config.h b/include/git2/config.h
index 43bc194..a0dc11b 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -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
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index f617623..09c7963 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -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);
diff --git a/src/config.c b/src/config.c
index 6c055e0..a4627c9 100644
--- a/src/config.c
+++ b/src/config.c
@@ -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;
diff --git a/src/config_file.c b/src/config_file.c
index 6eb51ac..ed79624 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -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;
diff --git a/src/diff_driver.c b/src/diff_driver.c
index e82dfa5..bd5a8fb 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -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;
diff --git a/src/remote.c b/src/remote.c
index 158f3e9..003fada 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -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);
 
diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c
index efc4315..390b24c 100644
--- a/tests-clar/config/multivar.c
+++ b/tests-clar/config/multivar.c
@@ -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);
diff --git a/tests-clar/config/validkeyname.c b/tests-clar/config/validkeyname.c
index 03c13d7..3369973 100644
--- a/tests-clar/config/validkeyname.c
+++ b/tests-clar/config/validkeyname.c
@@ -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);