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>
This commit is contained in:

committed by
Junio C Hamano

parent
9b6b40d93a
commit
7d61826439
@ -3520,9 +3520,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||||||
|
|
||||||
ret = lock_raw_ref(refs, update->refname, mustexist,
|
ret = lock_raw_ref(refs, update->refname, mustexist,
|
||||||
affected_refnames, NULL,
|
affected_refnames, NULL,
|
||||||
&update->lock, &referent,
|
&lock, &referent,
|
||||||
&update->type, err);
|
&update->type, err);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
char *reason;
|
char *reason;
|
||||||
|
|
||||||
@ -3533,7 +3532,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock = update->lock;
|
update->backend_data = lock;
|
||||||
|
|
||||||
if (update->type & REF_ISSYMREF) {
|
if (update->type & REF_ISSYMREF) {
|
||||||
if (update->flags & REF_NODEREF) {
|
if (update->flags & REF_NODEREF) {
|
||||||
@ -3589,7 +3588,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||||||
for (parent_update = update->parent_update;
|
for (parent_update = update->parent_update;
|
||||||
parent_update;
|
parent_update;
|
||||||
parent_update = parent_update->parent_update) {
|
parent_update = parent_update->parent_update) {
|
||||||
oidcpy(&parent_update->lock->old_oid, &lock->old_oid);
|
struct ref_lock *parent_lock = parent_update->backend_data;
|
||||||
|
oidcpy(&parent_lock->old_oid, &lock->old_oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((update->flags & REF_HAVE_OLD) &&
|
if ((update->flags & REF_HAVE_OLD) &&
|
||||||
@ -3624,7 +3624,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||||||
* The lock was freed upon failure of
|
* The lock was freed upon failure of
|
||||||
* write_ref_to_lockfile():
|
* write_ref_to_lockfile():
|
||||||
*/
|
*/
|
||||||
update->lock = NULL;
|
update->backend_data = NULL;
|
||||||
strbuf_addf(err,
|
strbuf_addf(err,
|
||||||
"cannot update the ref '%s': %s",
|
"cannot update the ref '%s': %s",
|
||||||
update->refname, write_err);
|
update->refname, write_err);
|
||||||
@ -3742,7 +3742,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
|
|||||||
/* Perform updates first so live commits remain referenced */
|
/* Perform updates first so live commits remain referenced */
|
||||||
for (i = 0; i < transaction->nr; i++) {
|
for (i = 0; i < transaction->nr; i++) {
|
||||||
struct ref_update *update = transaction->updates[i];
|
struct ref_update *update = transaction->updates[i];
|
||||||
struct ref_lock *lock = update->lock;
|
struct ref_lock *lock = update->backend_data;
|
||||||
|
|
||||||
if (update->flags & REF_NEEDS_COMMIT ||
|
if (update->flags & REF_NEEDS_COMMIT ||
|
||||||
update->flags & REF_LOG_ONLY) {
|
update->flags & REF_LOG_ONLY) {
|
||||||
@ -3755,7 +3755,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
|
|||||||
lock->ref_name, old_msg);
|
lock->ref_name, old_msg);
|
||||||
free(old_msg);
|
free(old_msg);
|
||||||
unlock_ref(lock);
|
unlock_ref(lock);
|
||||||
update->lock = NULL;
|
update->backend_data = NULL;
|
||||||
ret = TRANSACTION_GENERIC_ERROR;
|
ret = TRANSACTION_GENERIC_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -3765,7 +3765,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
|
|||||||
if (commit_ref(lock)) {
|
if (commit_ref(lock)) {
|
||||||
strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
|
strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
|
||||||
unlock_ref(lock);
|
unlock_ref(lock);
|
||||||
update->lock = NULL;
|
update->backend_data = NULL;
|
||||||
ret = TRANSACTION_GENERIC_ERROR;
|
ret = TRANSACTION_GENERIC_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -3774,17 +3774,18 @@ static int files_transaction_commit(struct ref_store *ref_store,
|
|||||||
/* Perform deletes now that updates are safely completed */
|
/* Perform deletes now that updates are safely completed */
|
||||||
for (i = 0; i < transaction->nr; i++) {
|
for (i = 0; i < transaction->nr; i++) {
|
||||||
struct ref_update *update = transaction->updates[i];
|
struct ref_update *update = transaction->updates[i];
|
||||||
|
struct ref_lock *lock = update->backend_data;
|
||||||
|
|
||||||
if (update->flags & REF_DELETING &&
|
if (update->flags & REF_DELETING &&
|
||||||
!(update->flags & REF_LOG_ONLY)) {
|
!(update->flags & REF_LOG_ONLY)) {
|
||||||
if (delete_ref_loose(update->lock, update->type, err)) {
|
if (delete_ref_loose(lock, update->type, err)) {
|
||||||
ret = TRANSACTION_GENERIC_ERROR;
|
ret = TRANSACTION_GENERIC_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(update->flags & REF_ISPRUNING))
|
if (!(update->flags & REF_ISPRUNING))
|
||||||
string_list_append(&refs_to_delete,
|
string_list_append(&refs_to_delete,
|
||||||
update->lock->ref_name);
|
lock->ref_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3800,8 +3801,8 @@ cleanup:
|
|||||||
transaction->state = REF_TRANSACTION_CLOSED;
|
transaction->state = REF_TRANSACTION_CLOSED;
|
||||||
|
|
||||||
for (i = 0; i < transaction->nr; i++)
|
for (i = 0; i < transaction->nr; i++)
|
||||||
if (transaction->updates[i]->lock)
|
if (transaction->updates[i]->backend_data)
|
||||||
unlock_ref(transaction->updates[i]->lock);
|
unlock_ref(transaction->updates[i]->backend_data);
|
||||||
string_list_clear(&refs_to_delete, 0);
|
string_list_clear(&refs_to_delete, 0);
|
||||||
free(head_ref);
|
free(head_ref);
|
||||||
string_list_clear(&affected_refnames, 0);
|
string_list_clear(&affected_refnames, 0);
|
||||||
|
@ -162,7 +162,7 @@ struct ref_update {
|
|||||||
*/
|
*/
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
|
||||||
struct ref_lock *lock;
|
void *backend_data;
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
char *msg;
|
char *msg;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user