Skip to content

Commit 074336e

Browse files
mhaggergitster
authored andcommitted
lock_ref_sha1_basic(): do not set force_write for missing references
If a reference is missing, its SHA-1 will be null_sha1, which can't possibly match a new value that ref_transaction_commit() is trying to update it to. So there is no need to set force_write in this scenario. Signed-off-by: Michael Haggerty <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 706d5f8 commit 074336e

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

refs.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
22592259
int type, lflags;
22602260
int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
22612261
int resolve_flags = 0;
2262-
int missing = 0;
22632262
int attempts_remaining = 3;
22642263

22652264
lock = xcalloc(1, sizeof(struct ref_lock));
@@ -2298,13 +2297,13 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
22982297
orig_refname, strerror(errno));
22992298
goto error_return;
23002299
}
2301-
missing = is_null_sha1(lock->old_sha1);
2302-
/* When the ref did not exist and we are creating it,
2303-
* make sure there is no existing ref that is packed
2304-
* whose name begins with our refname, nor a ref whose
2305-
* name is a proper prefix of our refname.
2300+
/*
2301+
* If the ref did not exist and we are creating it, make sure
2302+
* there is no existing packed ref whose name begins with our
2303+
* refname, nor a packed ref whose name is a proper prefix of
2304+
* our refname.
23062305
*/
2307-
if (missing &&
2306+
if (is_null_sha1(lock->old_sha1) &&
23082307
!is_refname_available(refname, skip, get_packed_refs(&ref_cache))) {
23092308
last_errno = ENOTDIR;
23102309
goto error_return;
@@ -2320,8 +2319,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
23202319
lock->ref_name = xstrdup(refname);
23212320
lock->orig_ref_name = xstrdup(orig_refname);
23222321
ref_file = git_path("%s", refname);
2323-
if (missing)
2324-
lock->force_write = 1;
23252322
if ((flags & REF_NODEREF) && (type & REF_ISSYMREF))
23262323
lock->force_write = 1;
23272324

0 commit comments

Comments
 (0)