Skip to content

Commit fb5a6bb

Browse files
mhaggergitster
authored andcommitted
ref_transaction_delete(): remove "have_old" parameter
Instead, verify the reference's old value if and only if old_sha1 is non-NULL. Signed-off-by: Michael Haggerty <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d147bd commit fb5a6bb

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

builtin/receive-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
953953
if (ref_transaction_delete(transaction,
954954
namespaced_name,
955955
old_sha1,
956-
0, old_sha1 != NULL,
957-
"push", &err)) {
956+
0, "push", &err)) {
958957
rp_error("%s", err.buf);
959958
strbuf_release(&err);
960959
return "failed to delete";

builtin/update-ref.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
265265
if (*next != line_termination)
266266
die("delete %s: extra input: %s", refname, next);
267267

268-
if (ref_transaction_delete(transaction, refname, old_sha1,
269-
update_flags, have_old, msg, &err))
268+
if (ref_transaction_delete(transaction, refname,
269+
have_old ? old_sha1 : NULL,
270+
update_flags, msg, &err))
270271
die("%s", err.buf);
271272

272273
update_flags = 0;

refs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,7 @@ static void prune_ref(struct ref_to_prune *r)
25762576
transaction = ref_transaction_begin(&err);
25772577
if (!transaction ||
25782578
ref_transaction_delete(transaction, r->name, r->sha1,
2579-
REF_ISPRUNING, 1, NULL, &err) ||
2579+
REF_ISPRUNING, NULL, &err) ||
25802580
ref_transaction_commit(transaction, &err)) {
25812581
ref_transaction_free(transaction);
25822582
error("%s", err.buf);
@@ -2753,8 +2753,9 @@ int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flag
27532753

27542754
transaction = ref_transaction_begin(&err);
27552755
if (!transaction ||
2756-
ref_transaction_delete(transaction, refname, sha1, flags,
2757-
sha1 && !is_null_sha1(sha1), NULL, &err) ||
2756+
ref_transaction_delete(transaction, refname,
2757+
(sha1 && !is_null_sha1(sha1)) ? sha1 : NULL,
2758+
flags, NULL, &err) ||
27582759
ref_transaction_commit(transaction, &err)) {
27592760
error("%s", err.buf);
27602761
ref_transaction_free(transaction);
@@ -3696,11 +3697,11 @@ int ref_transaction_create(struct ref_transaction *transaction,
36963697
int ref_transaction_delete(struct ref_transaction *transaction,
36973698
const char *refname,
36983699
const unsigned char *old_sha1,
3699-
unsigned int flags, int have_old, const char *msg,
3700+
unsigned int flags, const char *msg,
37003701
struct strbuf *err)
37013702
{
37023703
return ref_transaction_update(transaction, refname,
3703-
null_sha1, have_old ? old_sha1 : NULL,
3704+
null_sha1, old_sha1,
37043705
flags, msg, err);
37053706
}
37063707

refs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ int ref_transaction_create(struct ref_transaction *transaction,
295295
struct strbuf *err);
296296

297297
/*
298-
* Add a reference deletion to transaction. If have_old is true, then
299-
* old_sha1 holds the value that the reference should have had before
298+
* Add a reference deletion to transaction. If old_sha1 is non-NULL, then
299+
* it holds the value that the reference should have had before
300300
* the update (which must not be the null SHA-1).
301301
* Function returns 0 on success and non-zero on failure. A failure to delete
302302
* means that the transaction as a whole has failed and will need to be
@@ -305,7 +305,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
305305
int ref_transaction_delete(struct ref_transaction *transaction,
306306
const char *refname,
307307
const unsigned char *old_sha1,
308-
unsigned int flags, int have_old, const char *msg,
308+
unsigned int flags, const char *msg,
309309
struct strbuf *err);
310310

311311
/*

0 commit comments

Comments
 (0)