Commit 4b181037 by Russell Belfer

Minor iterator API cleanups

In preparation for further iterator changes, this cleans up a few
small things in the iterator API:

* removed the git_iterator_for_repo_index_range API
* made git_iterator_free not be inlined
* minor param name and test function name tweaks
parent facc0650
...@@ -485,20 +485,6 @@ int git_iterator_for_index_range( ...@@ -485,20 +485,6 @@ int git_iterator_for_index_range(
return 0; return 0;
} }
int git_iterator_for_repo_index_range(
git_iterator **iter,
git_repository *repo,
const char *start,
const char *end)
{
int error;
git_index *index;
if ((error = git_repository_index__weakptr(&index, repo)) < 0)
return error;
return git_iterator_for_index_range(iter, index, start, end);
}
typedef struct workdir_iterator_frame workdir_iterator_frame; typedef struct workdir_iterator_frame workdir_iterator_frame;
struct workdir_iterator_frame { struct workdir_iterator_frame {
...@@ -988,6 +974,22 @@ fail: ...@@ -988,6 +974,22 @@ fail:
return -1; return -1;
} }
void git_iterator_free(git_iterator *iter)
{
if (iter == NULL)
return;
iter->cb->free(iter);
git__free(iter->start);
git__free(iter->end);
memset(iter, 0, sizeof(*iter));
git__free(iter);
}
git_index *git_iterator_index_get_index(git_iterator *iter) git_index *git_iterator_index_get_index(git_iterator *iter)
{ {
if (iter->type == GIT_ITERATOR_INDEX) if (iter->type == GIT_ITERATOR_INDEX)
......
...@@ -44,47 +44,34 @@ struct git_iterator { ...@@ -44,47 +44,34 @@ struct git_iterator {
bool ignore_case; bool ignore_case;
}; };
extern int git_iterator_for_nothing(git_iterator **iter); extern int git_iterator_for_nothing(git_iterator **out);
extern int git_iterator_for_tree_range( extern int git_iterator_for_tree_range(
git_iterator **iter, git_tree *tree, git_iterator **out, git_tree *tree, const char *start, const char *end);
const char *start, const char *end);
GIT_INLINE(int) git_iterator_for_tree( GIT_INLINE(int) git_iterator_for_tree(git_iterator **out, git_tree *tree)
git_iterator **iter, git_tree *tree)
{ {
return git_iterator_for_tree_range(iter, tree, NULL, NULL); return git_iterator_for_tree_range(out, tree, NULL, NULL);
} }
extern int git_iterator_for_index_range( extern int git_iterator_for_index_range(
git_iterator **iter, git_index *index, const char *start, const char *end); git_iterator **out, git_index *index, const char *start, const char *end);
GIT_INLINE(int) git_iterator_for_index( GIT_INLINE(int) git_iterator_for_index(git_iterator **out, git_index *index)
git_iterator **iter, git_index *index)
{ {
return git_iterator_for_index_range(iter, index, NULL, NULL); return git_iterator_for_index_range(out, index, NULL, NULL);
}
extern int git_iterator_for_repo_index_range(
git_iterator **iter, git_repository *repo,
const char *start, const char *end);
GIT_INLINE(int) git_iterator_for_repo_index(
git_iterator **iter, git_repository *repo)
{
return git_iterator_for_repo_index_range(iter, repo, NULL, NULL);
} }
extern int git_iterator_for_workdir_range( extern int git_iterator_for_workdir_range(
git_iterator **iter, git_repository *repo, git_iterator **out, git_repository *repo, const char *start, const char *end);
const char *start, const char *end);
GIT_INLINE(int) git_iterator_for_workdir( GIT_INLINE(int) git_iterator_for_workdir(git_iterator **out, git_repository *repo)
git_iterator **iter, git_repository *repo)
{ {
return git_iterator_for_workdir_range(iter, repo, NULL, NULL); return git_iterator_for_workdir_range(out, repo, NULL, NULL);
} }
extern void git_iterator_free(git_iterator *iter);
/* Spool all iterator values, resort with alternative ignore_case value /* Spool all iterator values, resort with alternative ignore_case value
* and replace callbacks with spoolandsort alternates. * and replace callbacks with spoolandsort alternates.
*/ */
...@@ -130,21 +117,6 @@ GIT_INLINE(int) git_iterator_reset( ...@@ -130,21 +117,6 @@ GIT_INLINE(int) git_iterator_reset(
return iter->cb->reset(iter, start, end); return iter->cb->reset(iter, start, end);
} }
GIT_INLINE(void) git_iterator_free(git_iterator *iter)
{
if (iter == NULL)
return;
iter->cb->free(iter);
git__free(iter->start);
git__free(iter->end);
memset(iter, 0, sizeof(*iter));
git__free(iter);
}
GIT_INLINE(git_iterator_type_t) git_iterator_type(git_iterator *iter) GIT_INLINE(git_iterator_type_t) git_iterator_type(git_iterator *iter)
{ {
return iter->type; return iter->type;
......
...@@ -1130,10 +1130,12 @@ static int load_submodule_config_from_index( ...@@ -1130,10 +1130,12 @@ static int load_submodule_config_from_index(
git_repository *repo, git_oid *gitmodules_oid) git_repository *repo, git_oid *gitmodules_oid)
{ {
int error; int error;
git_index *index;
git_iterator *i; git_iterator *i;
const git_index_entry *entry; const git_index_entry *entry;
if ((error = git_iterator_for_repo_index(&i, repo)) < 0) if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
(error = git_iterator_for_index(&i, index)) < 0)
return error; return error;
error = git_iterator_current(i, &entry); error = git_iterator_current(i, &entry);
......
...@@ -355,12 +355,14 @@ static void index_iterator_test( ...@@ -355,12 +355,14 @@ static void index_iterator_test(
const char **expected_names, const char **expected_names,
const char **expected_oids) const char **expected_oids)
{ {
git_index *index;
git_iterator *i; git_iterator *i;
const git_index_entry *entry; const git_index_entry *entry;
int count = 0; int count = 0;
git_repository *repo = cl_git_sandbox_init(sandbox); git_repository *repo = cl_git_sandbox_init(sandbox);
cl_git_pass(git_iterator_for_repo_index_range(&i, repo, start, end)); cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_iterator_for_index_range(&i, index, start, end));
cl_git_pass(git_iterator_current(i, &entry)); cl_git_pass(git_iterator_current(i, &entry));
while (entry != NULL) { while (entry != NULL) {
...@@ -378,6 +380,7 @@ static void index_iterator_test( ...@@ -378,6 +380,7 @@ static void index_iterator_test(
} }
git_iterator_free(i); git_iterator_free(i);
git_index_free(index);
cl_assert_equal_i(expected_count, count); cl_assert_equal_i(expected_count, count);
} }
......
...@@ -620,9 +620,7 @@ static void assert_ignore_case( ...@@ -620,9 +620,7 @@ static void assert_ignore_case(
{ {
git_config *config; git_config *config;
unsigned int status; unsigned int status;
git_buf lower_case_path = GIT_BUF_INIT, git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT;
camel_case_path = GIT_BUF_INIT;
git_repository *repo, *repo2; git_repository *repo, *repo2;
repo = cl_git_sandbox_init("empty_standard_repo"); repo = cl_git_sandbox_init("empty_standard_repo");
...@@ -641,12 +639,12 @@ static void assert_ignore_case( ...@@ -641,12 +639,12 @@ static void assert_ignore_case(
cl_git_pass(git_repository_open(&repo2, "./empty_standard_repo")); cl_git_pass(git_repository_open(&repo2, "./empty_standard_repo"));
cl_git_pass(git_buf_joinpath(&camel_case_path,
git_repository_workdir(repo), "Plop"));
cl_git_pass(git_status_file(&status, repo2, "plop")); cl_git_pass(git_status_file(&status, repo2, "plop"));
cl_assert_equal_i(GIT_STATUS_CURRENT, status); cl_assert_equal_i(GIT_STATUS_CURRENT, status);
cl_git_pass(git_buf_joinpath(&camel_case_path,
git_repository_workdir(repo), "Plop"));
cl_git_pass(p_rename(git_buf_cstr(&lower_case_path), git_buf_cstr(&camel_case_path))); cl_git_pass(p_rename(git_buf_cstr(&lower_case_path), git_buf_cstr(&camel_case_path)));
cl_git_pass(git_status_file(&status, repo2, "plop")); cl_git_pass(git_status_file(&status, repo2, "plop"));
...@@ -660,12 +658,12 @@ static void assert_ignore_case( ...@@ -660,12 +658,12 @@ static void assert_ignore_case(
git_buf_free(&camel_case_path); git_buf_free(&camel_case_path);
} }
void test_status_worktree__file_status_honors_ignorecase_conf_setting_set_to_true(void) void test_status_worktree__file_status_honors_core_ignorecase_true(void)
{ {
assert_ignore_case(true, GIT_STATUS_CURRENT, GIT_STATUS_CURRENT); assert_ignore_case(true, GIT_STATUS_CURRENT, GIT_STATUS_CURRENT);
} }
void test_status_worktree__file_status_honors_ignorecase_conf_setting_set_to_false(void) void test_status_worktree__file_status_honors_core_ignorecase_false(void)
{ {
assert_ignore_case(false, GIT_STATUS_WT_DELETED, GIT_STATUS_WT_NEW); assert_ignore_case(false, GIT_STATUS_WT_DELETED, GIT_STATUS_WT_NEW);
} }
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