diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-03-05 19:44:06 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-03-09 00:43:47 -0800 |
commit | 5803c6f8a2faf8cfbbd046d9ebd682b82bb2b086 (patch) | |
tree | 4f586a9a7d7735115167257b023ac9e7fc01869d /tree-walk.c | |
parent | 40d934df72eaf244c826d5c26da0896ce7185cb6 (diff) | |
download | git-5803c6f8a2faf8cfbbd046d9ebd682b82bb2b086.tar.gz |
Add return value to 'traverse_tree()' callback
This allows the callback to return an error value, but it can also
specify which of the tree entries that it actually used up by returning
a positive mask value.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tree-walk.c')
-rw-r--r-- | tree-walk.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/tree-walk.c b/tree-walk.c index f9f7d225e9..7170e375b3 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -135,8 +135,9 @@ char *make_traverse_path(char *path, const struct traverse_info *info, const str return path; } -void traverse_trees(int n, struct tree_desc *t, struct traverse_info *info) +int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info) { + int ret = 0; struct name_entry *entry = xmalloc(n*sizeof(*entry)); for (;;) { @@ -171,19 +172,26 @@ void traverse_trees(int n, struct tree_desc *t, struct traverse_info *info) break; /* - * Update the tree entries we've walked, and clear - * all the unused name-entries. + * Clear all the unused name-entries. */ for (i = 0; i < n; i++) { - if (mask & (1ul << i)) { - update_tree_entry(t+i); + if (mask & (1ul << i)) continue; - } entry_clear(entry + i); } - info->fn(n, mask, entry, info); + ret = info->fn(n, mask, entry, info); + if (ret < 0) + break; + if (ret) + mask &= ret; + ret = 0; + for (i = 0; i < n; i++) { + if (mask & (1ul << i)) + update_tree_entry(t + i); + } } free(entry); + return ret; } static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result, unsigned *mode) |