Commit ceb01c09 by Carlos Martín Nieto

Merge pull request #3426 from ethomson/fs_iterator

iterator: loop fs_iterator advance (don't recurse)
parents f2b25261 26d7cf6e
......@@ -1432,17 +1432,12 @@ static int fs_iterator__advance_into(
return error;
}
static int fs_iterator__advance_over(
const git_index_entry **entry, git_iterator *self)
static void fs_iterator__advance_over_internal(git_iterator *self)
{
int error = 0;
fs_iterator *fi = (fs_iterator *)self;
fs_iterator_frame *ff;
fs_iterator_path_with_stat *next;
if (entry != NULL)
*entry = NULL;
while (fi->entry.path != NULL) {
ff = fi->stack;
next = git_vector_get(&ff->entries, ++ff->index);
......@@ -1452,8 +1447,19 @@ static int fs_iterator__advance_over(
fs_iterator__pop_frame(fi, ff, false);
}
}
error = fs_iterator__update_entry(fi);
static int fs_iterator__advance_over(
const git_index_entry **entry, git_iterator *self)
{
int error;
if (entry != NULL)
*entry = NULL;
fs_iterator__advance_over_internal(self);
error = fs_iterator__update_entry((fs_iterator *)self);
if (!error && entry != NULL)
error = fs_iterator__current(entry, self);
......@@ -1530,6 +1536,7 @@ static int fs_iterator__update_entry(fs_iterator *fi)
{
fs_iterator_path_with_stat *ps;
while (true) {
memset(&fi->entry, 0, sizeof(fi->entry));
if (!fi->stack)
......@@ -1555,16 +1562,24 @@ static int fs_iterator__update_entry(fs_iterator *fi)
/* allow wrapper to check/update the entry (can force skip) */
if (fi->update_entry_cb &&
fi->update_entry_cb(fi) == GIT_ENOTFOUND)
return fs_iterator__advance_over(NULL, (git_iterator *)fi);
fi->update_entry_cb(fi) == GIT_ENOTFOUND) {
fs_iterator__advance_over_internal(&fi->base);
continue;
}
/* if this is a tree and trees aren't included, then skip */
if (fi->entry.mode == GIT_FILEMODE_TREE && !iterator__include_trees(fi)) {
int error = fs_iterator__advance_into(NULL, (git_iterator *)fi);
int error = fs_iterator__advance_into(NULL, &fi->base);
if (error != GIT_ENOTFOUND)
return error;
giterr_clear();
return fs_iterator__advance_over(NULL, (git_iterator *)fi);
fs_iterator__advance_over_internal(&fi->base);
continue;
}
break;
}
return 0;
......
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