ref_transaction_commit(): inline call to write_ref_sha1()

And remove the function write_ref_sha1(), as it is no longer used. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 10, 2015 at 04:45 UTC 4da50def5b4dcb0753334e3f44fffaccb3728a6c
1 file changed +10 -28
refs.c
+10 -28
@@ -3134,30 +3134,6 @@ static int commit_ref_update(struct ref_lock *lock,
3134 return 0;
3135 }
3136
3137 -/*
3138 - * Write sha1 as the new value of the reference specified by the
3139 - * (open) lock. On error, roll back the lockfile and set errno
3140 - * appropriately.
3141 - */
3142 -static int write_ref_sha1(struct ref_lock *lock,
3143 - const unsigned char *sha1, const char *logmsg)
3144 -{
3145 - if (!lock) {
3146 - errno = EINVAL;
3147 - return -1;
3148 - }
3149 - if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {
3150 - unlock_ref(lock);
3151 - return 0;
3152 - }
3153 -
3154 - if (write_ref_to_lockfile(lock, sha1) ||
3155 - commit_ref_update(lock, sha1, logmsg))
3156 - return -1;
3157 -
3158 - return 0;
3159 -}
3160 -
3137 int create_symref(const char *ref_target, const char *refs_heads_master,
3138 const char *logmsg)
3139 {
@@ -3852,15 +3828,21 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3828 struct ref_update *update = updates[i];
3829
3830 if (!is_null_sha1(update->new_sha1)) {
3855 - if (write_ref_sha1(update->lock, update->new_sha1,
3856 - update->msg)) {
3857 - update->lock = NULL; /* freed by write_ref_sha1 */
3831 + if (!update->lock->force_write &&
3832 + !hashcmp(update->lock->old_sha1, update->new_sha1)) {
3833 + unlock_ref(update->lock);
3834 + update->lock = NULL;
3835 + } else if (write_ref_to_lockfile(update->lock, update->new_sha1) ||
3836 + commit_ref_update(update->lock, update->new_sha1, update->msg)) {
3837 + update->lock = NULL; /* freed by the above calls */
3838 strbuf_addf(err, "Cannot update the ref '%s'.",
3839 update->refname);
3840 ret = TRANSACTION_GENERIC_ERROR;
3841 goto cleanup;
3842 + } else {
3843 + /* freed by the above calls: */
3844 + update->lock = NULL;
3845 }
3863 - update->lock = NULL; /* freed by write_ref_sha1 */
3846 }
3847 }
3848