tree: Add payload to `git_tree_walk`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 2ff167f..bd89de3 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -284,7 +284,7 @@ GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_tr
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);
+typedef int (*git_treewalk_cb)(const char *root, git_tree_entry *entry, void *payload);
/** Tree traversal modes */
enum git_treewalk_mode {
@@ -310,7 +310,7 @@ enum git_treewalk_mode {
* @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_EXTERN(int) git_tree_walk(git_tree *walk, git_treewalk_cb callback, int mode, void *payload);
/** @} */
GIT_END_DECL
diff --git a/src/tree.c b/src/tree.c
index 4586891..92ca5ab 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -683,7 +683,8 @@ static int tree_walk_post(
git_tree *tree,
git_treewalk_cb callback,
char *root,
- size_t root_len)
+ size_t root_len,
+ void *payload)
{
int error;
unsigned int i;
@@ -693,7 +694,7 @@ static int tree_walk_post(
root[root_len] = '\0';
- if (callback(root, entry) < 0)
+ if (callback(root, entry, payload) < 0)
continue;
if (ENTRY_IS_TREE(entry)) {
@@ -707,7 +708,10 @@ static int tree_walk_post(
root[root_len + entry->filename_len] = '/';
tree_walk_post(subtree,
- callback, root, root_len + entry->filename_len + 1);
+ callback, root,
+ root_len + entry->filename_len + 1,
+ payload
+ );
git_tree_close(subtree);
}
@@ -716,14 +720,14 @@ static int tree_walk_post(
return GIT_SUCCESS;
}
-int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode)
+int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload)
{
char root_path[GIT_PATH_MAX];
root_path[0] = '\0';
switch (mode) {
case GIT_TREEWALK_POST:
- return tree_walk_post(tree, callback, root_path, 0);
+ return tree_walk_post(tree, callback, root_path, 0, payload);
case GIT_TREEWALK_PRE:
return git__throw(GIT_ENOTIMPLEMENTED,