diff options
author | Russell Belfer <rb@github.com> | 2013-01-09 01:39:15 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-01-15 21:49:32 +0400 |
commit | 4b181037553601a0747ad39ccdd85ebd3b184055 (patch) | |
tree | 1f4bb97ad79bd9f86337d372317e68f862fa1b3c | |
parent | facc0650b12655c9637732bb992d1053cd946057 (diff) |
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
-rw-r--r-- | src/iterator.c | 30 | ||||
-rw-r--r-- | src/iterator.h | 52 | ||||
-rw-r--r-- | src/submodule.c | 4 | ||||
-rw-r--r-- | tests-clar/diff/iterator.c | 5 | ||||
-rw-r--r-- | tests-clar/status/worktree.c | 16 |
5 files changed, 42 insertions, 65 deletions
diff --git a/src/iterator.c b/src/iterator.c index 08e2e79e4..3d75dd8b5 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -485,20 +485,6 @@ int git_iterator_for_index_range( 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; struct workdir_iterator_frame { @@ -988,6 +974,22 @@ fail: 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) { if (iter->type == GIT_ITERATOR_INDEX) diff --git a/src/iterator.h b/src/iterator.h index 8a4356e3e..727da97b3 100644 --- a/src/iterator.h +++ b/src/iterator.h @@ -44,47 +44,34 @@ struct git_iterator { 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( - git_iterator **iter, git_tree *tree, - const char *start, const char *end); + git_iterator **out, git_tree *tree, const char *start, const char *end); -GIT_INLINE(int) git_iterator_for_tree( - git_iterator **iter, git_tree *tree) +GIT_INLINE(int) git_iterator_for_tree(git_iterator **out, 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( - 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_iterator **iter, git_index *index) +GIT_INLINE(int) git_iterator_for_index(git_iterator **out, git_index *index) { - return git_iterator_for_index_range(iter, 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); + return git_iterator_for_index_range(out, index, NULL, NULL); } extern int git_iterator_for_workdir_range( - git_iterator **iter, git_repository *repo, - const char *start, const char *end); + git_iterator **out, git_repository *repo, const char *start, const char *end); -GIT_INLINE(int) git_iterator_for_workdir( - git_iterator **iter, git_repository *repo) +GIT_INLINE(int) git_iterator_for_workdir(git_iterator **out, 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 * and replace callbacks with spoolandsort alternates. */ @@ -130,21 +117,6 @@ GIT_INLINE(int) git_iterator_reset( 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) { return iter->type; diff --git a/src/submodule.c b/src/submodule.c index a72326602..5283322f2 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -1130,10 +1130,12 @@ static int load_submodule_config_from_index( git_repository *repo, git_oid *gitmodules_oid) { int error; + git_index *index; git_iterator *i; 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; error = git_iterator_current(i, &entry); diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c index b5790632d..de083ea36 100644 --- a/tests-clar/diff/iterator.c +++ b/tests-clar/diff/iterator.c @@ -355,12 +355,14 @@ static void index_iterator_test( const char **expected_names, const char **expected_oids) { + git_index *index; git_iterator *i; const git_index_entry *entry; int count = 0; 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)); while (entry != NULL) { @@ -378,6 +380,7 @@ static void index_iterator_test( } git_iterator_free(i); + git_index_free(index); cl_assert_equal_i(expected_count, count); } diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index 62f3f3cf3..ead1bc734 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -620,11 +620,9 @@ static void assert_ignore_case( { git_config *config; unsigned int status; - git_buf lower_case_path = GIT_BUF_INIT, - camel_case_path = GIT_BUF_INIT; - + git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT; git_repository *repo, *repo2; - + repo = cl_git_sandbox_init("empty_standard_repo"); cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt"); @@ -641,12 +639,12 @@ static void assert_ignore_case( 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_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(git_status_file(&status, repo2, "plop")); @@ -660,12 +658,12 @@ static void assert_ignore_case( 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); } -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); } |