summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-07-19 10:15:43 +0200
committerPatrick Steinhardt <ps@pks.im>2019-07-19 13:02:57 +0200
commit869ae5a3a1e00464439172b34ff1c80ace0d4095 (patch)
tree38d7a2ea9138d007d4236f2f57f040162ec45f17
parent0d12b8dd77010f53cac936947c2b1b51452c5ac9 (diff)
downloadlibgit2-869ae5a3a1e00464439172b34ff1c80ace0d4095.tar.gz
repository: avoid swallowing error codes in `create_head`
The error handling in `git_repository_create_head` completely swallows all error codes. While probably not too much of a problem, this also violates our usual coding style. Refactor the code to use a local `error` variable with the typical `goto out` statements.
-rw-r--r--src/repository.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/repository.c b/src/repository.c
index 71386d65f..c40efa352 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1360,10 +1360,11 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
git_buf ref_path = GIT_BUF_INIT;
git_filebuf ref = GIT_FILEBUF_INIT;
const char *fmt;
+ int error;
- if (git_buf_joinpath(&ref_path, git_dir, GIT_HEAD_FILE) < 0 ||
- git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE) < 0)
- goto fail;
+ if ((error = git_buf_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
+ (error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
+ goto out;
if (!ref_name)
ref_name = GIT_BRANCH_MASTER;
@@ -1373,17 +1374,14 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
else
fmt = "ref: " GIT_REFS_HEADS_DIR "%s\n";
- if (git_filebuf_printf(&ref, fmt, ref_name) < 0 ||
- git_filebuf_commit(&ref) < 0)
- goto fail;
-
- git_buf_dispose(&ref_path);
- return 0;
+ if ((error = git_filebuf_printf(&ref, fmt, ref_name)) < 0 ||
+ (error = git_filebuf_commit(&ref)) < 0)
+ goto out;
-fail:
+out:
git_buf_dispose(&ref_path);
git_filebuf_cleanup(&ref);
- return -1;
+ return error;
}
static bool is_chmod_supported(const char *file_path)