diff options
author | Carlos Martín Nieto <carlosmn@github.com> | 2021-04-11 14:27:14 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlosmn@github.com> | 2021-04-11 18:29:48 +0200 |
commit | 6591deefbf2443ef2162ac2384620bf0ec8065cb (patch) | |
tree | 01149564f445c99d0164f0791bddcae215563b32 | |
parent | 34b9a04c77235dfc9401cb7ef8efc6c4ee7e99dd (diff) | |
download | libgit2-cmn/repo-no-passthrough.tar.gz |
repo: remove an inappropriate use of PASSTHROUGHcmn/repo-no-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.
-rw-r--r-- | src/repository.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/repository.c b/src/repository.c index 2c8b8192e..4ad87c11e 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2354,21 +2354,19 @@ int git_repository_head_unborn(git_repository *repo) return 0; } -static int at_least_one_cb(const char *refname, void *payload) -{ - GIT_UNUSED(refname); - GIT_UNUSED(payload); - return GIT_PASSTHROUGH; -} - static int repo_contains_no_reference(git_repository *repo) { - int error = git_reference_foreach_name(repo, &at_least_one_cb, NULL); + git_reference_iterator *iter; + const char *refname; + int error; - if (error == GIT_PASSTHROUGH) - return 0; + if ((error = git_reference_iterator_new(&iter, repo)) < 0) + return error; - if (!error) + error = git_reference_next_name(&refname, iter); + git_reference_iterator_free(iter); + + if (error == GIT_ITEROVER) return 1; return error; |