refs.c: make ref_transaction_begin take an err argument
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>
Ronnie Sahlberg committed
May 19, 2014 at 10:42 UTC
93a644ea9d3702cc1cc62c0d413f81f8e46fabe7
3 files changed
+6
-3
builtin/update-ref.c
+4
-1
@@ -365,7 +365,9 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
365
die("Refusing to perform update with empty message.");
366
367
if (read_stdin) {
368
- transaction = ref_transaction_begin();
368
+ transaction = ref_transaction_begin(&err);
369
+ if (!transaction)
370
+ die("%s", err.buf);
371
if (delete || no_deref || argc > 0)
372
usage_with_options(git_update_ref_usage, options);
373
if (end_null)
@@ -374,6 +376,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
376
if (ref_transaction_commit(transaction, msg, &err))
377
die("%s", err.buf);
378
ref_transaction_free(transaction);
379
+ strbuf_release(&err);
380
return 0;
381
}
382
refs.c
+1
-1
@@ -3397,7 +3397,7 @@ struct ref_transaction {
3397
size_t nr;
3398
};
3399
3400
-struct ref_transaction *ref_transaction_begin(void)
3400
+struct ref_transaction *ref_transaction_begin(struct strbuf *err)
3401
{
3402
return xcalloc(1, sizeof(struct ref_transaction));
3403
}
refs.h
+1
-1
@@ -262,7 +262,7 @@ enum action_on_err {
262
* Begin a reference transaction. The reference transaction must
263
* be freed by calling ref_transaction_free().
264
*/
265
-struct ref_transaction *ref_transaction_begin(void);
265
+struct ref_transaction *ref_transaction_begin(struct strbuf *err);
266
267
/*
268
* The following functions add a reference check or update to a