Skip to content

Commit 8df4e51

Browse files
mhaggergitster
authored andcommitted
struct ref_update: move "have_old" into "flags"
Instead of having a separate have_old field, record this boolean value as a bit in the "flags" field. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fec14ec commit 8df4e51

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

refs.c

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ static unsigned char refname_disposition[256] = {
4141
#define REF_DELETING 0x02
4242

4343
/*
44-
* Used as a flag to ref_transaction_delete when a loose ref is being
44+
* Used as a flag in ref_update::flags when a loose ref is being
4545
* pruned.
4646
*/
4747
#define REF_ISPRUNING 0x04
4848

49+
/*
50+
* Used as a flag in ref_update::flags when old_sha1 should be
51+
* checked.
52+
*/
53+
#define REF_HAVE_OLD 0x08
54+
4955
/*
5056
* Try to read one refname component from the front of refname.
5157
* Return the length of the component found, or -1 if the component is
@@ -3563,16 +3569,20 @@ int for_each_reflog(each_ref_fn fn, void *cb_data)
35633569
}
35643570

35653571
/**
3566-
* Information needed for a single ref update. Set new_sha1 to the
3567-
* new value or to zero to delete the ref. To check the old value
3568-
* while locking the ref, set have_old to 1 and set old_sha1 to the
3569-
* value or to zero to ensure the ref does not exist before update.
3572+
* Information needed for a single ref update. Set new_sha1 to the new
3573+
* value or to null_sha1 to delete the ref. To check the old value
3574+
* while the ref is locked, set (flags & REF_HAVE_OLD) and set
3575+
* old_sha1 to the old value, or to null_sha1 to ensure the ref does
3576+
* not exist before update.
35703577
*/
35713578
struct ref_update {
35723579
unsigned char new_sha1[20];
35733580
unsigned char old_sha1[20];
3574-
unsigned int flags; /* REF_NODEREF? */
3575-
int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
3581+
/*
3582+
* One or more of REF_HAVE_OLD, REF_NODEREF,
3583+
* REF_DELETING, and REF_ISPRUNING:
3584+
*/
3585+
unsigned int flags;
35763586
struct ref_lock *lock;
35773587
int type;
35783588
char *msg;
@@ -3666,10 +3676,11 @@ int ref_transaction_update(struct ref_transaction *transaction,
36663676

36673677
update = add_update(transaction, refname);
36683678
hashcpy(update->new_sha1, new_sha1);
3669-
update->flags = flags;
3670-
update->have_old = have_old;
3671-
if (have_old)
3679+
if (have_old) {
36723680
hashcpy(update->old_sha1, old_sha1);
3681+
flags |= REF_HAVE_OLD;
3682+
}
3683+
update->flags = flags;
36733684
if (msg)
36743685
update->msg = xstrdup(msg);
36753686
return 0;
@@ -3785,13 +3796,13 @@ int ref_transaction_commit(struct ref_transaction *transaction,
37853796

37863797
if (is_null_sha1(update->new_sha1))
37873798
flags |= REF_DELETING;
3788-
update->lock = lock_ref_sha1_basic(update->refname,
3789-
(update->have_old ?
3790-
update->old_sha1 :
3791-
NULL),
3792-
NULL,
3793-
flags,
3794-
&update->type);
3799+
update->lock = lock_ref_sha1_basic(
3800+
update->refname,
3801+
((update->flags & REF_HAVE_OLD) ?
3802+
update->old_sha1 : NULL),
3803+
NULL,
3804+
flags,
3805+
&update->type);
37953806
if (!update->lock) {
37963807
ret = (errno == ENOTDIR)
37973808
? TRANSACTION_NAME_CONFLICT

0 commit comments

Comments
 (0)