Unverified Commit 1fd26760 by Edward Thomson Committed by GitHub

Merge pull request #4618 from tiennou/fix/pwned-references

refs: preserve the owning refdb when duping reference
parents d7f413c0 2dc54855
......@@ -115,6 +115,9 @@ int git_reference_dup(git_reference **dest, git_reference *source)
GITERR_CHECK_ALLOC(*dest);
(*dest)->db = source->db;
GIT_REFCOUNT_INC((*dest)->db);
return 0;
}
......
......@@ -116,6 +116,10 @@ int git_reference_lookup_resolved(
* with the given name pointing to the reference pointed to by
* the file. If it is not a symbolic reference, it will return
* the resolved reference.
*
* Note that because the refdb is not involved for symbolic references, they
* won't be owned, hence you should either not make the returned reference
* 'externally visible', or perform the lookup before returning it to the user.
*/
int git_reference__read_head(
git_reference **out,
......
......@@ -21,6 +21,7 @@ void test_refs_dup__direct(void)
cl_git_pass(git_reference_dup(&b, a));
cl_assert(git_reference_cmp(a, b) == 0);
cl_assert(git_reference_owner(b) == g_repo);
git_reference_free(b);
git_reference_free(a);
......@@ -34,6 +35,7 @@ void test_refs_dup__symbolic(void)
cl_git_pass(git_reference_dup(&b, a));
cl_assert(git_reference_cmp(a, b) == 0);
cl_assert(git_reference_owner(b) == g_repo);
git_reference_free(b);
git_reference_free(a);
......
......@@ -27,6 +27,7 @@ void test_worktree_repository__head(void)
cl_git_pass(git_reference_lookup(&ref, fixture.repo, "refs/heads/testrepo-worktree"));
cl_git_pass(git_repository_head_for_worktree(&head, fixture.repo, "testrepo-worktree"));
cl_assert(git_reference_cmp(ref, head) == 0);
cl_assert(git_reference_owner(ref) == fixture.repo);
git_reference_free(ref);
git_reference_free(head);
......
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