diff options
author | Vicent Marti <tanoku@gmail.com> | 2011-10-27 22:33:31 -0700 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-10-27 22:33:31 -0700 |
commit | da37654d04617b4dacce6e7a4796007d2854624d (patch) | |
tree | 4af06d8774d5e369e8d62c84b56e2644ad672ddc /include/git2/tree.h | |
parent | 4849dbb8b9273337593aa3f06dc11c28137fa13d (diff) | |
download | libgit2-da37654d04617b4dacce6e7a4796007d2854624d.tar.gz |
tree: Add traversal in post-order
Diffstat (limited to 'include/git2/tree.h')
-rw-r--r-- | include/git2/tree.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/git2/tree.h b/include/git2/tree.h index 8d638f72..68d82351 100644 --- a/include/git2/tree.h +++ b/include/git2/tree.h @@ -282,6 +282,36 @@ GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_tr * entry, GIT_EINVALIDPATH or an error code */ GIT_EXTERN(int) git_tree_frompath(git_tree **parent_out, git_tree *root, const char *treeentry_path); + +/** Callback for the tree traversal method */ +typedef int (*git_treewalk_cb)(const char *root, git_tree_entry *entry); + +/** Tree traversal modes */ +enum git_treewalk_mode { + GIT_TREEWALK_PRE = 0, /* Pre-order */ + GIT_TREEWALK_POST = 1, /* Post-order */ +}; + +/** + * Traverse the entries in a tree and its subtrees in + * post or pre order + * + * The entries will be traversed in the specified order, + * children subtrees will be automatically loaded as required, + * and the `callback` will be called once per entry with + * the current (relative) root for the entry and the entry + * data itself. + * + * If the callback returns a negative value, the passed entry + * will be skiped on the traversal. + * + * @param tree The tree to walk + * @param callback Function to call on each tree entry + * @param mode Traversal mode (pre or post-order) + * @return GIT_SUCCESS or an error code + */ +GIT_EXTERN(int) git_tree_walk(git_tree *walk, git_treewalk_cb callback, int mode); + /** @} */ GIT_END_DECL #endif |