Skip to content

Commit d13fa1a

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 38b86e8 commit d13fa1a

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

refs/files-backend.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -608,27 +608,23 @@ static struct ref_entry *get_packed_ref(struct packed_ref_store *refs,
608608
return find_ref_entry(get_packed_refs(refs), refname);
609609
}
610610

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)
617614
{
618615
struct ref_entry *entry;
619616

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;
629623
}
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;
632628
}
633629

634630
static int files_read_raw_ref(struct ref_store *ref_store,
@@ -674,7 +670,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
674670
if (lstat(path, &st) < 0) {
675671
if (errno != ENOENT)
676672
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)) {
678675
errno = ENOENT;
679676
goto out;
680677
}
@@ -713,7 +710,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
713710
* ref is supposed to be, there could still be a
714711
* packed ref:
715712
*/
716-
if (resolve_packed_ref(refs, refname, sha1, type)) {
713+
if (packed_read_raw_ref(refs->packed_ref_store, refname,
714+
sha1, referent, type)) {
717715
errno = EISDIR;
718716
goto out;
719717
}

0 commit comments

Comments
 (0)