update-ref: use err argument to get error from ref_transaction_commit

Call ref_transaction_commit with QUIET_ON_ERR and use the strbuf that is returned to print a log message if/after the transaction fails. 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 8bcd37482e95b47119f3a8f03a1c8ce5815594a3
1 file changed +5 -5
builtin/update-ref.c
+5 -5
@@ -342,6 +342,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
342 const char *refname, *oldval, *msg = NULL;
343 unsigned char sha1[20], oldsha1[20];
344 int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0, flags = 0;
345 + struct strbuf err = STRBUF_INIT;
346 struct option options[] = {
347 OPT_STRING( 'm', NULL, &msg, N_("reason"), N_("reason of the update")),
348 OPT_BOOL('d', NULL, &delete, N_("delete the reference")),
@@ -359,18 +360,17 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
360 die("Refusing to perform update with empty message.");
361
362 if (read_stdin) {
362 - int ret;
363 transaction = ref_transaction_begin();
364 -
364 if (delete || no_deref || argc > 0)
365 usage_with_options(git_update_ref_usage, options);
366 if (end_null)
367 line_termination = '\0';
368 update_refs_stdin();
370 - ret = ref_transaction_commit(transaction, msg, NULL,
371 - UPDATE_REFS_DIE_ON_ERR);
369 + if (ref_transaction_commit(transaction, msg, &err,
370 + UPDATE_REFS_QUIET_ON_ERR))
371 + die("%s", err.buf);
372 ref_transaction_free(transaction);
373 - return ret;
373 + return 0;
374 }
375
376 if (end_null)