color_parse: do not mention variable name in error message
[gitweb.git] / builtin / update-ref.c
index 405267f6e2776b3b2bf5c91c1102e090f5ac68f0..3067b11310fb01e9e05a1988898566f211601e07 100644 (file)
@@ -16,6 +16,7 @@ static struct ref_transaction *transaction;
 
 static char line_termination = '\n';
 static int update_flags;
+static struct strbuf err = STRBUF_INIT;
 
 /*
  * Parse one whitespace- or NUL-terminated, possibly C-quoted argument
@@ -197,8 +198,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, &err))
+               die("%s", err.buf);
 
        update_flags = 0;
        free(refname);
@@ -286,8 +288,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, &err))
+               die("%s", err.buf);
 
        update_flags = 0;
        free(refname);
@@ -359,17 +362,16 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                die("Refusing to perform update with empty message.");
 
        if (read_stdin) {
-               int ret;
                transaction = ref_transaction_begin();
-
                if (delete || no_deref || argc > 0)
                        usage_with_options(git_update_ref_usage, options);
                if (end_null)
                        line_termination = '\0';
                update_refs_stdin();
-               ret = ref_transaction_commit(transaction, msg,
-                                            UPDATE_REFS_DIE_ON_ERR);
-               return ret;
+               if (ref_transaction_commit(transaction, msg, &err))
+                       die("%s", err.buf);
+               ref_transaction_free(transaction);
+               return 0;
        }
 
        if (end_null)