refs: keep track of unresolved reference value in iterators
Since ref iterators do not hold onto the direct value of a reference without resolving it, the only way to get ahold of a direct value of a symbolic ref is to make a separate call to refs_read_symbolic_ref. To make accessing the direct value of a symbolic ref more efficient, let's save the direct value of the ref in the iterators for both the files backend and the reftable backend. Signed-off-by: John Cai <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -245,9 +245,12 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
|
||||
{
|
||||
struct object_id oid;
|
||||
int flag;
|
||||
const char *referent = refs_resolve_ref_unsafe(&refs->base,
|
||||
refname,
|
||||
RESOLVE_REF_READING,
|
||||
&oid, &flag);
|
||||
|
||||
if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,
|
||||
&oid, &flag)) {
|
||||
if (!referent) {
|
||||
oidclr(&oid, the_repository->hash_algo);
|
||||
flag |= REF_ISBROKEN;
|
||||
} else if (is_null_oid(&oid)) {
|
||||
@ -268,7 +271,11 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,
|
||||
oidclr(&oid, the_repository->hash_algo);
|
||||
flag |= REF_BAD_NAME | REF_ISBROKEN;
|
||||
}
|
||||
add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));
|
||||
|
||||
if (!(flag & REF_ISSYMREF))
|
||||
referent = NULL;
|
||||
|
||||
add_entry_to_dir(dir, create_ref_entry(refname, referent, &oid, flag));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -886,6 +893,8 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
|
||||
iter->base.refname = iter->iter0->refname;
|
||||
iter->base.oid = iter->iter0->oid;
|
||||
iter->base.flags = iter->iter0->flags;
|
||||
iter->base.referent = iter->iter0->referent;
|
||||
|
||||
return ITER_OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user