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)
git_tree_lookup(&tree, repo, &oid);
// 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
printf("tree entries: %d\n", cnt);
size_t cnt = git_tree_entrycount(tree); // 3
printf("tree entries: %d\n", (int)cnt);
entry = git_tree_entry_byindex(tree, 0);
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)
{
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)
......
......@@ -85,7 +85,7 @@ struct tree_iterator_frame {
tree_iterator_frame *next, *prev;
git_tree *tree;
char *start;
unsigned int index;
size_t index;
};
typedef struct {
......
......@@ -19,7 +19,7 @@ static int find_subtree_in_current_level(
const char *annotated_object_sha,
int fanout)
{
unsigned int i;
size_t i;
const git_tree_entry *entry;
*out = NULL;
......@@ -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)
{
unsigned int i;
size_t i;
const git_tree_entry *entry;
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)
git_packbuilder_insert(pb, oid, NULL) < 0)
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);
return -1;
}
......
......@@ -166,6 +166,7 @@ git_tree_entry *git_tree_entry_dup(const git_tree_entry *entry)
return NULL;
memcpy(copy, entry, total_size);
return copy;
}
......@@ -288,10 +289,10 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
return at_pos;
}
unsigned int git_tree_entrycount(const git_tree *tree)
size_t git_tree_entrycount(const git_tree *tree)
{
assert(tree);
return (unsigned int)tree->entries.length;
return tree->entries.length;
}
static int tree_error(const char *str)
......@@ -694,7 +695,10 @@ on_error:
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;
......@@ -855,7 +859,11 @@ static int tree_walk(
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;
git_buf root_path = GIT_BUF_INIT;
......
......@@ -38,11 +38,11 @@ void test_object_tree_walk__0(void)
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
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);
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);
git_tree_free(tree);
......@@ -83,21 +83,21 @@ void test_object_tree_walk__1(void)
ct = 0;
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);
ct = 0;
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(
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(
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);
}
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