Commit f0244463 by Vicent Marti

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.
parent b41a30bd
...@@ -47,6 +47,7 @@ GIT_BEGIN_DECL ...@@ -47,6 +47,7 @@ GIT_BEGIN_DECL
*/ */
GIT_EXTERN(int) git_branch_create( GIT_EXTERN(int) git_branch_create(
git_reference **branch_out, git_reference **branch_out,
git_repository *repo,
const char *branch_name, const char *branch_name,
const git_object *target, const git_object *target,
int force); int force);
......
...@@ -52,6 +52,7 @@ static int create_error_invalid(const char *msg) ...@@ -52,6 +52,7 @@ static int create_error_invalid(const char *msg)
int git_branch_create( int git_branch_create(
git_reference **ref_out, git_reference **ref_out,
git_repository *repository,
const char *branch_name, const char *branch_name,
const git_object *target, const git_object *target,
int force) int force)
...@@ -63,6 +64,7 @@ int git_branch_create( ...@@ -63,6 +64,7 @@ int git_branch_create(
int error = -1; int error = -1;
assert(branch_name && target && ref_out); assert(branch_name && target && ref_out);
assert(git_object_owner(target) == repository);
target_type = git_object_type(target); target_type = git_object_type(target);
...@@ -89,7 +91,7 @@ int git_branch_create( ...@@ -89,7 +91,7 @@ int git_branch_create(
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0) if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup; 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) git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0)
goto cleanup; goto cleanup;
...@@ -224,7 +226,8 @@ int git_branch_lookup( ...@@ -224,7 +226,8 @@ int git_branch_lookup(
return retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE); 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_config *config;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
......
...@@ -183,7 +183,7 @@ static int retrieve_reflog_path(git_buf *path, git_reference *ref) ...@@ -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); 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; int fd;
......
...@@ -42,7 +42,7 @@ void test_refs_branches_create__can_create_a_local_branch(void) ...@@ -42,7 +42,7 @@ void test_refs_branches_create__can_create_a_local_branch(void)
{ {
retrieve_known_commit(&target, repo); 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))); 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 ...@@ -50,14 +50,14 @@ void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with
{ {
retrieve_known_commit(&target, repo); 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) void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
{ {
retrieve_known_commit(&target, repo); 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_git_pass(git_oid_cmp(git_reference_oid(branch), git_object_id(target)));
cl_assert_equal_s("refs/heads/br2", git_reference_name(branch)); 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 ...@@ -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 */ /* b25fa35 is a tag, pointing to another tag which points to a commit */
retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); 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")); 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 ...@@ -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 */ /* 53fc32d is the tree of commit e90810b */
retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016"); 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); git_object_free(target);
/* 521d87c is an annotated tag pointing to a blob */ /* 521d87c is an annotated tag pointing to a blob */
retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"); 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));
} }
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