Skip to content

Commit 5894438

Browse files
committed
Merge branch 'zero_oid_in_old'
Manually merging libgit2#5842
2 parents be95f68 + cf323cb commit 5894438

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

include/git2/refs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
9797
* of updating does not match the one passed through `current_value`
9898
* (i.e. if the ref has changed since the user read it).
9999
*
100+
* If `current_value` is all zeros, this function will return GIT_EMODIFIED
101+
* if the ref already exists.
102+
*
100103
* @param out Pointer to the newly created reference
101104
* @param repo Repository where that reference will live
102105
* @param name The name of the reference

src/refdb_fs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,11 @@ static int cmp_old_ref(int *cmp, git_refdb_backend *backend, const char *name,
11731173
if (!old_id && !old_target)
11741174
return 0;
11751175

1176-
if ((error = refdb_fs_backend__lookup(&old_ref, backend, name)) < 0)
1176+
if ((error = refdb_fs_backend__lookup(&old_ref, backend, name)) < 0) {
1177+
if (error == GIT_ENOTFOUND && old_id && git_oid_is_zero(old_id))
1178+
return 0;
11771179
goto out;
1180+
}
11781181

11791182
/* If the types don't match, there's no way the values do */
11801183
if (old_id && old_ref->type != GIT_REFERENCE_DIRECT) {

tests/refs/races.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ void test_refs_races__cleanup(void)
2222
cl_git_sandbox_cleanup();
2323
}
2424

25+
void test_refs_races__create_matching_zero_old(void)
26+
{
27+
git_reference *ref;
28+
git_oid id, zero_id;
29+
30+
git_oid_fromstr(&id, commit_id);
31+
git_oid_fromstr(&zero_id, "0000000000000000000000000000000000000000");
32+
33+
cl_git_fail(git_reference_create_matching(&ref, g_repo, refname, &id, 1, &zero_id, NULL));
34+
35+
cl_git_pass(git_reference_create_matching(&ref, g_repo, other_refname, &id, 1, &zero_id, NULL));
36+
cl_git_fail(git_reference_create_matching(&ref, g_repo, other_refname, &id, 1, &zero_id, NULL));
37+
38+
git_reference_free(ref);
39+
}
40+
2541
void test_refs_races__create_matching(void)
2642
{
2743
git_reference *ref, *ref2, *ref3;

0 commit comments

Comments
 (0)