Skip to content

Commit 6591dee

Browse files
committed
repo: remove an inappropriate use of PASSTHROUGH
This error code is for callbacks where we should act as though the callback was not set. This is not something that makes sense for a `_foreach` and checking for that error message to bubble up mostly is happenstance precisely because this is not an error code we expect in the callback. As part of removing this, let's also remove a use of foreach as we can open-code this check.
1 parent 34b9a04 commit 6591dee

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/repository.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,21 +2354,19 @@ int git_repository_head_unborn(git_repository *repo)
23542354
return 0;
23552355
}
23562356

2357-
static int at_least_one_cb(const char *refname, void *payload)
2358-
{
2359-
GIT_UNUSED(refname);
2360-
GIT_UNUSED(payload);
2361-
return GIT_PASSTHROUGH;
2362-
}
2363-
23642357
static int repo_contains_no_reference(git_repository *repo)
23652358
{
2366-
int error = git_reference_foreach_name(repo, &at_least_one_cb, NULL);
2359+
git_reference_iterator *iter;
2360+
const char *refname;
2361+
int error;
23672362

2368-
if (error == GIT_PASSTHROUGH)
2369-
return 0;
2363+
if ((error = git_reference_iterator_new(&iter, repo)) < 0)
2364+
return error;
23702365

2371-
if (!error)
2366+
error = git_reference_next_name(&refname, iter);
2367+
git_reference_iterator_free(iter);
2368+
2369+
if (error == GIT_ITEROVER)
23722370
return 1;
23732371

23742372
return error;

0 commit comments

Comments
 (0)