]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: refactor `find_pack_entry()` to work on the packfile store
authorPatrick Steinhardt <ps@pks.im>
Thu, 18 Dec 2025 06:55:28 +0000 (07:55 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Jan 2026 00:37:43 +0000 (09:37 +0900)
The function `find_pack_entry()` doesn't work on a specific packfile
store, but instead works on the whole repository. This causes a bit of a
conceptual mismatch in its callers:

  - `packfile_store_freshen_object()` supposedly acts on a store, and
    its callers know to iterate through all sources already.

  - `packfile_store_read_object_info()` behaves likewise.

The only exception that doesn't know to handle iteration through sources
is `has_object_pack()`, but that function is trivial to adapt.

Refactor the code so that `find_pack_entry()` works on the packfile
store level instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
packfile.c

index 3bce1b150d5b940eb43cee2f177dd6d7e8fa877e..0e4c63e11d1d4d59847c640c87f4c8cf9a4e719f 100644 (file)
@@ -2087,29 +2087,23 @@ static int fill_pack_entry(const struct object_id *oid,
        return 1;
 }
 
-static int find_pack_entry(struct repository *r,
+static int find_pack_entry(struct packfile_store *store,
                           const struct object_id *oid,
                           struct pack_entry *e)
 {
-       struct odb_source *source;
-
-       for (source = r->objects->sources; source; source = source->next) {
-               packfile_store_prepare(r->objects->sources->packfiles);
-               if (source->midx && fill_midx_entry(source->midx, oid, e))
-                       return 1;
-       }
+       struct packfile_list_entry *l;
 
-       for (source = r->objects->sources; source; source = source->next) {
-               struct packfile_list_entry *l;
+       packfile_store_prepare(store);
+       if (store->source->midx && fill_midx_entry(store->source->midx, oid, e))
+               return 1;
 
-               for (l = source->packfiles->packs.head; l; l = l->next) {
-                       struct packed_git *p = l->pack;
+       for (l = store->packs.head; l; l = l->next) {
+               struct packed_git *p = l->pack;
 
-                       if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
-                               if (!source->packfiles->skip_mru_updates)
-                                       packfile_list_prepend(&source->packfiles->packs, p);
-                               return 1;
-                       }
+               if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
+                       if (!store->skip_mru_updates)
+                               packfile_list_prepend(&store->packs, p);
+                       return 1;
                }
        }
 
@@ -2120,7 +2114,7 @@ int packfile_store_freshen_object(struct packfile_store *store,
                                  const struct object_id *oid)
 {
        struct pack_entry e;
-       if (!find_pack_entry(store->source->odb->repo, oid, &e))
+       if (!find_pack_entry(store, oid, &e))
                return 0;
        if (e.p->is_cruft)
                return 0;
@@ -2141,7 +2135,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
        struct pack_entry e;
        int rtype;
 
-       if (!find_pack_entry(store->source->odb->repo, oid, &e))
+       if (!find_pack_entry(store, oid, &e))
                return 1;
 
        /*
@@ -2217,8 +2211,17 @@ struct packed_git **packfile_store_get_kept_pack_cache(struct packfile_store *st
 
 int has_object_pack(struct repository *r, const struct object_id *oid)
 {
+       struct odb_source *source;
        struct pack_entry e;
-       return find_pack_entry(r, oid, &e);
+
+       odb_prepare_alternates(r->objects);
+       for (source = r->objects->sources; source; source = source->next) {
+               int ret = find_pack_entry(source->packfiles, oid, &e);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
 }
 
 int has_object_kept_pack(struct repository *r, const struct object_id *oid,