refs: make lock generic

Instead of including a files-backend-specific struct ref_lock, change the generic ref_update struct to include a void pointer that backends can use for their own arbitrary data. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed Sep 4, 2016 at 18:08 UTC 7d618264394a17e6ecd83d9412ac9ddb4609a2e5
2 files changed +14 -13
refs/files-backend.c
+13 -12
@@ -3520,9 +3520,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
3520
3521 ret = lock_raw_ref(refs, update->refname, mustexist,
3522 affected_refnames, NULL,
3523 - &update->lock, &referent,
3523 + &lock, &referent,
3524 &update->type, err);
3525 -
3525 if (ret) {
3526 char *reason;
3527
@@ -3533,7 +3532,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
3532 return ret;
3533 }
3534
3536 - lock = update->lock;
3535 + update->backend_data = lock;
3536
3537 if (update->type & REF_ISSYMREF) {
3538 if (update->flags & REF_NODEREF) {
@@ -3589,7 +3588,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
3588 for (parent_update = update->parent_update;
3589 parent_update;
3590 parent_update = parent_update->parent_update) {
3592 - oidcpy(&parent_update->lock->old_oid, &lock->old_oid);
3591 + struct ref_lock *parent_lock = parent_update->backend_data;
3592 + oidcpy(&parent_lock->old_oid, &lock->old_oid);
3593 }
3594
3595 if ((update->flags & REF_HAVE_OLD) &&
@@ -3624,7 +3624,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
3624 * The lock was freed upon failure of
3625 * write_ref_to_lockfile():
3626 */
3627 - update->lock = NULL;
3627 + update->backend_data = NULL;
3628 strbuf_addf(err,
3629 "cannot update the ref '%s': %s",
3630 update->refname, write_err);
@@ -3742,7 +3742,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
3742 /* Perform updates first so live commits remain referenced */
3743 for (i = 0; i < transaction->nr; i++) {
3744 struct ref_update *update = transaction->updates[i];
3745 - struct ref_lock *lock = update->lock;
3745 + struct ref_lock *lock = update->backend_data;
3746
3747 if (update->flags & REF_NEEDS_COMMIT ||
3748 update->flags & REF_LOG_ONLY) {
@@ -3755,7 +3755,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
3755 lock->ref_name, old_msg);
3756 free(old_msg);
3757 unlock_ref(lock);
3758 - update->lock = NULL;
3758 + update->backend_data = NULL;
3759 ret = TRANSACTION_GENERIC_ERROR;
3760 goto cleanup;
3761 }
@@ -3765,7 +3765,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
3765 if (commit_ref(lock)) {
3766 strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
3767 unlock_ref(lock);
3768 - update->lock = NULL;
3768 + update->backend_data = NULL;
3769 ret = TRANSACTION_GENERIC_ERROR;
3770 goto cleanup;
3771 }
@@ -3774,17 +3774,18 @@ static int files_transaction_commit(struct ref_store *ref_store,
3774 /* Perform deletes now that updates are safely completed */
3775 for (i = 0; i < transaction->nr; i++) {
3776 struct ref_update *update = transaction->updates[i];
3777 + struct ref_lock *lock = update->backend_data;
3778
3779 if (update->flags & REF_DELETING &&
3780 !(update->flags & REF_LOG_ONLY)) {
3780 - if (delete_ref_loose(update->lock, update->type, err)) {
3781 + if (delete_ref_loose(lock, update->type, err)) {
3782 ret = TRANSACTION_GENERIC_ERROR;
3783 goto cleanup;
3784 }
3785
3786 if (!(update->flags & REF_ISPRUNING))
3787 string_list_append(&refs_to_delete,
3787 - update->lock->ref_name);
3788 + lock->ref_name);
3789 }
3790 }
3791
@@ -3800,8 +3801,8 @@ cleanup:
3801 transaction->state = REF_TRANSACTION_CLOSED;
3802
3803 for (i = 0; i < transaction->nr; i++)
3803 - if (transaction->updates[i]->lock)
3804 - unlock_ref(transaction->updates[i]->lock);
3804 + if (transaction->updates[i]->backend_data)
3805 + unlock_ref(transaction->updates[i]->backend_data);
3806 string_list_clear(&refs_to_delete, 0);
3807 free(head_ref);
3808 string_list_clear(&affected_refnames, 0);
refs/refs-internal.h
+1 -1
@@ -162,7 +162,7 @@ struct ref_update {
162 */
163 unsigned int flags;
164
165 - struct ref_lock *lock;
165 + void *backend_data;
166 unsigned int type;
167 char *msg;
168