diff options
Diffstat (limited to 'include/git2/tree.h')
-rw-r--r-- | include/git2/tree.h | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/include/git2/tree.h b/include/git2/tree.h index 8d638f723..bd89de34f 100644 --- a/include/git2/tree.h +++ b/include/git2/tree.h @@ -269,19 +269,49 @@ GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(cons GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld); /** - * Retrieve the tree object containing a tree entry, given - * a relative path to this tree entry + * Retrieve a subtree contained in a tree, given its + * relative path. * * The returned tree is owned by the repository and * should be closed with the `git_object_close` method. * - * @param parent_out Pointer where to store the parent tree + * @param subtree Pointer where to store the subtree * @param root A previously loaded tree which will be the root of the relative path - * @param treeentry_path Path to the tree entry from which to extract the last tree object - * @return GIT_SUCCESS on success; GIT_ENOTFOUND if the path does not lead to an - * entry, GIT_EINVALIDPATH or an error code + * @param subtree_path Path to the contained subtree + * @return GIT_SUCCESS on success; GIT_ENOTFOUND if the path does not lead to a + * subtree, GIT_EINVALIDPATH or an error code */ -GIT_EXTERN(int) git_tree_frompath(git_tree **parent_out, git_tree *root, const char *treeentry_path); +GIT_EXTERN(int) git_tree_get_subtree(git_tree **subtree, git_tree *root, const char *subtree_path); + +/** Callback for the tree traversal method */ +typedef int (*git_treewalk_cb)(const char *root, git_tree_entry *entry, void *payload); + +/** 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, void *payload); + /** @} */ GIT_END_DECL #endif |