Commit 32063d82 by Patrick Steinhardt

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.
parent 8c773438
...@@ -681,40 +681,41 @@ static int refdb_fs_backend__iterator_next_name( ...@@ -681,40 +681,41 @@ static int refdb_fs_backend__iterator_next_name(
static int refdb_fs_backend__iterator( static int refdb_fs_backend__iterator(
git_reference_iterator **out, git_refdb_backend *_backend, const char *glob) 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_backend *backend = (refdb_fs_backend *)_backend;
refdb_fs_iter *iter = NULL;
int error;
assert(backend); assert(backend);
if ((error = packed_reload(backend)) < 0) if ((error = packed_reload(backend)) < 0)
return error; goto out;
iter = git__calloc(1, sizeof(refdb_fs_iter)); iter = git__calloc(1, sizeof(refdb_fs_iter));
GIT_ERROR_CHECK_ALLOC(iter); GIT_ERROR_CHECK_ALLOC(iter);
git_pool_init(&iter->pool, 1); git_pool_init(&iter->pool, 1);
if (git_vector_init(&iter->loose, 8, NULL) < 0) if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0)
goto fail; goto out;
if (glob != NULL && if (glob != NULL &&
(iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL) (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL) {
goto fail; 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 = refdb_fs_backend__iterator_next;
iter->parent.next_name = refdb_fs_backend__iterator_next_name; iter->parent.next_name = refdb_fs_backend__iterator_next_name;
iter->parent.free = refdb_fs_backend__iterator_free; iter->parent.free = refdb_fs_backend__iterator_free;
if (iter_load_loose_paths(backend, iter) < 0)
goto fail;
*out = (git_reference_iterator *)iter; *out = (git_reference_iterator *)iter;
return 0; out:
if (error)
fail: refdb_fs_backend__iterator_free((git_reference_iterator *)iter);
refdb_fs_backend__iterator_free((git_reference_iterator *)iter); return error;
return -1;
} }
static bool ref_is_available( static bool ref_is_available(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment