Commit 869ae5a3 by Patrick Steinhardt

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.
parent 0d12b8dd
......@@ -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)
......
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