summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2016-02-24 17:58:48 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-25 16:01:02 -0800
commit6fc85f781d366229d421e81888e4ce7bf0bc688f (patch)
tree3dce273c9366607e2576b68f59ebfa53f135d6b3
parentfe4e79996af79e125ba70a1e9bea099b54dd4570 (diff)
downloadgit-6fc85f781d366229d421e81888e4ce7bf0bc688f.tar.gz
refs: make lock generic
Instead of using a files-backend-specific struct ref_lock, the generic ref_transaction struct should provide a void pointer that backends can use for their own lock data. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--refs/files-backend.c29
-rw-r--r--refs/refs-internal.h2
2 files changed, 17 insertions, 14 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 6554079d4e..3aa6ba7e72 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3074,11 +3074,12 @@ static int files_transaction_commit(struct ref_transaction *transaction,
*/
for (i = 0; i < n; i++) {
struct ref_update *update = updates[i];
+ struct ref_lock *lock;
if ((update->flags & REF_HAVE_NEW) &&
is_null_sha1(update->new_sha1))
update->flags |= REF_DELETING;
- update->lock = lock_ref_sha1_basic(
+ lock = lock_ref_sha1_basic(
update->refname,
((update->flags & REF_HAVE_OLD) ?
update->old_sha1 : NULL),
@@ -3086,7 +3087,8 @@ static int files_transaction_commit(struct ref_transaction *transaction,
update->flags,
&update->type,
err);
- if (!update->lock) {
+ update->backend_data = lock;
+ if (!lock) {
char *reason;
ret = (errno == ENOTDIR)
@@ -3104,12 +3106,12 @@ static int files_transaction_commit(struct ref_transaction *transaction,
(update->flags & REF_NODEREF));
if (!overwriting_symref &&
- !hashcmp(update->lock->old_oid.hash, update->new_sha1)) {
+ !hashcmp(lock->old_oid.hash, update->new_sha1)) {
/*
* The reference already has the desired
* value, so we don't need to write it.
*/
- } else if (write_ref_to_lockfile(update->lock,
+ } else if (write_ref_to_lockfile(lock,
update->new_sha1,
err)) {
char *write_err = strbuf_detach(err, NULL);
@@ -3118,7 +3120,7 @@ static int files_transaction_commit(struct ref_transaction *transaction,
* The lock was freed upon failure of
* write_ref_to_lockfile():
*/
- update->lock = NULL;
+ update->backend_data = NULL;
strbuf_addf(err,
"cannot update the ref '%s': %s",
update->refname, write_err);
@@ -3134,7 +3136,7 @@ static int files_transaction_commit(struct ref_transaction *transaction,
* We didn't have to write anything to the lockfile.
* Close it to free up the file descriptor:
*/
- if (close_ref(update->lock)) {
+ if (close_ref(lock)) {
strbuf_addf(err, "Couldn't close %s.lock",
update->refname);
goto cleanup;
@@ -3147,16 +3149,16 @@ static int files_transaction_commit(struct ref_transaction *transaction,
struct ref_update *update = updates[i];
if (update->flags & REF_NEEDS_COMMIT) {
- if (commit_ref_update(update->lock,
+ if (commit_ref_update(update->backend_data,
update->new_sha1, update->msg,
update->flags, err)) {
/* freed by commit_ref_update(): */
- update->lock = NULL;
+ update->backend_data = NULL;
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
} else {
/* freed by commit_ref_update(): */
- update->lock = NULL;
+ update->backend_data = NULL;
}
}
}
@@ -3164,16 +3166,17 @@ static int files_transaction_commit(struct ref_transaction *transaction,
/* Perform deletes now that updates are safely completed */
for (i = 0; i < n; i++) {
struct ref_update *update = updates[i];
+ struct ref_lock *lock = update->backend_data;
if (update->flags & REF_DELETING) {
- if (delete_ref_loose(update->lock, update->type, err)) {
+ if (delete_ref_loose(lock, update->type, err)) {
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
}
if (!(update->flags & REF_ISPRUNING))
string_list_append(&refs_to_delete,
- update->lock->ref_name);
+ lock->ref_name);
}
}
@@ -3189,8 +3192,8 @@ cleanup:
transaction->state = REF_TRANSACTION_CLOSED;
for (i = 0; i < n; i++)
- if (updates[i]->lock)
- unlock_ref(updates[i]->lock);
+ if (updates[i]->backend_data)
+ unlock_ref(updates[i]->backend_data);
string_list_clear(&refs_to_delete, 0);
string_list_clear(&affected_refnames, 0);
return ret;
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index d6fe1994db..8d091cbfc7 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -144,7 +144,7 @@ struct ref_update {
* REF_DELETING, and REF_ISPRUNING:
*/
unsigned int flags;
- struct ref_lock *lock;
+ void *backend_data;
int type;
char *msg;
const char refname[FLEX_ARRAY];