summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-07-10 15:22:39 -0700
committerRussell Belfer <rb@github.com>2012-07-10 23:19:47 -0700
commitb3ff1dab317dc9194c4bc124afd95ae9be2ad57b (patch)
treec031792209b9758395610720b8dbfb776165f783 /src/config.c
parentc3a875c975cde11ffd18947c419b1cd38205e6c3 (diff)
downloadlibgit2-b3ff1dab317dc9194c4bc124afd95ae9be2ad57b.tar.gz
Adding git_config_foreach_match() iteration fn
Adding a new config iteration function that let's you iterate over just the config entries that match a particular regular expression. The old foreach becomes a simple use of this with an empty pattern. This also fixes an apparent bug in the existing `git_config_foreach` where returning a non-zero value from the iteration callback was not correctly aborting the iteration and the returned value was not being propogated back to the caller of foreach. Added to tests to cover all these changes.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index d18b85c30..98fb3b20d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -136,17 +136,27 @@ int git_config_add_file(git_config *cfg, git_config_file *file, int priority)
* Loop over all the variables
*/
-int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, void *), void *data)
+int git_config_foreach(
+ git_config *cfg, int (*fn)(const char *, const char *, void *), void *data)
+{
+ return git_config_foreach_match(cfg, NULL, fn, data);
+}
+
+int git_config_foreach_match(
+ git_config *cfg,
+ const char *regexp,
+ int (*fn)(const char *, const char *, void *),
+ void *data)
{
int ret = 0;
unsigned int i;
file_internal *internal;
git_config_file *file;
- for(i = 0; i < cfg->files.length && ret == 0; ++i) {
+ for (i = 0; i < cfg->files.length && ret == 0; ++i) {
internal = git_vector_get(&cfg->files, i);
file = internal->file;
- ret = file->foreach(file, fn, data);
+ ret = file->foreach(file, regexp, fn, data);
}
return ret;