config: implement _foreach and _foreach_match on top of the iterator directly Use a glob iterator instead of going through git_config_backend_foreach_match. This function is left as it's exposed in the API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/src/config.c b/src/config.c
index 9d809f8..3881d73 100644
--- a/src/config.c
+++ b/src/config.c
@@ -455,12 +455,12 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf
}
iter->parent.next = all_iter_glob_next;
+ iter->parent.free = all_iter_glob_free;
} else {
iter->parent.next = all_iter_next;
+ iter->parent.free = all_iter_free;
}
- iter->parent.free = all_iter_glob_free;
-
iter->i = cfg->files.length;
iter->cfg = cfg;
@@ -527,18 +527,27 @@ int git_config_foreach_match(
git_config_foreach_cb cb,
void *payload)
{
- int ret = 0;
- size_t i;
- file_internal *internal;
- git_config_backend *file;
+ int error;
+ git_config_iterator *iter;
+ git_config_entry *entry;
- for (i = 0; i < cfg->files.length && ret == 0; ++i) {
- internal = git_vector_get(&cfg->files, i);
- file = internal->file;
- ret = git_config_backend_foreach_match(file, regexp, cb, payload);
+ if ((error = git_config_iterator_glob_new(&iter, cfg, regexp)) < 0)
+ return error;
+
+ while ((error = git_config_next(&entry, iter)) == 0) {
+ if(cb(entry, payload)) {
+ giterr_clear();
+ error = GIT_EUSER;
+ break;
+ }
}
- return ret;
+ git_config_iterator_free(iter);
+
+ if (error == GIT_ITEROVER)
+ error = 0;
+
+ return error;
}
/**************