mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-04 01:40:18 +00:00
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.
This commit is contained in:
parent
53ae12359d
commit
a6bf16878a
@ -351,8 +351,9 @@ enum git_treewalk_mode {
|
||||
* the current (relative) root for the entry and the entry
|
||||
* data itself.
|
||||
*
|
||||
* If the callback returns a negative value, the passed entry
|
||||
* will be skipped on the traversal.
|
||||
* If the callback returns a positive value, the passed entry will be
|
||||
* skipped on the traversal (in pre mode). A negative value stops the
|
||||
* walk.
|
||||
*
|
||||
* @param tree The tree to walk
|
||||
* @param callback Function to call on each tree entry
|
||||
|
||||
11
src/tree.c
11
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user