@@ -41,11 +41,17 @@ static unsigned char refname_disposition[256] = {
41
41
#define REF_DELETING 0x02
42
42
43
43
/*
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
45
45
* pruned.
46
46
*/
47
47
#define REF_ISPRUNING 0x04
48
48
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
+
49
55
/*
50
56
* Try to read one refname component from the front of refname.
51
57
* 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)
3563
3569
}
3564
3570
3565
3571
/**
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.
3570
3577
*/
3571
3578
struct ref_update {
3572
3579
unsigned char new_sha1 [20 ];
3573
3580
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 ;
3576
3586
struct ref_lock * lock ;
3577
3587
int type ;
3578
3588
char * msg ;
@@ -3666,10 +3676,11 @@ int ref_transaction_update(struct ref_transaction *transaction,
3666
3676
3667
3677
update = add_update (transaction , refname );
3668
3678
hashcpy (update -> new_sha1 , new_sha1 );
3669
- update -> flags = flags ;
3670
- update -> have_old = have_old ;
3671
- if (have_old )
3679
+ if (have_old ) {
3672
3680
hashcpy (update -> old_sha1 , old_sha1 );
3681
+ flags |= REF_HAVE_OLD ;
3682
+ }
3683
+ update -> flags = flags ;
3673
3684
if (msg )
3674
3685
update -> msg = xstrdup (msg );
3675
3686
return 0 ;
@@ -3785,13 +3796,13 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3785
3796
3786
3797
if (is_null_sha1 (update -> new_sha1 ))
3787
3798
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 );
3795
3806
if (!update -> lock ) {
3796
3807
ret = (errno == ENOTDIR )
3797
3808
? TRANSACTION_NAME_CONFLICT
0 commit comments