Commit 1e96c9d5341e5f2b0e1af9a1088cc30d3ffb9a01

Carlos Martín Nieto 2013-08-08T20:47:06

config: add _next() and _iterator_free() Make it look like the refs iterator API.

diff --git a/include/git2/config.h b/include/git2/config.h
index e1d34b9..b338e0c 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -351,6 +351,23 @@ GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const cha
  * interested in. Use NULL to indicate all
  */
 GIT_EXTERN(int) git_config_get_multivar(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp);
+
+/**
+ * Return the current entry and advance the iterator
+ *
+ * @param entry pointer to store the entry
+ * @param iter the iterator
+ * @return 0 or an error code. GIT_ITEROVER if the iteration has completed
+ */
+GIT_EXTERN(int) git_config_next(git_config_entry **entry, git_config_iterator *iter);
+
+/**
+ * Free a config iterator
+ *
+ * @param iter the iterator to free
+ */
+GIT_EXTERN(void) git_config_iterator_free(git_config_iterator *iter);
+
 /**
  * Set the value of an integer config variable in the config file
  * with the highest level (usually the local one).
diff --git a/src/config.c b/src/config.c
index 63a386d..83b101d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -727,6 +727,16 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
 	return file->set_multivar(file, name, regexp, value);
 }
 
+int git_config_next(git_config_entry **entry, git_config_iterator *iter)
+{
+	return iter->next(entry, iter);
+}
+
+void git_config_iterator_free(git_config_iterator *iter)
+{
+	iter->free(iter);
+}
+
 static int git_config__find_file_to_path(
 	char *out, size_t outlen, int (*find)(git_buf *buf))
 {
diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c
index b7283b3..afb993c 100644
--- a/tests-clar/config/multivar.c
+++ b/tests-clar/config/multivar.c
@@ -70,6 +70,22 @@ static void check_get_multivar_foreach(
 	}
 }
 
+static void check_get_multivar(git_config *cfg, int expected)
+{
+	git_config_iterator *iter;
+	git_config_entry *entry;
+	int n = 0;
+
+	cl_git_pass(git_config_get_multivar(&iter, cfg, _name, NULL));
+
+	while (git_config_next(&entry, iter) == 0)
+		n++;
+
+	cl_assert_equal_i(expected, n);
+	git_config_iterator_free(iter);
+
+}
+
 void test_config_multivar__get(void)
 {
 	git_config *cfg;
@@ -101,6 +117,8 @@ void test_config_multivar__get(void)
 	cl_git_pass(git_config_add_file_ondisk(cfg, "config/config11", GIT_CONFIG_LEVEL_SYSTEM, 1));
 	check_get_multivar_foreach(cfg, 2, 1);
 
+	check_get_multivar(cfg, 2);
+
 	git_config_free(cfg);
 }