Commit e120123e by Russell Belfer Committed by Ben Straub

API review / update for tree.h

parent 824cb2d5
...@@ -261,8 +261,8 @@ int main (int argc, char** argv) ...@@ -261,8 +261,8 @@ int main (int argc, char** argv)
git_tree_lookup(&tree, repo, &oid); git_tree_lookup(&tree, repo, &oid);
// Getting the count of entries in the tree so you can iterate over them if you want to. // Getting the count of entries in the tree so you can iterate over them if you want to.
int cnt = git_tree_entrycount(tree); // 3 size_t cnt = git_tree_entrycount(tree); // 3
printf("tree entries: %d\n", cnt); printf("tree entries: %d\n", (int)cnt);
entry = git_tree_entry_byindex(tree, 0); entry = git_tree_entry_byindex(tree, 0);
printf("Entry name: %s\n", git_tree_entry_name(entry)); // "hello.c" printf("Entry name: %s\n", git_tree_entry_name(entry)); // "hello.c"
......
...@@ -1603,7 +1603,7 @@ int git_index_read_tree(git_index *index, git_tree *tree) ...@@ -1603,7 +1603,7 @@ int git_index_read_tree(git_index *index, git_tree *tree)
{ {
git_index_clear(index); git_index_clear(index);
return git_tree_walk(tree, read_tree_cb, GIT_TREEWALK_POST, index); return git_tree_walk(tree, GIT_TREEWALK_POST, read_tree_cb, index);
} }
git_repository *git_index_owner(const git_index *index) git_repository *git_index_owner(const git_index *index)
......
...@@ -85,7 +85,7 @@ struct tree_iterator_frame { ...@@ -85,7 +85,7 @@ struct tree_iterator_frame {
tree_iterator_frame *next, *prev; tree_iterator_frame *next, *prev;
git_tree *tree; git_tree *tree;
char *start; char *start;
unsigned int index; size_t index;
}; };
typedef struct { typedef struct {
......
...@@ -19,7 +19,7 @@ static int find_subtree_in_current_level( ...@@ -19,7 +19,7 @@ static int find_subtree_in_current_level(
const char *annotated_object_sha, const char *annotated_object_sha,
int fanout) int fanout)
{ {
unsigned int i; size_t i;
const git_tree_entry *entry; const git_tree_entry *entry;
*out = NULL; *out = NULL;
...@@ -71,7 +71,7 @@ static int find_subtree_r(git_tree **out, git_tree *root, ...@@ -71,7 +71,7 @@ static int find_subtree_r(git_tree **out, git_tree *root,
static int find_blob(git_oid *blob, git_tree *tree, const char *target) static int find_blob(git_oid *blob, git_tree *tree, const char *target)
{ {
unsigned int i; size_t i;
const git_tree_entry *entry; const git_tree_entry *entry;
for (i=0; i<git_tree_entrycount(tree); i++) { for (i=0; i<git_tree_entrycount(tree); i++) {
......
...@@ -1284,7 +1284,7 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid) ...@@ -1284,7 +1284,7 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
git_packbuilder_insert(pb, oid, NULL) < 0) git_packbuilder_insert(pb, oid, NULL) < 0)
return -1; return -1;
if (git_tree_walk(tree, cb_tree_walk, GIT_TREEWALK_PRE, pb) < 0) { if (git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, pb) < 0) {
git_tree_free(tree); git_tree_free(tree);
return -1; return -1;
} }
......
...@@ -166,6 +166,7 @@ git_tree_entry *git_tree_entry_dup(const git_tree_entry *entry) ...@@ -166,6 +166,7 @@ git_tree_entry *git_tree_entry_dup(const git_tree_entry *entry)
return NULL; return NULL;
memcpy(copy, entry, total_size); memcpy(copy, entry, total_size);
return copy; return copy;
} }
...@@ -288,10 +289,10 @@ int git_tree__prefix_position(git_tree *tree, const char *path) ...@@ -288,10 +289,10 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
return at_pos; return at_pos;
} }
unsigned int git_tree_entrycount(const git_tree *tree) size_t git_tree_entrycount(const git_tree *tree)
{ {
assert(tree); assert(tree);
return (unsigned int)tree->entries.length; return tree->entries.length;
} }
static int tree_error(const char *str) static int tree_error(const char *str)
...@@ -694,7 +695,10 @@ on_error: ...@@ -694,7 +695,10 @@ on_error:
return -1; return -1;
} }
void git_treebuilder_filter(git_treebuilder *bld, int (*filter)(const git_tree_entry *, void *), void *payload) void git_treebuilder_filter(
git_treebuilder *bld,
git_treebuilder_filter_cb filter,
void *payload)
{ {
unsigned int i; unsigned int i;
...@@ -855,7 +859,11 @@ static int tree_walk( ...@@ -855,7 +859,11 @@ static int tree_walk(
return error; return error;
} }
int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload) int git_tree_walk(
git_tree *tree,
git_treewalk_mode mode,
git_treewalk_cb callback,
void *payload)
{ {
int error = 0; int error = 0;
git_buf root_path = GIT_BUF_INIT; git_buf root_path = GIT_BUF_INIT;
......
...@@ -38,11 +38,11 @@ void test_object_tree_walk__0(void) ...@@ -38,11 +38,11 @@ void test_object_tree_walk__0(void)
cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
ct = 0; ct = 0;
cl_git_pass(git_tree_walk(tree, treewalk_count_cb, GIT_TREEWALK_PRE, &ct)); cl_git_pass(git_tree_walk(tree, GIT_TREEWALK_PRE, treewalk_count_cb, &ct));
cl_assert_equal_i(3, ct); cl_assert_equal_i(3, ct);
ct = 0; ct = 0;
cl_git_pass(git_tree_walk(tree, treewalk_count_cb, GIT_TREEWALK_POST, &ct)); cl_git_pass(git_tree_walk(tree, GIT_TREEWALK_POST, treewalk_count_cb, &ct));
cl_assert_equal_i(3, ct); cl_assert_equal_i(3, ct);
git_tree_free(tree); git_tree_free(tree);
...@@ -83,21 +83,21 @@ void test_object_tree_walk__1(void) ...@@ -83,21 +83,21 @@ void test_object_tree_walk__1(void)
ct = 0; ct = 0;
cl_assert_equal_i( cl_assert_equal_i(
GIT_EUSER, git_tree_walk(tree, treewalk_stop_cb, GIT_TREEWALK_PRE, &ct)); GIT_EUSER, git_tree_walk(tree, GIT_TREEWALK_PRE, treewalk_stop_cb, &ct));
cl_assert_equal_i(2, ct); cl_assert_equal_i(2, ct);
ct = 0; ct = 0;
cl_assert_equal_i( cl_assert_equal_i(
GIT_EUSER, git_tree_walk(tree, treewalk_stop_cb, GIT_TREEWALK_POST, &ct)); GIT_EUSER, git_tree_walk(tree, GIT_TREEWALK_POST, treewalk_stop_cb, &ct));
cl_assert_equal_i(2, ct); cl_assert_equal_i(2, ct);
cl_assert_equal_i( cl_assert_equal_i(
GIT_EUSER, git_tree_walk( GIT_EUSER, git_tree_walk(
tree, treewalk_stop_immediately_cb, GIT_TREEWALK_PRE, NULL)); tree, GIT_TREEWALK_PRE, treewalk_stop_immediately_cb, NULL));
cl_assert_equal_i( cl_assert_equal_i(
GIT_EUSER, git_tree_walk( GIT_EUSER, git_tree_walk(
tree, treewalk_stop_immediately_cb, GIT_TREEWALK_POST, NULL)); tree, GIT_TREEWALK_POST, treewalk_stop_immediately_cb, NULL));
git_tree_free(tree); git_tree_free(tree);
} }
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