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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Feb 17, 2015 at 18:00 UTC
8df4e51138781927962438819d79ae3221b527b5
1 file changed
+28
-17
refs.c
+28
-17
@@ -41,11 +41,17 @@ static unsigned char refname_disposition[256] = {
41
#define REF_DELETING 0x02
42
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
* pruned.
46
*/
47
#define REF_ISPRUNING 0x04
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
+
55
/*
56
* Try to read one refname component from the front of refname.
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)
3569
}
3570
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.
3577
*/
3578
struct ref_update {
3579
unsigned char new_sha1[20];
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;
3586
struct ref_lock *lock;
3587
int type;
3588
char *msg;
@@ -3666,10 +3676,11 @@ int ref_transaction_update(struct ref_transaction *transaction,
3676
3677
update = add_update(transaction, refname);
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) {
3680
hashcpy(update->old_sha1, old_sha1);
3681
+ flags |= REF_HAVE_OLD;
3682
+ }
3683
+ update->flags = flags;
3684
if (msg)
3685
update->msg = xstrdup(msg);
3686
return 0;
@@ -3785,13 +3796,13 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3796
3797
if (is_null_sha1(update->new_sha1))
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);
3806
if (!update->lock) {
3807
ret = (errno == ENOTDIR)
3808
? TRANSACTION_NAME_CONFLICT