packed_peel_ref(): new function, extracted from `files_peel_ref()`

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>

Michael Haggerty committed Jun 23, 2017 at 09:01 UTC 6dc6ba7092423dfd5b94b9dcb649f2905d456d94
1 file changed +15 -11
refs/files-backend.c
+15 -11
@@ -1013,6 +1013,18 @@ out:
1013 return ret;
1014 }
1015
1016 +static int packed_peel_ref(struct packed_ref_store *refs,
1017 + const char *refname, unsigned char *sha1)
1018 +{
1019 + struct ref_entry *r = get_packed_ref(refs, refname);
1020 +
1021 + if (!r || peel_entry(r, 0))
1022 + return -1;
1023 +
1024 + hashcpy(sha1, r->u.value.peeled.hash);
1025 + return 0;
1026 +}
1027 +
1028 static int files_peel_ref(struct ref_store *ref_store,
1029 const char *refname, unsigned char *sha1)
1030 {
@@ -1043,17 +1055,9 @@ static int files_peel_ref(struct ref_store *ref_store,
1055 * be expensive and (b) loose references anyway usually do not
1056 * have REF_KNOWS_PEELED.
1057 */
1046 - if (flag & REF_ISPACKED) {
1047 - struct ref_entry *r =
1048 - get_packed_ref(refs->packed_ref_store, refname);
1049 -
1050 - if (r) {
1051 - if (peel_entry(r, 0))
1052 - return -1;
1053 - hashcpy(sha1, r->u.value.peeled.hash);
1054 - return 0;
1055 - }
1056 - }
1058 + if (flag & REF_ISPACKED &&
1059 + !packed_peel_ref(refs->packed_ref_store, refname, sha1))
1060 + return 0;
1061
1062 return peel_object(base, sha1);
1063 }