ref_transaction_update(): remove "have_old" parameter
Instead, verify the reference's old value if and only if old_sha1 is non-NULL. ref_transaction_delete() will get the same treatment in a moment. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
8df4e51138
commit
1d147bdff0
18
refs.c
18
refs.c
@ -3654,7 +3654,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const unsigned char *new_sha1,
|
||||
const unsigned char *old_sha1,
|
||||
unsigned int flags, int have_old, const char *msg,
|
||||
unsigned int flags, const char *msg,
|
||||
struct strbuf *err)
|
||||
{
|
||||
struct ref_update *update;
|
||||
@ -3664,9 +3664,6 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
||||
if (transaction->state != REF_TRANSACTION_OPEN)
|
||||
die("BUG: update called for transaction that is not open");
|
||||
|
||||
if (have_old && !old_sha1)
|
||||
die("BUG: have_old is true but old_sha1 is NULL");
|
||||
|
||||
if (!is_null_sha1(new_sha1) &&
|
||||
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
|
||||
strbuf_addf(err, "refusing to update ref with bad name %s",
|
||||
@ -3676,7 +3673,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
||||
|
||||
update = add_update(transaction, refname);
|
||||
hashcpy(update->new_sha1, new_sha1);
|
||||
if (have_old) {
|
||||
if (old_sha1) {
|
||||
hashcpy(update->old_sha1, old_sha1);
|
||||
flags |= REF_HAVE_OLD;
|
||||
}
|
||||
@ -3693,7 +3690,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
|
||||
struct strbuf *err)
|
||||
{
|
||||
return ref_transaction_update(transaction, refname, new_sha1,
|
||||
null_sha1, flags, 1, msg, err);
|
||||
null_sha1, flags, msg, err);
|
||||
}
|
||||
|
||||
int ref_transaction_delete(struct ref_transaction *transaction,
|
||||
@ -3702,8 +3699,9 @@ int ref_transaction_delete(struct ref_transaction *transaction,
|
||||
unsigned int flags, int have_old, const char *msg,
|
||||
struct strbuf *err)
|
||||
{
|
||||
return ref_transaction_update(transaction, refname, null_sha1,
|
||||
old_sha1, flags, have_old, msg, err);
|
||||
return ref_transaction_update(transaction, refname,
|
||||
null_sha1, have_old ? old_sha1 : NULL,
|
||||
flags, msg, err);
|
||||
}
|
||||
|
||||
int update_ref(const char *action, const char *refname,
|
||||
@ -3715,8 +3713,8 @@ int update_ref(const char *action, const char *refname,
|
||||
|
||||
t = ref_transaction_begin(&err);
|
||||
if (!t ||
|
||||
ref_transaction_update(t, refname, sha1, oldval, flags,
|
||||
!!oldval, action, &err) ||
|
||||
ref_transaction_update(t, refname, sha1, oldval,
|
||||
flags, action, &err) ||
|
||||
ref_transaction_commit(t, &err)) {
|
||||
const char *str = "update_ref failed for ref '%s': %s";
|
||||
|
||||
|
Reference in New Issue
Block a user