resolve_missing_loose_ref(): simplify semantics
authorMichael Haggerty <mhagger@alum.mit.edu>
Thu, 7 Apr 2016 19:02:55 +0000 (15:02 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Apr 2016 18:35:13 +0000 (11:35 -0700)
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>
refs/files-backend.c
index 9676ec2fd1054836a2695978430ae2977ae2dab8..c0cf6fd6c069d3cfa3f4506a5f691a111e31211d 100644 (file)
@@ -1368,11 +1368,9 @@ static struct ref_entry *get_packed_ref(const char *refname)
 }
 
 /*
- * A loose ref file doesn't exist; check for a packed ref.  The
- * options are forwarded from resolve_safe_unsafe().
+ * A loose ref file doesn't exist; check for a packed ref.
  */
 static int resolve_missing_loose_ref(const char *refname,
-                                    int resolve_flags,
                                     unsigned char *sha1,
                                     int *flags)
 {
@@ -1389,14 +1387,8 @@ static int resolve_missing_loose_ref(const char *refname,
                        *flags |= REF_ISPACKED;
                return 0;
        }
-       /* The reference is not a packed reference, either. */
-       if (resolve_flags & RESOLVE_REF_READING) {
-               errno = ENOENT;
-               return -1;
-       } else {
-               hashclr(sha1);
-               return 0;
-       }
+       /* refname is not a packed reference. */
+       return -1;
 }
 
 /* This function needs to return a meaningful errno on failure */
@@ -1461,9 +1453,13 @@ static const char *resolve_ref_1(const char *refname,
                if (lstat(path, &st) < 0) {
                        if (errno != ENOENT)
                                return NULL;
-                       if (resolve_missing_loose_ref(refname, resolve_flags,
-                                                     sha1, flags))
-                               return NULL;
+                       if (resolve_missing_loose_ref(refname, sha1, flags)) {
+                               if (resolve_flags & RESOLVE_REF_READING) {
+                                       errno = ENOENT;
+                                       return NULL;
+                               }
+                               hashclr(sha1);
+                       }
                        if (bad_name) {
                                hashclr(sha1);
                                if (flags)