repository: remove function to iterate over HEADs The function `git_repository_foreach_head` is broken, as it directly interacts with the on-disk representation of the reference database, thus assuming that no other refdb is used for the given repository. As this is an internal function only and all users have been replaced, let's remove this function.
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
diff --git a/src/repository.c b/src/repository.c
index 6c73703..89d8ab1 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -2299,45 +2299,6 @@ out:
return error;
}
-int git_repository_foreach_head(git_repository *repo,
- git_repository_foreach_head_cb cb,
- int flags, void *payload)
-{
- git_strarray worktrees = GIT_VECTOR_INIT;
- git_buf path = GIT_BUF_INIT;
- int error = 0;
- size_t i;
-
-
- if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO)) {
- /* Gather HEAD of main repository */
- if ((error = git_buf_joinpath(&path, repo->commondir, GIT_HEAD_FILE)) < 0 ||
- (error = cb(repo, path.ptr, payload) != 0))
- goto out;
- }
-
- if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_WORKTREES)) {
- if ((error = git_worktree_list(&worktrees, repo)) < 0) {
- error = 0;
- goto out;
- }
-
- /* Gather HEADs of all worktrees */
- for (i = 0; i < worktrees.count; i++) {
- if (get_worktree_file_path(&path, repo, worktrees.strings[i], GIT_HEAD_FILE) < 0)
- continue;
-
- if ((error = cb(repo, path.ptr, payload)) != 0)
- goto out;
- }
- }
-
-out:
- git_buf_dispose(&path);
- git_strarray_dispose(&worktrees);
- return error;
-}
-
int git_repository_head_unborn(git_repository *repo)
{
git_reference *ref = NULL;
diff --git a/src/repository.h b/src/repository.h
index a823bdc..d73e77d 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -173,35 +173,6 @@ int git_repository_foreach_worktree(git_repository *repo,
void *payload);
/*
- * Called for each HEAD.
- *
- * Can return either 0, causing the iteration over HEADs to
- * continue, or a non-0 value causing the iteration to abort. The
- * return value is passed back to the caller of
- * `git_repository_foreach_head`
- */
-typedef int (*git_repository_foreach_head_cb)(git_repository *repo, const char *path, void *payload);
-
-enum {
- /* Skip enumeration of the main repository HEAD */
- GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO = (1u << 0),
- /* Skip enumeration of worktree HEADs */
- GIT_REPOSITORY_FOREACH_HEAD_SKIP_WORKTREES = (1u << 1),
-};
-
-/*
- * Iterate over repository and all worktree HEADs.
- *
- * This function will be called for the repository HEAD and for
- * all HEADS of linked worktrees. For each HEAD, the callback is
- * executed with the given payload. The return value equals the
- * return value of the last executed callback function.
- */
-int git_repository_foreach_head(git_repository *repo,
- git_repository_foreach_head_cb cb,
- int flags, void *payload);
-
-/*
* Weak pointers to repository internals.
*
* The returned pointers do not need to be freed. Do not keep
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index a08c305..cd20bed 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -581,49 +581,6 @@ void test_worktree_worktree__prune_worktree(void)
git_worktree_free(wt);
}
-static int read_head_ref(git_repository *repo, const char *path, void *payload)
-{
- git_vector *refs = (git_vector *) payload;
- git_reference *head;
-
- GIT_UNUSED(repo);
-
- cl_git_pass(git_reference__read_head(&head, repo, path));
-
- git_vector_insert(refs, head);
-
- return 0;
-}
-
-void test_worktree_worktree__foreach_head_gives_same_results_in_wt_and_repo(void)
-{
- git_vector repo_refs = GIT_VECTOR_INIT, worktree_refs = GIT_VECTOR_INIT;
- git_reference *heads[2];
- size_t i;
-
- cl_git_pass(git_reference_lookup(&heads[0], fixture.repo, GIT_HEAD_FILE));
- cl_git_pass(git_reference_lookup(&heads[1], fixture.worktree, GIT_HEAD_FILE));
-
- cl_git_pass(git_repository_foreach_head(fixture.repo, read_head_ref, 0, &repo_refs));
- cl_git_pass(git_repository_foreach_head(fixture.worktree, read_head_ref, 0, &worktree_refs));
-
- cl_assert_equal_i(repo_refs.length, ARRAY_SIZE(heads));
- cl_assert_equal_i(worktree_refs.length, ARRAY_SIZE(heads));
-
- for (i = 0; i < ARRAY_SIZE(heads); i++) {
- cl_assert_equal_s(heads[i]->name, ((git_reference *) repo_refs.contents[i])->name);
- cl_assert_equal_s(heads[i]->name, ((git_reference *) repo_refs.contents[i])->name);
- cl_assert_equal_s(heads[i]->name, ((git_reference *) worktree_refs.contents[i])->name);
-
- git_reference_free(heads[i]);
- git_reference_free(repo_refs.contents[i]);
- git_reference_free(worktree_refs.contents[i]);
- }
-
- git_vector_free(&repo_refs);
- git_vector_free(&worktree_refs);
-}
-
static int foreach_worktree_cb(git_repository *worktree, void *payload)
{
int *counter = (int *)payload;