struct ref_lock: delete the force_write member

Instead, compute the value when it is needed. Signed-off-by: Stefan Beller <sbeller@google.com> Edited-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Mar 3, 2015 at 12:43 UTC 5a6f47077b31be45bfadd6cef3b8b1a79ad57de5
1 file changed +9 -5
refs.c
+9 -5
@@ -12,7 +12,6 @@ struct ref_lock {
12 struct lock_file *lk;
13 unsigned char old_sha1[20];
14 int lock_fd;
15 - int force_write;
15 };
16
17 /*
@@ -2319,8 +2318,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2318 lock->ref_name = xstrdup(refname);
2319 lock->orig_ref_name = xstrdup(orig_refname);
2320 ref_file = git_path("%s", refname);
2322 - if ((flags & REF_NODEREF) && (type & REF_ISSYMREF))
2323 - lock->force_write = 1;
2321
2322 retry:
2323 switch (safe_create_leading_directories(ref_file)) {
@@ -3788,8 +3785,15 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3785 struct ref_update *update = updates[i];
3786
3787 if (!is_null_sha1(update->new_sha1)) {
3791 - if (!update->lock->force_write &&
3792 - !hashcmp(update->lock->old_sha1, update->new_sha1)) {
3788 + int overwriting_symref = ((update->type & REF_ISSYMREF) &&
3789 + (update->flags & REF_NODEREF));
3790 +
3791 + if (!overwriting_symref
3792 + && !hashcmp(update->lock->old_sha1, update->new_sha1)) {
3793 + /*
3794 + * The reference already has the desired
3795 + * value, so we don't need to write it.
3796 + */
3797 unlock_ref(update->lock);
3798 update->lock = NULL;
3799 } else if (write_ref_sha1(update->lock, update->new_sha1,