git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>,
	David Turner <dturner@twopensource.com>
Cc: "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org, "Michael Haggerty" <mhagger@alum.mit.edu>
Subject: [PATCH 5/5] lock_ref_for_update(): avoid a symref resolution
Date: Tue,  7 Jun 2016 13:50:10 +0200	[thread overview]
Message-ID: <dd34c6a5ef249f4ffb8c8cb7238889e84e19f82c.1465299118.git.mhagger@alum.mit.edu> (raw)
In-Reply-To: <cover.1465299118.git.mhagger@alum.mit.edu>

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>
---
 refs/files-backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 98c8b95..b8d7a9a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3481,7 +3481,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': "
-- 
2.8.1

      parent reply	other threads:[~2016-06-07 11:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-07 11:50 [PATCH 0/5] Improve test coverage of update-ref error messages Michael Haggerty
2016-06-07 11:50 ` [PATCH 1/5] t1404: rename file to t1404-update-ref-errors.sh Michael Haggerty
2016-06-07 11:50 ` [PATCH 2/5] t1404: document function test_update_rejected Michael Haggerty
2016-06-07 16:57   ` Johannes Sixt
2016-06-07 19:25     ` Junio C Hamano
2016-06-09 15:45     ` Michael Haggerty
2016-06-09 16:05       ` Junio C Hamano
2016-06-10  6:30         ` Michael Haggerty
2016-06-07 11:50 ` [PATCH 3/5] t1404: add more tests of update-ref error handling Michael Haggerty
2016-06-07 11:50 ` [PATCH 4/5] lock_ref_for_update(): make error handling more uniform Michael Haggerty
2016-06-07 11:50 ` Michael Haggerty [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dd34c6a5ef249f4ffb8c8cb7238889e84e19f82c.1465299118.git.mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).