Thread (14 messages) flat view 14 messages, 1 author, 2016-06-15
STALE3733d

Revision v2 of 3 in this series.

Revisions (3)
  1. v1 [diff vs current]
  2. v2 current
  3. v3 [diff vs current]

[PATCH v2 02/13] refs.c: use a single exit path from transaction commit and handle onerr

From: Ronnie Sahlberg <hidden>
Date: 2016-06-15 23:00:45
Subsystem: the rest · Maintainer: Linus Torvalds

Update ref_transaction_commit to have a single exit path and process onerr
if an error occured during hte commit. This does mean that in case of an error
occuring for UPDATE_REFS_MSG_ON_ERR during the calls to update_ref_lock or
update_ref_write we will log errors from both those functions as well as a
generic message from ref_transaction_commit.

I thought a while to make the MSG_ON_ERR message in ref_transaction_commit
conditional to only trigger if the error was not triggered by the two functions
we call that also take onerr, and which would already have logger an error
already for this case, but the code would just look too awful. I think it
is acceptable to log two error messages for those two cases than to badify
the commit code.

Signed-off-by: Ronnie Sahlberg <redacted>
---
 refs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/refs.c b/refs.c
index 138ab70..9daf89e 100644
--- a/refs.c
+++ b/refs.c
@@ -3414,12 +3414,12 @@ int ref_transaction_commit(struct ref_transaction *transaction,
 			   const char *msg, enum action_on_err onerr)
 {
 	int ret = 0, delnum = 0, i;
-	const char **delnames;
+	const char **delnames = NULL;
 	int n = transaction->nr;
 	struct ref_update **updates = transaction->updates;
 
 	if (!n)
-		return 0;
+		goto cleanup;
 
 	/* Allocate work space */
 	delnames = xmalloc(sizeof(*delnames) * n);
@@ -3481,6 +3481,14 @@ cleanup:
 			unlock_ref(updates[i]->lock);
 	free(delnames);
 	ref_transaction_free(transaction);
+	if (ret) {
+		const char *str = "Cannot commit transaction.";
+		switch (onerr) {
+		case UPDATE_REFS_MSG_ON_ERR: error(str); break;
+		case UPDATE_REFS_DIE_ON_ERR: die(str); break;
+		case UPDATE_REFS_QUIET_ON_ERR: break;
+		}
+	}
 	return ret;
 }
 
-- 
1.9.1.515.g3b87021
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help