Commit 2ba14f2367b14187e1714f32c11236476c22ddfa

Vicent Marti 2011-11-17T02:13:46

tree: Add payload to `git_tree_walk`

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,