Support repositories other than the_repository when advancing through an iterator. Signed-off-by: Jonathan Tan <jonathantanmy@xxxxxxxxxx> --- refs.c | 3 ++- refs/files-backend.c | 2 +- refs/iterator.c | 7 +------ refs/refs-internal.h | 1 + 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/refs.c b/refs.c index 3a57893032..6ed64bee1b 100644 --- a/refs.c +++ b/refs.c @@ -255,12 +255,13 @@ int refname_is_safe(const char *refname) * does not exist, emit a warning and return false. */ int ref_resolves_to_object(const char *refname, + struct repository *repo, const struct object_id *oid, unsigned int flags) { if (flags & REF_ISBROKEN) return 0; - if (!has_object_file(oid)) { + if (!repo_has_object_file(repo, oid)) { error(_("%s does not point to a valid object!"), refname); return 0; } diff --git a/refs/files-backend.c b/refs/files-backend.c index 1faab1cf66..24e5668d6c 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1127,7 +1127,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; diff --git a/refs/iterator.c b/refs/iterator.c index ee6b00a7be..59048523b8 100644 --- a/refs/iterator.c +++ b/refs/iterator.c @@ -12,15 +12,10 @@ int ref_iterator_advance(struct ref_iterator *ref_iterator) { int ok; - if (ref_iterator->repo && ref_iterator->repo != the_repository) - /* - * NEEDSWORK: make ref_resolves_to_object() support - * arbitrary repositories - */ - BUG("ref_iterator->repo must be NULL or the_repository"); while ((ok = ref_iterator->vtable->advance(ref_iterator)) == ITER_OK) { if (ref_iterator->repo && !ref_resolves_to_object(ref_iterator->refname, + ref_iterator->repo, ref_iterator->oid, ref_iterator->flags)) continue; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 4656ef83a3..57ad1262ab 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -66,6 +66,7 @@ int refname_is_safe(const char *refname); * referred-to object does not exist, emit a warning and return false. */ int ref_resolves_to_object(const char *refname, + struct repository *repo, const struct object_id *oid, unsigned int flags); -- 2.33.0.464.g1972c5931b-goog