Merge pull request #4915 from pks-t/pks/refdb-minor-refactorings refdb_fs: refactor error handling in `refdb_reflog_fs__delete`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 46f552e..1eebf51 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -2046,28 +2046,27 @@ cleanup:
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
{
- int error;
+ refdb_fs_backend *backend = (refdb_fs_backend *) _backend;
git_buf path = GIT_BUF_INIT;
-
- git_repository *repo;
- refdb_fs_backend *backend;
+ int error;
assert(_backend && name);
- backend = (refdb_fs_backend *) _backend;
- repo = backend->repo;
+ if ((error = retrieve_reflog_path(&path, backend->repo, name)) < 0)
+ goto out;
- error = retrieve_reflog_path(&path, repo, name);
+ if (!git_path_exists(path.ptr))
+ goto out;
- if (!error && git_path_exists(path.ptr)) {
- error = p_unlink(path.ptr);
- refdb_fs_backend__try_delete_empty_ref_hierarchie(backend, name, true);
- }
+ if ((error = p_unlink(path.ptr)) < 0)
+ goto out;
+ refdb_fs_backend__try_delete_empty_ref_hierarchie(backend, name, true);
+
+out:
git_buf_dispose(&path);
return error;
-
}
int git_refdb_backend_fs(