refs: teach arbitrary repo support to iterators

Note that should_pack_ref() is called when writing refs, which is only
supported for the_repository, hence the_repository is hardcoded there.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Tan
2021-10-08 14:08:15 -07:00
committed by Junio C Hamano
parent 34224e14d6
commit 9bc45a2802
4 changed files with 11 additions and 4 deletions

View File

@ -732,6 +732,7 @@ struct files_ref_iterator {
struct ref_iterator base;
struct ref_iterator *iter0;
struct repository *repo;
unsigned int flags;
};
@ -753,6 +754,7 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
!ref_resolves_to_object(iter->iter0->refname,
iter->repo,
iter->iter0->oid,
iter->iter0->flags))
continue;
@ -855,6 +857,7 @@ static struct ref_iterator *files_ref_iterator_begin(
base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,
overlay_iter->ordered);
iter->iter0 = overlay_iter;
iter->repo = ref_store->repo;
iter->flags = flags;
return ref_iterator;
@ -1139,7 +1142,7 @@ static int should_pack_ref(const char *refname,
return 0;
/* Do not pack broken refs: */
if (!ref_resolves_to_object(refname, oid, ref_flags))
if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
return 0;
return 1;