mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 10:28:56 +00:00
config: add _next() and _iterator_free()
Make it look like the refs iterator API.
This commit is contained in:
parent
99dfb538ad
commit
1e96c9d534
@ -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).
|
||||
|
10
src/config.c
10
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))
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user