summaryrefslogtreecommitdiff
path: root/src/branch.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-01-28 11:47:33 -0800
committerRussell Belfer <rb@github.com>2014-01-30 09:59:59 -0800
commit3cf11eef17d8359c032844de945da6e983572ecc (patch)
tree1611080fb64f96a21e06f01f12b79aa34581cb20 /src/branch.c
parentc0644c3fbb31c381afb2d0658b5c6e83432fd8c9 (diff)
downloadlibgit2-3cf11eef17d8359c032844de945da6e983572ecc.tar.gz
Misc cleanups
Diffstat (limited to 'src/branch.c')
-rw-r--r--src/branch.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/branch.c b/src/branch.c
index a1a04b2b4..d0dc21b85 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -21,27 +21,22 @@ static int retrieve_branch_reference(
const char *branch_name,
int is_remote)
{
- git_reference *branch;
- int error = -1;
+ git_reference *branch = NULL;
+ int error = 0;
char *prefix;
git_buf ref_name = GIT_BUF_INIT;
- *branch_reference_out = NULL;
-
prefix = is_remote ? GIT_REFS_REMOTES_DIR : GIT_REFS_HEADS_DIR;
- if (git_buf_joinpath(&ref_name, prefix, branch_name) < 0)
- goto cleanup;
+ if ((error = git_buf_joinpath(&ref_name, prefix, branch_name)) < 0)
+ /* OOM */;
+ else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0)
+ giterr_set(
+ GITERR_REFERENCE, "Cannot locate %s branch '%s'",
+ is_remote ? "remote-tracking" : "local", branch_name);
- if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0) {
- giterr_set(GITERR_REFERENCE,
- "Cannot locate %s branch '%s'.", is_remote ? "remote-tracking" : "local", branch_name);
- goto cleanup;
- }
+ *branch_reference_out = branch; /* will be NULL on error */
- *branch_reference_out = branch;
-
-cleanup:
git_buf_free(&ref_name);
return error;
}
@@ -63,21 +58,19 @@ int git_branch_create(
{
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT;
- int error = -1;
+ int error = 0;
assert(branch_name && commit && ref_out);
assert(git_object_owner((const git_object *)commit) == repository);
- if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
- goto cleanup;
-
- error = git_reference_create(&branch, repository,
- git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force, NULL, NULL);
+ if (!(error = git_buf_joinpath(
+ &canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name)))
+ error = git_reference_create(
+ &branch, repository, git_buf_cstr(&canonical_branch_name),
+ git_commit_id(commit), force, NULL, NULL);
- if (!error)
- *ref_out = branch;
+ *ref_out = branch;
-cleanup:
git_buf_free(&canonical_branch_name);
return error;
}