packed_peel_ref(): new function, extracted from `files_peel_ref()`
authorMichael Haggerty <mhagger@alum.mit.edu>
Fri, 23 Jun 2017 07:01:34 +0000 (09:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 23 Jun 2017 20:27:32 +0000 (13:27 -0700)
This will later become a method of `packed_ref_store`.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c
index c206791b91306178c0e279c3281832d4385795fe..185d05e1d67ac1654f43ccd3b28f681c414dd98d 100644 (file)
@@ -1013,6 +1013,18 @@ static int lock_raw_ref(struct files_ref_store *refs,
        return ret;
 }
 
+static int packed_peel_ref(struct packed_ref_store *refs,
+                          const char *refname, unsigned char *sha1)
+{
+       struct ref_entry *r = get_packed_ref(refs, refname);
+
+       if (!r || peel_entry(r, 0))
+               return -1;
+
+       hashcpy(sha1, r->u.value.peeled.hash);
+       return 0;
+}
+
 static int files_peel_ref(struct ref_store *ref_store,
                          const char *refname, unsigned char *sha1)
 {
@@ -1043,17 +1055,9 @@ static int files_peel_ref(struct ref_store *ref_store,
         * be expensive and (b) loose references anyway usually do not
         * have REF_KNOWS_PEELED.
         */
-       if (flag & REF_ISPACKED) {
-               struct ref_entry *r =
-                       get_packed_ref(refs->packed_ref_store, refname);
-
-               if (r) {
-                       if (peel_entry(r, 0))
-                               return -1;
-                       hashcpy(sha1, r->u.value.peeled.hash);
-                       return 0;
-               }
-       }
+       if (flag & REF_ISPACKED &&
+           !packed_peel_ref(refs->packed_ref_store, refname, sha1))
+               return 0;
 
        return peel_object(base, sha1);
 }