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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
diff --git a/src/iterator.c b/src/iterator.c
index 08e2e79..3d75dd8 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 8a4356e..727da97 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 a723266..5283322 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 b579063..de083ea 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 62f3f3c..ead1bc7 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);
}