summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2021-09-21 16:51:05 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-09-23 00:15:11 (GMT)
commita46edab00024957839e306d9db03797acb3ff8c7 (patch)
tree70241973040f699c27cd01d9d20d8c09f12d7c0e
parent3f9b584b15a5f5048844c2ef335c3704d33b1f04 (diff)
downloadgit-a46edab00024957839e306d9db03797acb3ff8c7.zip
git-a46edab00024957839e306d9db03797acb3ff8c7.tar.gz
git-a46edab00024957839e306d9db03797acb3ff8c7.tar.bz2
refs iterator: support non-the_repository advance
Support repositories other than the_repository when advancing through an iterator. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--refs.c3
-rw-r--r--refs/files-backend.c2
-rw-r--r--refs/iterator.c7
-rw-r--r--refs/refs-internal.h1
4 files changed, 5 insertions, 8 deletions
diff --git a/refs.c b/refs.c
index 3a57893..6ed64be 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 2a99e16..4742672 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 ee6b00a..5904852 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 4656ef8..57ad126 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);