OSDN Git Service

refs.c: add a strbuf argument to ref_transaction_commit for error logging
authorRonnie Sahlberg <sahlberg@google.com>
Fri, 20 Jun 2014 14:42:46 +0000 (07:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jul 2014 18:54:40 +0000 (11:54 -0700)
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>
builtin/update-ref.c
refs.c
refs.h

index 1fd7a89..22617af 100644 (file)
@@ -367,7 +367,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                if (end_null)
                        line_termination = '\0';
                update_refs_stdin();
-               ret = ref_transaction_commit(transaction, msg,
+               ret = ref_transaction_commit(transaction, msg, NULL,
                                             UPDATE_REFS_DIE_ON_ERR);
                ref_transaction_free(transaction);
                return ret;
diff --git a/refs.c b/refs.c
index 1d6dece..db05602 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -3444,7 +3444,8 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
 }
 
 int ref_transaction_commit(struct ref_transaction *transaction,
-                          const char *msg, enum action_on_err onerr)
+                          const char *msg, struct strbuf *err,
+                          enum action_on_err onerr)
 {
        int ret = 0, delnum = 0, i;
        const char **delnames;
@@ -3473,6 +3474,9 @@ int ref_transaction_commit(struct ref_transaction *transaction,
                                               update->flags,
                                               &update->type, onerr);
                if (!update->lock) {
+                       if (err)
+                               strbuf_addf(err, "Cannot lock the ref '%s'.",
+                                           update->refname);
                        ret = 1;
                        goto cleanup;
                }
diff --git a/refs.h b/refs.h
index 8c7f9c4..09d3564 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -269,9 +269,12 @@ void ref_transaction_delete(struct ref_transaction *transaction,
  * Commit all of the changes that have been queued in transaction, as
  * atomically as possible.  Return a nonzero value if there is a
  * problem.
+ * If err is non-NULL we will add an error string to it to explain why
+ * the transaction failed. The string does not end in newline.
  */
 int ref_transaction_commit(struct ref_transaction *transaction,
-                          const char *msg, enum action_on_err onerr);
+                          const char *msg, struct strbuf *err,
+                          enum action_on_err onerr);
 
 /*
  * Free an existing transaction and all associated data.