lock_ref_for_update(): avoid a symref resolution
authorMichael Haggerty <mhagger@alum.mit.edu>
Tue, 7 Jun 2016 07:32:08 +0000 (09:32 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jun 2016 18:49:00 +0000 (11:49 -0700)
If we're overwriting a symref with a SHA-1, we need to resolve the value
of the symref (1) to check against update->old_sha1 and (2) to write to
its reflog. However, we've already read the symref itself and know its
referent. So there is no need to read the symref's value through the
symref; we can read the referent directly.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c
index 6f8fecd024d177afe2427d58fae603c52a4ee156..769e5c410043afd2f0d4304fbef3850662437ed0 100644 (file)
@@ -3479,7 +3479,7 @@ static int lock_ref_for_update(struct ref_update *update,
                         * the transaction, so we have to read it here
                         * to record and possibly check old_sha1:
                         */
-                       if (read_ref_full(update->refname, 0,
+                       if (read_ref_full(referent.buf, 0,
                                          lock->old_oid.hash, NULL)) {
                                if (update->flags & REF_HAVE_OLD) {
                                        strbuf_addf(err, "cannot lock ref '%s': "