refs.c: remove the update_ref_write function

Since we only call update_ref_write from a single place and we only call it with onerr==QUIET_ON_ERR we can just as well get rid of it and just call write_ref_sha1 directly. This changes the return status for _commit from 1 to -1 on failures when writing to the ref. Eventually we will want _commit to start returning more detailed error conditions than the current simple success/failure. 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 Apr 29, 2014 at 13:42 UTC 04ad6223ec1163163c4f39308149bee852ee245f
1 file changed +8 -26
refs.c
+8 -26
@@ -3336,25 +3336,6 @@ int for_each_reflog(each_ref_fn fn, void *cb_data)
3336 return retval;
3337 }
3338
3339 -static int update_ref_write(const char *action, const char *refname,
3340 - const unsigned char *sha1, struct ref_lock *lock,
3341 - struct strbuf *err, enum action_on_err onerr)
3342 -{
3343 - if (write_ref_sha1(lock, sha1, action) < 0) {
3344 - const char *str = "Cannot update the ref '%s'.";
3345 - if (err)
3346 - strbuf_addf(err, str, refname);
3347 -
3348 - switch (onerr) {
3349 - case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
3350 - case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
3351 - case UPDATE_REFS_QUIET_ON_ERR: break;
3352 - }
3353 - return 1;
3354 - }
3355 - return 0;
3356 -}
3357 -
3339 /**
3340 * Information needed for a single ref update. Set new_sha1 to the
3341 * new value or to zero to delete the ref. To check the old value
@@ -3605,14 +3586,15 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3586 struct ref_update *update = updates[i];
3587
3588 if (!is_null_sha1(update->new_sha1)) {
3608 - ret = update_ref_write(msg,
3609 - update->refname,
3610 - update->new_sha1,
3611 - update->lock, err,
3612 - UPDATE_REFS_QUIET_ON_ERR);
3613 - update->lock = NULL; /* freed by update_ref_write */
3614 - if (ret)
3589 + ret = write_ref_sha1(update->lock, update->new_sha1,
3590 + msg);
3591 + update->lock = NULL; /* freed by write_ref_sha1 */
3592 + if (ret) {
3593 + if (err)
3594 + strbuf_addf(err, "Cannot update the ref '%s'.",
3595 + update->refname);
3596 goto cleanup;
3597 + }
3598 }
3599 }
3600