refs.c: add a strbuf argument to ref_transaction_commit for error logging

Add a strbuf argument to _commit so that we can pass an error string back to the caller. So that we can do error logging from the caller instead of from _commit. Longer term plan is to first convert all callers to use onerr==QUIET_ON_ERR and craft any log messages from the callers themselves and finally remove the onerr argument completely. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu>

Ronnie Sahlberg committed Jun 20, 2014 at 07:42 UTC 995f8746bc421a537e12622770a90be2205cd26f
3 files changed +10 -3
builtin/update-ref.c
+1 -1
@@ -367,7 +367,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
367 if (end_null)
368 line_termination = '\0';
369 update_refs_stdin();
370 - ret = ref_transaction_commit(transaction, msg,
370 + ret = ref_transaction_commit(transaction, msg, NULL,
371 UPDATE_REFS_DIE_ON_ERR);
372 ref_transaction_free(transaction);
373 return ret;
refs.c
+5 -1
@@ -3444,7 +3444,8 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
3444 }
3445
3446 int ref_transaction_commit(struct ref_transaction *transaction,
3447 - const char *msg, enum action_on_err onerr)
3447 + const char *msg, struct strbuf *err,
3448 + enum action_on_err onerr)
3449 {
3450 int ret = 0, delnum = 0, i;
3451 const char **delnames;
@@ -3473,6 +3474,9 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3474 update->flags,
3475 &update->type, onerr);
3476 if (!update->lock) {
3477 + if (err)
3478 + strbuf_addf(err, "Cannot lock the ref '%s'.",
3479 + update->refname);
3480 ret = 1;
3481 goto cleanup;
3482 }
refs.h
+4 -1
@@ -269,9 +269,12 @@ void ref_transaction_delete(struct ref_transaction *transaction,
269 * Commit all of the changes that have been queued in transaction, as
270 * atomically as possible. Return a nonzero value if there is a
271 * problem.
272 + * If err is non-NULL we will add an error string to it to explain why
273 + * the transaction failed. The string does not end in newline.
274 */
275 int ref_transaction_commit(struct ref_transaction *transaction,
274 - const char *msg, enum action_on_err onerr);
276 + const char *msg, struct strbuf *err,
277 + enum action_on_err onerr);
278
279 /*
280 * Free an existing transaction and all associated data.