Skip to content

Commit 1d147bd

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8df4e51 commit 1d147bd

12 files changed

+31
-29
lines changed

branch.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ void create_branch(const char *head,
284284

285285
transaction = ref_transaction_begin(&err);
286286
if (!transaction ||
287-
ref_transaction_update(transaction, ref.buf, sha1,
288-
null_sha1, 0, !forcing, msg, &err) ||
287+
ref_transaction_update(transaction, ref.buf,
288+
sha1, forcing ? NULL : null_sha1,
289+
0, msg, &err) ||
289290
ref_transaction_commit(transaction, &err))
290291
die("%s", err.buf);
291292
ref_transaction_free(transaction);

builtin/commit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17671767
ref_transaction_update(transaction, "HEAD", sha1,
17681768
current_head
17691769
? current_head->object.sha1 : NULL,
1770-
0, !!current_head, sb.buf, &err) ||
1770+
0, sb.buf, &err) ||
17711771
ref_transaction_commit(transaction, &err)) {
17721772
rollback_index_files();
17731773
die("%s", err.buf);

builtin/fetch.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ static int s_update_ref(const char *action,
416416

417417
transaction = ref_transaction_begin(&err);
418418
if (!transaction ||
419-
ref_transaction_update(transaction, ref->name, ref->new_sha1,
420-
ref->old_sha1, 0, check_old, msg, &err))
419+
ref_transaction_update(transaction, ref->name,
420+
ref->new_sha1,
421+
check_old ? ref->old_sha1 : NULL,
422+
0, msg, &err))
421423
goto fail;
422424

423425
ret = ref_transaction_commit(transaction, &err);

builtin/receive-pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
971971
if (ref_transaction_update(transaction,
972972
namespaced_name,
973973
new_sha1, old_sha1,
974-
0, 1, "push",
974+
0, "push",
975975
&err)) {
976976
rp_error("%s", err.buf);
977977
strbuf_release(&err);

builtin/replace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int replace_object_sha1(const char *object_ref,
172172
transaction = ref_transaction_begin(&err);
173173
if (!transaction ||
174174
ref_transaction_update(transaction, ref, repl, prev,
175-
0, 1, NULL, &err) ||
175+
0, NULL, &err) ||
176176
ref_transaction_commit(transaction, &err))
177177
die("%s", err.buf);
178178

builtin/tag.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
733733
transaction = ref_transaction_begin(&err);
734734
if (!transaction ||
735735
ref_transaction_update(transaction, ref.buf, object, prev,
736-
0, 1, NULL, &err) ||
736+
0, NULL, &err) ||
737737
ref_transaction_commit(transaction, &err))
738738
die("%s", err.buf);
739739
ref_transaction_free(transaction);

builtin/update-ref.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
198198
if (*next != line_termination)
199199
die("update %s: extra input: %s", refname, next);
200200

201-
if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
202-
update_flags, have_old, msg, &err))
201+
if (ref_transaction_update(transaction, refname,
202+
new_sha1, have_old ? old_sha1 : NULL,
203+
update_flags, msg, &err))
203204
die("%s", err.buf);
204205

205206
update_flags = 0;
@@ -297,7 +298,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
297298
die("verify %s: extra input: %s", refname, next);
298299

299300
if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
300-
update_flags, 1, msg, &err))
301+
update_flags, msg, &err))
301302
die("%s", err.buf);
302303

303304
update_flags = 0;

