Commit d8488b98 by Carlos Martín Nieto

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.
parent 54f3a572
...@@ -455,12 +455,12 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf ...@@ -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.next = all_iter_glob_next;
iter->parent.free = all_iter_glob_free;
} else { } else {
iter->parent.next = all_iter_next; 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->i = cfg->files.length;
iter->cfg = cfg; iter->cfg = cfg;
...@@ -527,18 +527,27 @@ int git_config_foreach_match( ...@@ -527,18 +527,27 @@ int git_config_foreach_match(
git_config_foreach_cb cb, git_config_foreach_cb cb,
void *payload) void *payload)
{ {
int ret = 0; int error;
size_t i; git_config_iterator *iter;
file_internal *internal; git_config_entry *entry;
git_config_backend *file;
for (i = 0; i < cfg->files.length && ret == 0; ++i) { if ((error = git_config_iterator_glob_new(&iter, cfg, regexp)) < 0)
internal = git_vector_get(&cfg->files, i); return error;
file = internal->file;
ret = git_config_backend_foreach_match(file, regexp, cb, payload); 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;
} }
/************** /**************
......
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