Skip to content

Commit d1f210f

Browse files
committed
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 parent ac5fbe3 commit d1f210f

File tree

3 files changed

+0
-111
lines changed

3 files changed

+0
-111
lines changed

src/repository.c

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,45 +2299,6 @@ int git_repository_foreach_worktree(git_repository *repo,
22992299
return error;
23002300
}
23012301

2302-
int git_repository_foreach_head(git_repository *repo,
2303-
git_repository_foreach_head_cb cb,
2304-
int flags, void *payload)
2305-
{
2306-
git_strarray worktrees = GIT_VECTOR_INIT;
2307-
git_buf path = GIT_BUF_INIT;
2308-
int error = 0;
2309-
size_t i;
2310-
2311-
2312-
if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO)) {
2313-
/* Gather HEAD of main repository */
2314-
if ((error = git_buf_joinpath(&path, repo->commondir, GIT_HEAD_FILE)) < 0 ||
2315-
(error = cb(repo, path.ptr, payload) != 0))
2316-
goto out;
2317-
}
2318-
2319-
if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_WORKTREES)) {
2320-
if ((error = git_worktree_list(&worktrees, repo)) < 0) {
2321-
error = 0;
2322-
goto out;
2323-
}
2324-
2325-
/* Gather HEADs of all worktrees */
2326-
for (i = 0; i < worktrees.count; i++) {
2327-
if (get_worktree_file_path(&path, repo, worktrees.strings[i], GIT_HEAD_FILE) < 0)
2328-
continue;
2329-
2330-
if ((error = cb(repo, path.ptr, payload)) != 0)
2331-
goto out;
2332-
}
2333-
}
2334-
2335-
out:
2336-
git_buf_dispose(&path);
2337-
git_strarray_dispose(&worktrees);
2338-
return error;
2339-
}
2340-
23412302
int git_repository_head_unborn(git_repository *repo)
23422303
{
23432304
git_reference *ref = NULL;

src/repository.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,6 @@ int git_repository_foreach_worktree(git_repository *repo,
172172
git_repository_foreach_worktree_cb cb,
173173
void *payload);
174174

175-
/*
176-
* Called for each HEAD.
177-
*
178-
* Can return either 0, causing the iteration over HEADs to
179-
* continue, or a non-0 value causing the iteration to abort. The
180-
* return value is passed back to the caller of
181-
* `git_repository_foreach_head`
182-
*/
183-
typedef int (*git_repository_foreach_head_cb)(git_repository *repo, const char *path, void *payload);
184-
185-
enum {
186-
/* Skip enumeration of the main repository HEAD */
187-
GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO = (1u << 0),
188-
/* Skip enumeration of worktree HEADs */
189-
GIT_REPOSITORY_FOREACH_HEAD_SKIP_WORKTREES = (1u << 1),
190-
};
191-
192-
/*
193-
* Iterate over repository and all worktree HEADs.
194-
*
195-
* This function will be called for the repository HEAD and for
196-
* all HEADS of linked worktrees. For each HEAD, the callback is
197-
* executed with the given payload. The return value equals the
198-
* return value of the last executed callback function.
199-
*/
200-
int git_repository_foreach_head(git_repository *repo,
201-
git_repository_foreach_head_cb cb,
202-
int flags, void *payload);
203-
204175
/*
205176
* Weak pointers to repository internals.
206177
*

tests/worktree/worktree.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -581,49 +581,6 @@ void test_worktree_worktree__prune_worktree(void)
581581
git_worktree_free(wt);
582582
}
583583

584-
static int read_head_ref(git_repository *repo, const char *path, void *payload)
585-
{
586-
git_vector *refs = (git_vector *) payload;
587-
git_reference *head;
588-
589-
GIT_UNUSED(repo);
590-
591-
cl_git_pass(git_reference__read_head(&head, repo, path));
592-
593-
git_vector_insert(refs, head);
594-
595-
return 0;
596-
}
597-
598-
void test_worktree_worktree__foreach_head_gives_same_results_in_wt_and_repo(void)
599-
{
600-
git_vector repo_refs = GIT_VECTOR_INIT, worktree_refs = GIT_VECTOR_INIT;
601-
git_reference *heads[2];
602-
size_t i;
603-
604-
cl_git_pass(git_reference_lookup(&heads[0], fixture.repo, GIT_HEAD_FILE));
605-
cl_git_pass(git_reference_lookup(&heads[1], fixture.worktree, GIT_HEAD_FILE));
606-
607-
cl_git_pass(git_repository_foreach_head(fixture.repo, read_head_ref, 0, &repo_refs));
608-
cl_git_pass(git_repository_foreach_head(fixture.worktree, read_head_ref, 0, &worktree_refs));
609-
610-
cl_assert_equal_i(repo_refs.length, ARRAY_SIZE(heads));
611-
cl_assert_equal_i(worktree_refs.length, ARRAY_SIZE(heads));
612-
613-
for (i = 0; i < ARRAY_SIZE(heads); i++) {
614-
cl_assert_equal_s(heads[i]->name, ((git_reference *) repo_refs.contents[i])->name);
615-
cl_assert_equal_s(heads[i]->name, ((git_reference *) repo_refs.contents[i])->name);
616-
cl_assert_equal_s(heads[i]->name, ((git_reference *) worktree_refs.contents[i])->name);
617-
618-
git_reference_free(heads[i]);
619-
git_reference_free(repo_refs.contents[i]);
620-
git_reference_free(worktree_refs.contents[i]);
621-
}
622-
623-
git_vector_free(&repo_refs);
624-
git_vector_free(&worktree_refs);
625-
}
626-
627584
static int foreach_worktree_cb(git_repository *worktree, void *payload)
628585
{
629586
int *counter = (int *)payload;

0 commit comments

Comments
 (0)