[PATCH 15/31] refs.c: lock the ref during _update instead of during _commit
- From
Ronnie Sahlberg <sahlberg@google.com>
- Date
- May 14, 2014, 22:13 UTC
- Message-ID
- <1400105610-21194-16-git-send-email-sahlberg@google.com>
- In-Reply-To
- <1400105610-21194-1-git-send-email-sahlberg@google.com>
Try to lock the ref during the transaction update instead of later during the commit phase. This allows us to do things such as :
t = transaction_begin() transaction_update_sha1(t, ref, ...) /* locking ref */ ... do stuff while we know that ref is locked ... transaction_commit(t)
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> --- refs.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/refs.c b/refs.c index 8212d77..b006238 100644 --- a/refs.c +++ b/refs.c @@ -3438,6 +3438,16 @@ int transaction_update_sha1(struct ref_transaction *transaction, */ if (update->flags & REF_ISPACKONLY) add_delname(transaction, update->refname); + else { + update->lock = lock_ref_sha1_basic(update->refname, + (update->have_old ? + update->old_sha1 : + NULL), + update->flags, + &update->type, + transaction->delnames, + transaction->delnum); + } return 0; } @@ -3566,14 +3576,6 @@ int transaction_commit(struct ref_transaction *transaction, if (update->flags & REF_ISPACKONLY) continue; - update->lock = lock_ref_sha1_basic(update->refname, - (update->have_old ? - update->old_sha1 : - NULL), - update->flags, - &update->type, - transaction->delnames, - transaction->delnum); if (!update->lock) { if (err) strbuf_addf(err, "Cannot lock the ref '%s'.",
-- 2.0.0.rc3.506.g3739a35