Commit d54aa9ae by Edward Thomson

iterator: introduce `git_iterator_foreach`

Introduce a `git_iterator_foreach` helper function which invokes a
callback on all files for a given iterator.
parent 9c34c996
...@@ -2298,6 +2298,35 @@ void git_iterator_free(git_iterator *iter) ...@@ -2298,6 +2298,35 @@ void git_iterator_free(git_iterator *iter)
git__free(iter); git__free(iter);
} }
int git_iterator_foreach(
git_iterator *iterator,
git_iterator_foreach_cb cb,
void *data)
{
const git_index_entry *iterator_item;
int error = 0;
if ((error = git_iterator_current(&iterator_item, iterator)) < 0)
goto done;
if ((error = cb(iterator_item, data)) != 0)
goto done;
while (true) {
if ((error = git_iterator_advance(&iterator_item, iterator)) < 0)
goto done;
if ((error = cb(iterator_item, data)) != 0)
goto done;
}
done:
if (error == GIT_ITEROVER)
error = 0;
return error;
}
int git_iterator_walk( int git_iterator_walk(
git_iterator **iterators, git_iterator **iterators,
size_t cnt, size_t cnt,
......
...@@ -291,6 +291,19 @@ extern int git_iterator_current_workdir_path( ...@@ -291,6 +291,19 @@ extern int git_iterator_current_workdir_path(
*/ */
extern git_index *git_iterator_index(git_iterator *iter); extern git_index *git_iterator_index(git_iterator *iter);
typedef int (*git_iterator_foreach_cb)(
const git_index_entry *entry,
void *data);
/**
* Walk the given iterator and invoke the callback for each path
* contained in the iterator.
*/
extern int git_iterator_foreach(
git_iterator *iterator,
git_iterator_foreach_cb cb,
void *data);
typedef int (*git_iterator_walk_cb)( typedef int (*git_iterator_walk_cb)(
const git_index_entry **entries, const git_index_entry **entries,
void *data); void *data);
......
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