diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-02-15 10:41:30 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 11:28:08 +0100 |
commit | 32063d82a14742896c933ce31bac2d0656e410ca (patch) | |
tree | 14459718a41262d62bf58204432b5b604170e8d5 | |
parent | 8c77343871c1d8c6a2cc1149143d3577c0ccfc43 (diff) | |
download | libgit2-32063d82a14742896c933ce31bac2d0656e410ca.tar.gz |
refdb_fs: refactor error handling in iterator creation
Refactor the error handling in `refdb_fs_backend__iterator` to always return the
correct error code returned by the failing function.
-rw-r--r-- | src/refdb_fs.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 7d987b4cd..c7df6f20a 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -681,40 +681,41 @@ static int refdb_fs_backend__iterator_next_name( static int refdb_fs_backend__iterator( git_reference_iterator **out, git_refdb_backend *_backend, const char *glob) { - int error; - refdb_fs_iter *iter; refdb_fs_backend *backend = (refdb_fs_backend *)_backend; + refdb_fs_iter *iter = NULL; + int error; assert(backend); if ((error = packed_reload(backend)) < 0) - return error; + goto out; iter = git__calloc(1, sizeof(refdb_fs_iter)); GIT_ERROR_CHECK_ALLOC(iter); git_pool_init(&iter->pool, 1); - if (git_vector_init(&iter->loose, 8, NULL) < 0) - goto fail; + if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0) + goto out; if (glob != NULL && - (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL) - goto fail; + (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL) { + error = GIT_ERROR_NOMEMORY; + goto out; + } + + if ((error = iter_load_loose_paths(backend, iter)) < 0) + goto out; iter->parent.next = refdb_fs_backend__iterator_next; iter->parent.next_name = refdb_fs_backend__iterator_next_name; iter->parent.free = refdb_fs_backend__iterator_free; - if (iter_load_loose_paths(backend, iter) < 0) - goto fail; - *out = (git_reference_iterator *)iter; - return 0; - -fail: - refdb_fs_backend__iterator_free((git_reference_iterator *)iter); - return -1; +out: + if (error) + refdb_fs_backend__iterator_free((git_reference_iterator *)iter); + return error; } static bool ref_is_available( |