Skip to content

Commit

Permalink
refs.c: make ref_transaction_begin take an err argument
Browse files Browse the repository at this point in the history
Add an err argument to _begin so that on non-fatal failures in future ref
backends we can report a nice error back to the caller.
While _begin can currently never fail for other reasons than OOM, in which
case we die() anyway, we may add other types of backends in the future.
For example, a hypothetical MySQL backend could fail in _begin with
"Can not connect to MySQL server. No route to host".

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ronnie Sahlberg authored and Junio C Hamano committed Sep 3, 2014
1 parent 8c8bdc0 commit 93a644e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion builtin/update-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
die("Refusing to perform update with empty message.");

if (read_stdin) {
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)
Expand All @@ -374,6 +376,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
if (ref_transaction_commit(transaction, msg, &err))
die("%s", err.buf);
ref_transaction_free(transaction);
strbuf_release(&err);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3397,7 +3397,7 @@ struct ref_transaction {
size_t nr;
};

struct ref_transaction *ref_transaction_begin(void)
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
{
return xcalloc(1, sizeof(struct ref_transaction));
}
Expand Down
2 changes: 1 addition & 1 deletion refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ enum action_on_err {
* Begin a reference transaction. The reference transaction must
* be freed by calling ref_transaction_free().
*/
struct ref_transaction *ref_transaction_begin(void);
struct ref_transaction *ref_transaction_begin(struct strbuf *err);

/*
* The following functions add a reference check or update to a
Expand Down

0 comments on commit 93a644e

Please sign in to comment.