Commit 2ba14f23 by Vicent Marti

tree: Add payload to `git_tree_walk`

parent 9432af36
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment