resolve_missing_loose_ref(): simplify semantics
Make resolve_missing_loose_ref() only responsible for looking up a packed reference, without worrying about whether we want to read or write the reference and without setting errno on failure. Move the other logic to the caller. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 7, 2016 at 15:02 UTC
419c6f4c76c5950a33ed2cedbce9c6f7d66773f6
1 file changed
+10
-14
refs/files-backend.c
+10
-14
@@ -1368,11 +1368,9 @@ static struct ref_entry *get_packed_ref(const char *refname)
1368
}
1369
1370
/*
1371
- * A loose ref file doesn't exist; check for a packed ref. The
1372
- * options are forwarded from resolve_safe_unsafe().
1371
+ * A loose ref file doesn't exist; check for a packed ref.
1372
*/
1373
static int resolve_missing_loose_ref(const char *refname,
1375
- int resolve_flags,
1374
unsigned char *sha1,
1375
int *flags)
1376
{
@@ -1389,14 +1387,8 @@ static int resolve_missing_loose_ref(const char *refname,
1387
*flags |= REF_ISPACKED;
1388
return 0;
1389
}
1392
- /* The reference is not a packed reference, either. */
1393
- if (resolve_flags & RESOLVE_REF_READING) {
1394
- errno = ENOENT;
1395
- return -1;
1396
- } else {
1397
- hashclr(sha1);
1398
- return 0;
1399
- }
1390
+ /* refname is not a packed reference. */
1391
+ return -1;
1392
}
1393
1394
/* This function needs to return a meaningful errno on failure */
@@ -1461,9 +1453,13 @@ static const char *resolve_ref_1(const char *refname,
1453
if (lstat(path, &st) < 0) {
1454
if (errno != ENOENT)
1455
return NULL;
1464
- if (resolve_missing_loose_ref(refname, resolve_flags,
1465
- sha1, flags))
1466
- return NULL;
1456
+ if (resolve_missing_loose_ref(refname, sha1, flags)) {
1457
+ if (resolve_flags & RESOLVE_REF_READING) {
1458
+ errno = ENOENT;
1459
+ return NULL;
1460
+ }
1461
+ hashclr(sha1);
1462
+ }
1463
if (bad_name) {
1464
hashclr(sha1);
1465
if (flags)