refs.c: make update_ref_write update a strbuf on failure

Change update_ref_write to also update an error strbuf on failure.
This makes the error available to ref_transaction_commit callers if the
transaction failed due to update_ref_sha1/write_ref_sha1 failures.

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>
This commit is contained in:
Ronnie Sahlberg 2014-06-20 07:42:57 -07:00 коммит произвёл Junio C Hamano
Родитель 038d005129
Коммит c1703d7634
1 изменённых файлов: 6 добавлений и 3 удалений

9
refs.c
Просмотреть файл

@ -3353,10 +3353,13 @@ static struct ref_lock *update_ref_lock(const char *refname,
static int update_ref_write(const char *action, const char *refname,
const unsigned char *sha1, struct ref_lock *lock,
enum action_on_err onerr)
struct strbuf *err, enum action_on_err onerr)
{
if (write_ref_sha1(lock, sha1, action) < 0) {
const char *str = "Cannot update the ref '%s'.";
if (err)
strbuf_addf(err, str, refname);
switch (onerr) {
case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
@ -3477,7 +3480,7 @@ int update_ref(const char *action, const char *refname,
lock = update_ref_lock(refname, oldval, flags, NULL, onerr);
if (!lock)
return 1;
return update_ref_write(action, refname, sha1, lock, onerr);
return update_ref_write(action, refname, sha1, lock, NULL, onerr);
}
static int ref_update_compare(const void *r1, const void *r2)
@ -3559,7 +3562,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
ret = update_ref_write(msg,
update->refname,
update->new_sha1,
update->lock, onerr);
update->lock, err, onerr);
update->lock = NULL; /* freed by update_ref_write */
if (ret)
goto cleanup;