[PATCH 15/31] refs.c: lock the ref during _update instead of during _commit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]