Commit 1e96c9d5 by Carlos Martín Nieto

config: add _next() and _iterator_free()

Make it look like the refs iterator API.
parent 99dfb538
......@@ -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).
......
......@@ -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))
{
......
......@@ -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);
}
......
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