diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-08-13 16:07:47 +0400 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-08-13 16:07:47 +0400 |
commit | a6bf16878a121152f5bddf4d46f641e8f044d278 (patch) | |
tree | 985236fd9f726695ea9591415c89594283290793 /src/tree.c | |
parent | 53ae12359d324890c4d30cc06bd2631ebdec43bb (diff) |
tree: allow the user to skip an entry or cancel the walk
Returning a negative cancels the walk, and returning a positive one
causes us to skip an entry, which was previously done by a negative
value.
This allows us to stay consistent with the rest of the functions that
take a callback and keeps the skipping functionality.
Diffstat (limited to 'src/tree.c')
-rw-r--r-- | src/tree.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/tree.c b/src/tree.c index 911cbadcf..19250fe5e 100644 --- a/src/tree.c +++ b/src/tree.c @@ -787,8 +787,13 @@ static int tree_walk( for (i = 0; i < tree->entries.length; ++i) { git_tree_entry *entry = tree->entries.contents[i]; - if (preorder && callback(path->ptr, entry, payload) < 0) - continue + if (preorder) { + error = callback(path->ptr, entry, payload); + if (error > 0) + continue; + if (error < 0) + return GIT_EUSER; + } if (git_tree_entry__is_tree(entry)) { git_tree *subtree; @@ -813,7 +818,7 @@ static int tree_walk( git_tree_free(subtree); } - if (!preorder && callback(path->ptr, entry, payload)) { + if (!preorder && callback(path->ptr, entry, payload) < 0) { error = GIT_EUSER; break; } |