packed_read_raw_ref(): new function, replacing `resolve_packed_ref()`

Add a new function, `packed_read_raw_ref()`, which is nearly a `read_raw_ref_fn`. Use it in place of `resolve_packed_ref()`. 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 d13fa1a9ba494fbf0e4c362ebe1f60ff464a8f43
1 file changed +17 -19
refs/files-backend.c
+17 -19
@@ -608,27 +608,23 @@ static struct ref_entry *get_packed_ref(struct packed_ref_store *refs,
608 return find_ref_entry(get_packed_refs(refs), refname);
609 }
610
611 -/*
612 - * A loose ref file doesn't exist; check for a packed ref.
613 - */
614 -static int resolve_packed_ref(struct files_ref_store *refs,
615 - const char *refname,
616 - unsigned char *sha1, unsigned int *flags)
611 +static int packed_read_raw_ref(struct packed_ref_store *refs,
612 + const char *refname, unsigned char *sha1,
613 + struct strbuf *referent, unsigned int *type)
614 {
615 struct ref_entry *entry;
616
620 - /*
621 - * The loose reference file does not exist; check for a packed
622 - * reference.
623 - */
624 - entry = get_packed_ref(refs->packed_ref_store, refname);
625 - if (entry) {
626 - hashcpy(sha1, entry->u.value.oid.hash);
627 - *flags |= REF_ISPACKED;
628 - return 0;
617 + *type = 0;
618 +
619 + entry = get_packed_ref(refs, refname);
620 + if (!entry) {
621 + errno = ENOENT;
622 + return -1;
623 }
630 - /* refname is not a packed reference. */
631 - return -1;
624 +
625 + hashcpy(sha1, entry->u.value.oid.hash);
626 + *type = REF_ISPACKED;
627 + return 0;
628 }
629
630 static int files_read_raw_ref(struct ref_store *ref_store,
@@ -674,7 +670,8 @@ stat_ref:
670 if (lstat(path, &st) < 0) {
671 if (errno != ENOENT)
672 goto out;
677 - if (resolve_packed_ref(refs, refname, sha1, type)) {
673 + if (packed_read_raw_ref(refs->packed_ref_store, refname,
674 + sha1, referent, type)) {
675 errno = ENOENT;
676 goto out;
677 }
@@ -713,7 +710,8 @@ stat_ref:
710 * ref is supposed to be, there could still be a
711 * packed ref:
712 */
716 - if (resolve_packed_ref(refs, refname, sha1, type)) {
713 + if (packed_read_raw_ref(refs->packed_ref_store, refname,
714 + sha1, referent, type)) {
715 errno = EISDIR;
716 goto out;
717 }