[PATCH v2 13/13] refs.c: change update_ref to use a transaction

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

 



Change the update_ref helper function to use a ref transaction internally.

Signed-off-by: Ronnie Sahlberg <sahlberg@xxxxxxxxxx>
---
 refs.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/refs.c b/refs.c
index 878948a..e52b6bf 100644
--- a/refs.c
+++ b/refs.c
@@ -3390,11 +3390,29 @@ int update_ref(const char *action, const char *refname,
 	       const unsigned char *sha1, const unsigned char *oldval,
 	       int flags, enum action_on_err onerr)
 {
-	struct ref_lock *lock;
-	lock = update_ref_lock(refname, oldval, flags, NULL, onerr);
-	if (!lock)
-		return 1;
-	return update_ref_write(action, refname, sha1, lock, onerr);
+	struct ref_transaction *t;
+	const char *str = "update_ref failed for ref '%s'.";
+
+	t = ref_transaction_begin();
+	if (!t)
+		goto error_return;
+	if (ref_transaction_update(t, refname, sha1, oldval, flags,
+				   !!oldval)) {
+		ref_transaction_rollback(t);
+		goto error_return;
+	}
+	if (ref_transaction_commit(t, action, onerr))
+		goto error_return;
+
+	return 0;
+
+error_return:
+	switch (onerr) {
+	case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
+	case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
+	case UPDATE_REFS_QUIET_ON_ERR: break;
+	}
+	return 1;
 }
 
 static int ref_update_compare(const void *r1, const void *r2)
-- 
1.9.1.515.g3b87021

--
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]