]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: teach arbitrary repo support to iterators
authorJonathan Tan <jonathantanmy@google.com>
Fri, 8 Oct 2021 21:08:15 +0000 (14:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Oct 2021 22:06:05 +0000 (15:06 -0700)
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>
refs.c
refs/files-backend.c
refs/packed-backend.c
refs/refs-internal.h

diff --git a/refs.c b/refs.c
index 9c4e388153b64dc42d8e8ea64659a277dbbe749c..c07aeff6f4e36b1db579c6a53db5b79ef2338c79 100644 (file)
--- 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;
        }
index 6a481e968ff16700f355653fb8cea4684fa4c048..3f213d24b0a2d0f80504e915af97578ef3de099d 100644 (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;
index ea3493b24ed34a712b763991c74d63a927169317..63f78bbaeadf5b521e3afe9e1d968e96312ae996 100644 (file)
@@ -778,6 +778,7 @@ struct packed_ref_iterator {
        struct object_id oid, peeled;
        struct strbuf refname_buf;
 
+       struct repository *repo;
        unsigned int flags;
 };
 
@@ -866,8 +867,8 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator)
                        continue;
 
                if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
-                   !ref_resolves_to_object(iter->base.refname, &iter->oid,
-                                           iter->flags))
+                   !ref_resolves_to_object(iter->base.refname, iter->repo,
+                                           &iter->oid, iter->flags))
                        continue;
 
                return ITER_OK;
@@ -956,6 +957,7 @@ static struct ref_iterator *packed_ref_iterator_begin(
 
        iter->base.oid = &iter->oid;
 
+       iter->repo = ref_store->repo;
        iter->flags = flags;
 
        if (prefix && *prefix)
index d28440c9cc78803c64e8286ffc19da68c3bd1335..500d77864d896741890c92d030e058892db5e057 100644 (file)
@@ -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);