summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-12-19 11:04:58 +0100
committerPatrick Steinhardt <ps@pks.im>2018-12-19 11:04:58 +0100
commit8dde7e1137a05bdb6f6309f68ae6b0cfa61e2a71 (patch)
tree5e0df8bc28df9d8ac48087c07391fe6c4f3ba094
parentbc2196575467e7fef30a445d5ae840350ed0467e (diff)
downloadlibgit2-8dde7e1137a05bdb6f6309f68ae6b0cfa61e2a71.tar.gz
refdb_fs: refactor error handling in `refdb_reflog_fs__delete`
The function `refdb_reflog_fs__delete` uses the `if (!error && foobar())` pattern of checking, where error conditions are being checked by following calls to different code. This does not match our current style, where the call-site of a function is usually directly responsible for checking the return value. Convert the function to use `if ((error = foobar()) < 0) goto out;` style. Note that this changes the code flow a bit: previously, we were always trying to delete empty reference hierarchies even if deleting the reflog entry has failed. This wasn't much of a problem -- if deletion failed, the hierarchy will still contain at least one file and thus the function call was an expensive no-op. Now, we will only perform this deletion if we have successfully removed the reflog.
-rw-r--r--src/refdb_fs.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 46f552e91..1eebf5174 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(