diff options
author | Russell Belfer <rb@github.com> | 2012-08-27 11:45:48 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-27 11:45:48 -0700 |
commit | 0b9174c621d1826cfbd0eec83cf7f0cc3cc0aa35 (patch) | |
tree | a6835b7ac3cd1e3bf9ba85e5a05eb566604bd688 | |
parent | 2b175ca972f2531e5ef46d24abeb831d90033a33 (diff) | |
parent | d1445b7528f17910b9d4301617b8129ee30d1c3e (diff) | |
download | libgit2-0b9174c621d1826cfbd0eec83cf7f0cc3cc0aa35.tar.gz |
Merge pull request #903 from nulltoken/topic/peeling-duplication
branch: reduce code duplication
-rw-r--r-- | src/branch.c | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/src/branch.c b/src/branch.c index 52fed67ad..f6f314035 100644 --- a/src/branch.c +++ b/src/branch.c @@ -57,7 +57,6 @@ int git_branch_create( const git_object *target, int force) { - git_otype target_type = GIT_OBJ_BAD; git_object *commit = NULL; git_reference *branch = NULL; git_buf canonical_branch_name = GIT_BUF_INIT; @@ -66,27 +65,8 @@ int git_branch_create( assert(branch_name && target && ref_out); assert(git_object_owner(target) == repository); - target_type = git_object_type(target); - - switch (target_type) - { - case GIT_OBJ_TAG: - if (git_tag_peel(&commit, (git_tag *)target) < 0) - goto cleanup; - - if (git_object_type(commit) != GIT_OBJ_COMMIT) { - create_error_invalid("The given target does not resolve to a commit"); - goto cleanup; - } - break; - - case GIT_OBJ_COMMIT: - commit = (git_object *)target; - break; - - default: - return create_error_invalid("Only git_tag and git_commit objects are valid targets."); - } + if (git_object_peel(&commit, (git_object *)target, GIT_OBJ_COMMIT) < 0) + return create_error_invalid("The given target does not resolve to a commit"); if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0) goto cleanup; @@ -99,9 +79,7 @@ int git_branch_create( error = 0; cleanup: - if (target_type == GIT_OBJ_TAG) - git_object_free(commit); - + git_object_free(commit); git_buf_free(&canonical_branch_name); return error; } |