read_loose_refs(): simplify function logic
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 3, 2015 at 15:51 UTC
f5517074f8f5cecc773b2ff927be4a059f2c9db0
1 file changed
+12
-7
refs.c
+12
-7
@@ -1281,19 +1281,24 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1281
create_dir_entry(refs, refname.buf,
1282
refname.len, 1));
1283
} else {
1284
+ int read_ok;
1285
+
1286
if (*refs->name) {
1287
hashclr(sha1);
1288
flag = 0;
1287
- if (resolve_gitlink_ref(refs->name, refname.buf, sha1) < 0) {
1288
- hashclr(sha1);
1289
- flag |= REF_ISBROKEN;
1290
- }
1291
- } else if (read_ref_full(refname.buf,
1292
- RESOLVE_REF_READING,
1293
- sha1, &flag)) {
1289
+ read_ok = !resolve_gitlink_ref(refs->name,
1290
+ refname.buf, sha1);
1291
+ } else {
1292
+ read_ok = !read_ref_full(refname.buf,
1293
+ RESOLVE_REF_READING,
1294
+ sha1, &flag);
1295
+ }
1296
+
1297
+ if (!read_ok) {
1298
hashclr(sha1);
1299
flag |= REF_ISBROKEN;
1300
}
1301
+
1302
if (check_refname_format(refname.buf,
1303
REFNAME_ALLOW_ONELEVEL)) {
1304
hashclr(sha1);