refs.c: make ref_transaction_begin take an err argument
[gitweb.git] / builtin / update-ref.c
index 1fd7a8918693fca9610cb8d5de68b8607be4a30a..96a53b92aed97142996c1071555e85bdcb333987 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);
@@ -224,7 +226,9 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next)
        if (*next != line_termination)
                die("create %s: extra input: %s", refname, next);
 
-       ref_transaction_create(transaction, refname, new_sha1, update_flags);
+       if (ref_transaction_create(transaction, refname, new_sha1,
+                                  update_flags, &err))
+               die("%s", err.buf);
 
        update_flags = 0;
        free(refname);
@@ -254,8 +258,9 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next)
        if (*next != line_termination)
                die("delete %s: extra input: %s", refname, next);
 
-       ref_transaction_delete(transaction, refname, old_sha1,
-                              update_flags, have_old);
+       if (ref_transaction_delete(transaction, refname, old_sha1,
+                                  update_flags, have_old, &err))
+               die("%s", err.buf);
 
        update_flags = 0;
        free(refname);
@@ -286,8 +291,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,18 +365,19 @@ 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();
-
+               transaction = ref_transaction_begin(&err);
+               if (!transaction)
+                       die("%s", err.buf);
                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);
+               if (ref_transaction_commit(transaction, msg, &err))
+                       die("%s", err.buf);
                ref_transaction_free(transaction);
-               return ret;
+               strbuf_release(&err);
+               return 0;
        }
 
        if (end_null)