+ if (!(update->flags & REF_DELETING) &&
+ (update->lock->force_write ||
+ hashcmp(update->lock->old_sha1, update->new_sha1))) {
+ if (write_ref_to_lockfile(update->lock, update->new_sha1)) {
+ /*
+ * The lock was freed upon failure of
+ * write_ref_to_lockfile():
+ */
+ update->lock = NULL;
+ strbuf_addf(err, "Cannot update the ref '%s'.",
+ update->refname);
+ ret = TRANSACTION_GENERIC_ERROR;
+ goto cleanup;
+ }
+ update->flags |= REF_NEEDS_COMMIT;
+ } else {
+ /*
+ * We didn't have to write anything to the lockfile.
+ * Close it to free up the file descriptor:
+ */
+ if (close_ref(update->lock)) {
+ strbuf_addf(err, "Couldn't close %s.lock",
+ update->refname);
+ goto cleanup;
+ }
+ }