Skip to content

Commit 4da50de

Browse files
mhaggergitster
authored andcommitted
ref_transaction_commit(): inline call to write_ref_sha1()
And remove the function write_ref_sha1(), as it is no longer used. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 29957fd commit 4da50de

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

refs.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,30 +3134,6 @@ static int commit_ref_update(struct ref_lock *lock,
31343134
return 0;
31353135
}
31363136

3137-
/*
3138-
* Write sha1 as the new value of the reference specified by the
3139-
* (open) lock. On error, roll back the lockfile and set errno
3140-
* appropriately.
3141-
*/
3142-
static int write_ref_sha1(struct ref_lock *lock,
3143-
const unsigned char *sha1, const char *logmsg)
3144-
{
3145-
if (!lock) {
3146-
errno = EINVAL;
3147-
return -1;
3148-
}
3149-
if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {
3150-
unlock_ref(lock);
3151-
return 0;
3152-
}
3153-
3154-
if (write_ref_to_lockfile(lock, sha1) ||
3155-
commit_ref_update(lock, sha1, logmsg))
3156-
return -1;
3157-
3158-
return 0;
3159-
}
3160-
31613137
int create_symref(const char *ref_target, const char *refs_heads_master,
31623138
const char *logmsg)
31633139
{
@@ -3852,15 +3828,21 @@ int ref_transaction_commit(struct ref_transaction *transaction,
38523828
struct ref_update *update = updates[i];
38533829

38543830
if (!is_null_sha1(update->new_sha1)) {
3855-
if (write_ref_sha1(update->lock, update->new_sha1,
3856-
update->msg)) {
3857-
update->lock = NULL; /* freed by write_ref_sha1 */
3831+
if (!update->lock->force_write &&
3832+
!hashcmp(update->lock->old_sha1, update->new_sha1)) {
3833+
unlock_ref(update->lock);
3834+
update->lock = NULL;
3835+
} else if (write_ref_to_lockfile(update->lock, update->new_sha1) ||
3836+
commit_ref_update(update->lock, update->new_sha1, update->msg)) {
3837+
update->lock = NULL; /* freed by the above calls */
38583838
strbuf_addf(err, "Cannot update the ref '%s'.",
38593839
update->refname);
38603840
ret = TRANSACTION_GENERIC_ERROR;
38613841
goto cleanup;
3842+
} else {
3843+
/* freed by the above calls: */
3844+
update->lock = NULL;
38623845
}
3863-
update->lock = NULL; /* freed by write_ref_sha1 */
38643846
}
38653847
}
38663848

0 commit comments

Comments
 (0)