fast-import.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ static int update_branch(struct branch *b)
17161716
transaction = ref_transaction_begin(&err);
17171717
if (!transaction ||
17181718
ref_transaction_update(transaction, b->name, b->sha1, old_sha1,
1719-
0, 1, msg, &err) ||
1719+
0, msg, &err) ||
17201720
ref_transaction_commit(transaction, &err)) {
17211721
ref_transaction_free(transaction);
17221722
error("%s", err.buf);
@@ -1756,8 +1756,8 @@ static void dump_tags(void)
17561756
strbuf_reset(&ref_name);
17571757
strbuf_addf(&ref_name, "refs/tags/%s", t->name);
17581758

1759-
if (ref_transaction_update(transaction, ref_name.buf, t->sha1,
1760-
NULL, 0, 0, msg, &err)) {
1759+
if (ref_transaction_update(transaction, ref_name.buf,
1760+
t->sha1, NULL, 0, msg, &err)) {
17611761
failure |= error("%s", err.buf);
17621762
goto cleanup;
17631763
}

refs.c

+8-10
Original file line numberDiff line numberDiff line change
@@ -3654,7 +3654,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
36543654
const char *refname,
36553655
const unsigned char *new_sha1,
36563656
const unsigned char *old_sha1,
3657-
unsigned int flags, int have_old, const char *msg,
3657+
unsigned int flags, const char *msg,
36583658
struct strbuf *err)
36593659
{
36603660
struct ref_update *update;
@@ -3664,9 +3664,6 @@ int ref_transaction_update(struct ref_transaction *transaction,
36643664
if (transaction->state != REF_TRANSACTION_OPEN)
36653665
die("BUG: update called for transaction that is not open");
36663666

3667-
if (have_old && !old_sha1)
3668-
die("BUG: have_old is true but old_sha1 is NULL");
3669-
36703667
if (!is_null_sha1(new_sha1) &&
36713668
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
36723669
strbuf_addf(err, "refusing to update ref with bad name %s",
@@ -3676,7 +3673,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
36763673

36773674
update = add_update(transaction, refname);
36783675
hashcpy(update->new_sha1, new_sha1);
3679-
if (have_old) {
3676+
if (old_sha1) {
36803677
hashcpy(update->old_sha1, old_sha1);
36813678
flags |= REF_HAVE_OLD;
36823679
}
@@ -3693,7 +3690,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
36933690
struct strbuf *err)
36943691
{
36953692
return ref_transaction_update(transaction, refname, new_sha1,
3696-
null_sha1, flags, 1, msg, err);
3693+
null_sha1, flags, msg, err);
36973694
}
36983695

36993696
int ref_transaction_delete(struct ref_transaction *transaction,
@@ -3702,8 +3699,9 @@ int ref_transaction_delete(struct ref_transaction *transaction,
37023699
unsigned int flags, int have_old, const char *msg,
37033700
struct strbuf *err)
37043701
{
3705-
return ref_transaction_update(transaction, refname, null_sha1,
3706-
old_sha1, flags, have_old, msg, err);
3702+
return ref_transaction_update(transaction, refname,
3703+
null_sha1, have_old ? old_sha1 : NULL,
3704+
flags, msg, err);
37073705
}
37083706

37093707
int update_ref(const char *action, const char *refname,
@@ -3715,8 +3713,8 @@ int update_ref(const char *action, const char *refname,
37153713

37163714
t = ref_transaction_begin(&err);
37173715
if (!t ||
3718-
ref_transaction_update(t, refname, sha1, oldval, flags,
3719-
!!oldval, action, &err) ||
3716+
ref_transaction_update(t, refname, sha1, oldval,
3717+
flags, action, &err) ||
37203718
ref_transaction_commit(t, &err)) {
37213719
const char *str = "update_ref failed for ref '%s': %s";
37223720

refs.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
265265
/*
266266
* Add a reference update to transaction. new_sha1 is the value that
267267
* the reference should have after the update, or null_sha1 if it should
268-
* be deleted. If have_old is true, then old_sha1 holds the value
269-
* that the reference should have had before the update, or zeros if
268+
* be deleted. If old_sha1 is non-NULL, then it is the value
269+
* that the reference should have had before the update, or null_sha1 if
270270
* it must not have existed beforehand.
271271
* Function returns 0 on success and non-zero on failure. A failure to update
272272
* means that the transaction as a whole has failed and will need to be
@@ -276,7 +276,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
276276
const char *refname,
277277
const unsigned char *new_sha1,
278278
const unsigned char *old_sha1,
279-
unsigned int flags, int have_old, const char *msg,
279+
unsigned int flags, const char *msg,
280280
struct strbuf *err);
281281

282282
/*

sequencer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
252252
if (!transaction ||
253253
ref_transaction_update(transaction, "HEAD",
254254
to, unborn ? null_sha1 : from,
255-
0, 1, sb.buf, &err) ||
255+
0, sb.buf, &err) ||
256256
ref_transaction_commit(transaction, &err)) {
257257
ref_transaction_free(transaction);
258258
error("%s", err.buf);

walker.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
299299
strbuf_reset(&refname);
300300
strbuf_addf(&refname, "refs/%s", write_ref[i]);
301301
if (ref_transaction_update(transaction, refname.buf,
302-
&sha1[20 * i], NULL, 0, 0,
302+
&sha1[20 * i], NULL, 0,
303303
msg ? msg : "fetch (unknown)",
304304
&err)) {
305305
error("%s", err.buf);

0 commit comments

Comments
 (0)