From f0244463ad280664d2cac950fcc5d6ff550905d1 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 27 Jul 2012 18:49:37 +0200 Subject: [PATCH] branch: Add `repository` argument to `create` Yes, we can get the repository from the owner of the object, but having it marked explicitly makes the API more consistent. --- include/git2/branch.h | 1 + src/branch.c | 7 +++++-- src/reflog.c | 2 +- tests-clar/refs/branches/create.c | 12 ++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/git2/branch.h b/include/git2/branch.h index 15894b709..2f46720af 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -47,6 +47,7 @@ GIT_BEGIN_DECL */ GIT_EXTERN(int) git_branch_create( git_reference **branch_out, + git_repository *repo, const char *branch_name, const git_object *target, int force); diff --git a/src/branch.c b/src/branch.c index d11eca8da..52fed67ad 100644 --- a/src/branch.c +++ b/src/branch.c @@ -52,6 +52,7 @@ static int create_error_invalid(const char *msg) int git_branch_create( git_reference **ref_out, + git_repository *repository, const char *branch_name, const git_object *target, int force) @@ -63,6 +64,7 @@ int git_branch_create( int error = -1; assert(branch_name && target && ref_out); + assert(git_object_owner(target) == repository); target_type = git_object_type(target); @@ -89,7 +91,7 @@ int git_branch_create( if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0) goto cleanup; - if (git_reference_create_oid(&branch, git_object_owner(commit), + if (git_reference_create_oid(&branch, repository, git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0) goto cleanup; @@ -224,7 +226,8 @@ int git_branch_lookup( return retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE); } -int retrieve_tracking_configuration(const char **out, git_reference *branch, const char *format) +static int retrieve_tracking_configuration( + const char **out, git_reference *branch, const char *format) { git_config *config; git_buf buf = GIT_BUF_INIT; diff --git a/src/reflog.c b/src/reflog.c index 445e53942..53cc25fa1 100644 --- a/src/reflog.c +++ b/src/reflog.c @@ -183,7 +183,7 @@ static int retrieve_reflog_path(git_buf *path, git_reference *ref) git_reference_owner(ref)->path_repository, GIT_REFLOG_DIR, ref->name); } -int create_new_reflog_file(const char *filepath) +static int create_new_reflog_file(const char *filepath) { int fd; diff --git a/tests-clar/refs/branches/create.c b/tests-clar/refs/branches/create.c index d53904303..fe72d4708 100644 --- a/tests-clar/refs/branches/create.c +++ b/tests-clar/refs/branches/create.c @@ -42,7 +42,7 @@ void test_refs_branches_create__can_create_a_local_branch(void) { retrieve_known_commit(&target, repo); - cl_git_pass(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0)); + cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0)); cl_git_pass(git_oid_cmp(git_reference_oid(branch), git_object_id(target))); } @@ -50,14 +50,14 @@ void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with { retrieve_known_commit(&target, repo); - cl_git_fail(git_branch_create(&branch, "br2", target, 0)); + cl_git_fail(git_branch_create(&branch, repo, "br2", target, 0)); } void test_refs_branches_create__can_force_create_over_an_existing_branch(void) { retrieve_known_commit(&target, repo); - cl_git_pass(git_branch_create(&branch, "br2", target, 1)); + cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1)); cl_git_pass(git_oid_cmp(git_reference_oid(branch), git_object_id(target))); cl_assert_equal_s("refs/heads/br2", git_reference_name(branch)); } @@ -67,7 +67,7 @@ void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_i /* b25fa35 is a tag, pointing to another tag which points to a commit */ retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); - cl_git_pass(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0)); + cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0)); cl_git_pass(git_oid_streq(git_reference_oid(branch), "e90810b8df3e80c413d903f631643c716887138d")); } @@ -76,11 +76,11 @@ void test_refs_branches_create__can_not_create_a_branch_pointing_to_a_non_commit /* 53fc32d is the tree of commit e90810b */ retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016"); - cl_git_fail(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0)); + cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0)); git_object_free(target); /* 521d87c is an annotated tag pointing to a blob */ retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"); - cl_git_fail(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0)); + cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0)); } -- 2.39.5