Thread (134 messages) flat view 134 messages, 4 authors, 2016-06-15

Re: [PATCH v8 10/44] refs.c: change ref_transaction_update() to do error checking and return status

From: Jonathan Nieder <hidden>
Date: 2016-06-15 23:01:11

Ronnie Sahlberg wrote:
Update ref_transaction_update() do some basic error checking and return
non-zero on error. Update all callers to check ref_transaction_update() for
error. There are currently no conditions in _update that will return error but
there will be in the future.
Probably worth passing a 'struct strbuf *err' argument.  Then callers
can do

		die("%s", err.buf);

and the error message can say which ref and whether we were trying to
create a ref, or delete one, or whatever.
quoted hunk ↗ jump to hunk
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -197,8 +197,9 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next)
 	if (*next != line_termination)
 		die("update %s: extra input: %s", refname, next);
 
-	ref_transaction_update(transaction, refname, new_sha1, old_sha1,
-			       update_flags, have_old);
+	if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
+				   update_flags, have_old))
+		die("update %s: failed", refname);
This could say

		die("update %s: %s", refname, err.buf);

to give context about which command it was trying to execute.

[...]
quoted hunk ↗ jump to hunk
@@ -286,8 +287,9 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next)
 	if (*next != line_termination)
 		die("verify %s: extra input: %s", refname, next);
 
-	ref_transaction_update(transaction, refname, new_sha1, old_sha1,
-			       update_flags, have_old);
+	if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
+				   update_flags, have_old))
+		die("failed transaction update for %s", refname);
And this could say

		die("verify %s: %s", refname, err.buf);

[...]
quoted hunk ↗ jump to hunk
--- a/refs.h
+++ b/refs.h
@@ -242,12 +242,15 @@ void ref_transaction_rollback(struct ref_transaction *transaction);
  * be deleted.  If have_old is true, then old_sha1 holds the value
  * that the reference should have had before the update, or zeros if
  * it must not have existed beforehand.
+ * Function returns 0 on success and non-zero on failure. A failure to update
+ * means that the transaction as a whole has failed and will need to be
+ * rolled back.
+ */
Thanks for this documentation.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help