git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: Anders Kaseorg <andersk@mit.edu>,
	Stefan Beller <sbeller@google.com>, Jeff King <peff@peff.net>,
	git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH v3 3/4] read_loose_refs(): simplify function logic
Date: Wed,  3 Jun 2015 15:51:58 +0200	[thread overview]
Message-ID: <ab21b4940709f6cfe11a663e4fa4e342e4f1ca41.1433339279.git.mhagger@alum.mit.edu> (raw)
In-Reply-To: <cover.1433339279.git.mhagger@alum.mit.edu>

Make it clearer that there are two possible ways to read the
reference, but that we handle read errors uniformly regardless of
which way it was read.

This refactoring also makes the following change easier to implement.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/refs.c b/refs.c
index 47e4e53..6736424 100644
--- a/refs.c
+++ b/refs.c
@@ -1308,19 +1308,24 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
 					 create_dir_entry(refs, refname.buf,
 							  refname.len, 1));
 		} else {
+			int read_ok;
+
 			if (*refs->name) {
 				hashclr(sha1);
 				flag = 0;
-				if (resolve_gitlink_ref(refs->name, refname.buf, sha1) < 0) {
-					hashclr(sha1);
-					flag |= REF_ISBROKEN;
-				}
-			} else if (read_ref_full(refname.buf,
-						 RESOLVE_REF_READING,
-						 sha1, &flag)) {
+				read_ok = !resolve_gitlink_ref(refs->name,
+							       refname.buf, sha1);
+			} else {
+				read_ok = !read_ref_full(refname.buf,
+							 RESOLVE_REF_READING,
+							 sha1, &flag);
+			}
+
+			if (!read_ok) {
 				hashclr(sha1);
 				flag |= REF_ISBROKEN;
 			}
+
 			if (check_refname_format(refname.buf,
 						 REFNAME_ALLOW_ONELEVEL)) {
 				hashclr(sha1);
-- 
2.1.4

  parent reply	other threads:[~2015-06-03 13:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-03 13:51 [PATCH v3 0/4] Fix how for-each-ref handles broken loose references Michael Haggerty
2015-06-03 13:51 ` [PATCH v3 1/4] t6301: new tests of for-each-ref error handling Michael Haggerty
2015-06-03 13:51 ` [PATCH v3 2/4] for-each-ref: report broken references correctly Michael Haggerty
2015-06-03 13:51 ` Michael Haggerty [this message]
2015-06-03 13:51 ` [PATCH v3 4/4] read_loose_refs(): treat NULL_SHA1 loose references as broken Michael Haggerty
2015-06-03 14:08   ` Jeff King
2015-06-03 18:51     ` Junio C Hamano
2015-06-03 20:15       ` Jeff King
2015-06-03 21:20         ` Junio C Hamano
2015-06-08  9:26           ` Michael Haggerty
2015-06-08 17:37             ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=ab21b4940709f6cfe11a663e4fa4e342e4f1ca41.1433339279.git.mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=andersk@mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.com \
    /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.
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 NNTP newsgroup(s).