]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: introduce macro to iterate through packs
authorPatrick Steinhardt <ps@pks.im>
Thu, 9 Oct 2025 08:01:39 +0000 (10:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Oct 2025 21:42:39 +0000 (14:42 -0700)
We have a bunch of different sites that want to iterate through all
packs of a given `struct packfile_store`. This pattern is somewhat
verbose and repetitive, which makes it somewhat cumbersome.

Introduce a new macro `repo_for_each_pack()` that removes some of the
boilerplate.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
20 files changed:
builtin/cat-file.c
builtin/count-objects.c
builtin/fsck.c
builtin/gc.c
builtin/pack-objects.c
builtin/pack-redundant.c
connected.c
http-backend.c
http.c
object-name.c
pack-bitmap.c
pack-objects.c
packfile.c
packfile.h
repack-cruft.c
repack-geometry.c
repack.c
server-info.c
t/helper/test-find-pack.c
t/helper/test-pack-mtimes.c

index ee6715fa523ce6094dd65a83b2f8b413f3854a87..0ab076aeb30ad98e2e58dc7b444f1ea722202a89 100644 (file)
@@ -852,10 +852,9 @@ static void batch_each_object(struct batch_options *opt,
 
        if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter,
                                                 batch_one_object_bitmapped, &payload)) {
-               struct packfile_store *packs = the_repository->objects->packfiles;
                struct packed_git *pack;
 
-               for (pack = packfile_store_get_all_packs(packs); pack; pack = pack->next) {
+               repo_for_each_pack(the_repository, pack) {
                        if (bitmap_index_contains_pack(bitmap, pack) ||
                            open_pack_index(pack))
                                continue;
index f2f407c2a7818334d9fce189228a76aac0c245f7..18f6e33b6f913f9a5a4e4656bd9bdbf2c040a42a 100644 (file)
@@ -122,7 +122,6 @@ int cmd_count_objects(int argc,
                                      count_loose, count_cruft, NULL, NULL);
 
        if (verbose) {
-               struct packfile_store *packs = the_repository->objects->packfiles;
                struct packed_git *p;
                unsigned long num_pack = 0;
                off_t size_pack = 0;
@@ -130,7 +129,7 @@ int cmd_count_objects(int argc,
                struct strbuf pack_buf = STRBUF_INIT;
                struct strbuf garbage_buf = STRBUF_INIT;
 
-               for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+               repo_for_each_pack(the_repository, p) {
                        if (!p->pack_local)
                                continue;
                        if (open_pack_index(p))
index 8ee95e0d67cf374b9814c92558ce969796300a7b..b1a650c6731d3268c65c2204af1975fe23e6d226 100644 (file)
@@ -867,20 +867,20 @@ static int mark_packed_for_connectivity(const struct object_id *oid,
 
 static int check_pack_rev_indexes(struct repository *r, int show_progress)
 {
-       struct packfile_store *packs = r->objects->packfiles;
        struct progress *progress = NULL;
+       struct packed_git *p;
        uint32_t pack_count = 0;
        int res = 0;
 
        if (show_progress) {
-               for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next)
+               repo_for_each_pack(r, p)
                        pack_count++;
                progress = start_delayed_progress(the_repository,
                                                  "Verifying reverse pack-indexes", pack_count);
                pack_count = 0;
        }
 
-       for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(r, p) {
                int load_error = load_pack_revindex_from_disk(p);
 
                if (load_error < 0) {
@@ -1000,8 +1000,6 @@ int cmd_fsck(int argc,
                for_each_packed_object(the_repository,
                                       mark_packed_for_connectivity, NULL, 0);
        } else {
-               struct packfile_store *packs = the_repository->objects->packfiles;
-
                odb_prepare_alternates(the_repository->objects);
                for (source = the_repository->objects->sources; source; source = source->next)
                        fsck_source(source);
@@ -1012,8 +1010,7 @@ int cmd_fsck(int argc,
                        struct progress *progress = NULL;
 
                        if (show_progress) {
-                               for (p = packfile_store_get_all_packs(packs); p;
-                                    p = p->next) {
+                               repo_for_each_pack(the_repository, p) {
                                        if (open_pack_index(p))
                                                continue;
                                        total += p->num_objects;
@@ -1022,8 +1019,8 @@ int cmd_fsck(int argc,
                                progress = start_progress(the_repository,
                                                          _("Checking objects"), total);
                        }
-                       for (p = packfile_store_get_all_packs(packs); p;
-                            p = p->next) {
+
+                       repo_for_each_pack(the_repository, p) {
                                /* verify gives error messages itself */
                                if (verify_pack(the_repository,
                                                p, fsck_obj_buffer,
index ab6d6d3bd1b4455059515e21dd841a5a07690e51..541d7471f190728c5ca3100ae129572d02497e50 100644 (file)
@@ -487,10 +487,9 @@ static int too_many_loose_objects(struct gc_config *cfg)
 static struct packed_git *find_base_packs(struct string_list *packs,
                                          unsigned long limit)
 {
-       struct packfile_store *packfiles = the_repository->objects->packfiles;
        struct packed_git *p, *base = NULL;
 
-       for (p = packfile_store_get_all_packs(packfiles); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                if (!p->pack_local || p->is_cruft)
                        continue;
                if (limit) {
@@ -509,14 +508,13 @@ static struct packed_git *find_base_packs(struct string_list *packs,
 
 static int too_many_packs(struct gc_config *cfg)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct packed_git *p;
-       int cnt;
+       int cnt = 0;
 
        if (cfg->gc_auto_pack_limit <= 0)
                return 0;
 
-       for (cnt = 0, p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                if (!p->pack_local)
                        continue;
                if (p->pack_keep)
@@ -1425,9 +1423,9 @@ static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED)
        if (incremental_repack_auto_limit < 0)
                return 1;
 
-       for (p = packfile_store_get_all_packs(the_repository->objects->packfiles);
-            count < incremental_repack_auto_limit && p;
-            p = p->next) {
+       repo_for_each_pack(the_repository, p) {
+               if (count >= incremental_repack_auto_limit)
+                       break;
                if (!p->multi_pack_index)
                        count++;
        }
@@ -1494,7 +1492,7 @@ static off_t get_auto_pack_size(void)
        struct repository *r = the_repository;
 
        odb_reprepare(r->objects);
-       for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) {
+       repo_for_each_pack(r, p) {
                if (p->pack_size > max_size) {
                        second_largest_size = max_size;
                        max_size = p->pack_size;
index fe987fbb8b6375368104ed72174c534895069405..50618e1073ed99adf41c6a55bf2c2c0de95e1559 100644 (file)
@@ -3831,12 +3831,10 @@ static int pack_mtime_cmp(const void *_a, const void *_b)
 
 static void read_packs_list_from_stdin(struct rev_info *revs)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct strbuf buf = STRBUF_INIT;
        struct string_list include_packs = STRING_LIST_INIT_DUP;
        struct string_list exclude_packs = STRING_LIST_INIT_DUP;
        struct string_list_item *item = NULL;
-
        struct packed_git *p;
 
        while (strbuf_getline(&buf, stdin) != EOF) {
@@ -3856,7 +3854,7 @@ static void read_packs_list_from_stdin(struct rev_info *revs)
        string_list_sort(&exclude_packs);
        string_list_remove_duplicates(&exclude_packs, 0);
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                const char *pack_name = pack_basename(p);
 
                if ((item = string_list_lookup(&include_packs, pack_name)))
@@ -4077,7 +4075,6 @@ static void enumerate_cruft_objects(void)
 
 static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct packed_git *p;
        struct rev_info revs;
        int ret;
@@ -4107,7 +4104,7 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
         * Re-mark only the fresh packs as kept so that objects in
         * unknown packs do not halt the reachability traversal early.
         */
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next)
+       repo_for_each_pack(the_repository, p)
                p->pack_keep_in_core = 0;
        mark_pack_kept_in_core(fresh_packs, 1);
 
@@ -4124,7 +4121,6 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
 
 static void read_cruft_objects(void)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct strbuf buf = STRBUF_INIT;
        struct string_list discard_packs = STRING_LIST_INIT_DUP;
        struct string_list fresh_packs = STRING_LIST_INIT_DUP;
@@ -4145,7 +4141,7 @@ static void read_cruft_objects(void)
        string_list_sort(&discard_packs);
        string_list_sort(&fresh_packs);
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                const char *pack_name = pack_basename(p);
                struct string_list_item *item;
 
@@ -4440,13 +4436,12 @@ static int loosened_object_can_be_discarded(const struct object_id *oid,
 
 static void loosen_unused_packed_objects(void)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct packed_git *p;
        uint32_t i;
        uint32_t loosened_objects_nr = 0;
        struct object_id oid;
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                if (!p->pack_local || p->pack_keep || p->pack_keep_in_core)
                        continue;
 
@@ -4747,13 +4742,12 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
 
 static void add_extra_kept_packs(const struct string_list *names)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct packed_git *p;
 
        if (!names->nr)
                return;
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                const char *name = basename(p->pack_name);
                int i;
 
@@ -5191,10 +5185,9 @@ int cmd_pack_objects(int argc,
 
        add_extra_kept_packs(&keep_pack_list);
        if (ignore_packed_keep_on_disk) {
-               struct packfile_store *packs = the_repository->objects->packfiles;
                struct packed_git *p;
 
-               for (p = packfile_store_get_all_packs(packs); p; p = p->next)
+               repo_for_each_pack(the_repository, p)
                        if (p->pack_local && p->pack_keep)
                                break;
                if (!p) /* no keep-able packs found */
@@ -5206,10 +5199,9 @@ int cmd_pack_objects(int argc,
                 * want to unset "local" based on looking at packs, as
                 * it also covers non-local objects
                 */
-               struct packfile_store *packs = the_repository->objects->packfiles;
                struct packed_git *p;
 
-               for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+               repo_for_each_pack(the_repository, p) {
                        if (!p->pack_local) {
                                have_non_local_packs = 1;
                                break;
index dd28171f0a179a156c4e48c82dd444bde5a7995a..fca7f195d6d4e0295166763580e78d9ffcc78fc3 100644 (file)
@@ -566,29 +566,23 @@ static struct pack_list * add_pack(struct packed_git *p)
 
 static struct pack_list * add_pack_file(const char *filename)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
-       struct packed_git *p = packfile_store_get_all_packs(packs);
+       struct packed_git *p;
 
        if (strlen(filename) < 40)
                die("Bad pack filename: %s", filename);
 
-       while (p) {
+       repo_for_each_pack(the_repository, p)
                if (strstr(p->pack_name, filename))
                        return add_pack(p);
-               p = p->next;
-       }
        die("Filename %s not found in packed_git", filename);
 }
 
 static void load_all(void)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
-       struct packed_git *p = packfile_store_get_all_packs(packs);
+       struct packed_git *p;
 
-       while (p) {
+       repo_for_each_pack(the_repository, p)
                add_pack(p);
-               p = p->next;
-       }
 }
 
 int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {
index b288a18b17c33fcead8b14947dfce38276c3d093..79403108dd8f574af7fcdb478975b17ceba76d25 100644 (file)
@@ -74,10 +74,9 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
                 */
                odb_reprepare(the_repository->objects);
                do {
-                       struct packfile_store *packs = the_repository->objects->packfiles;
                        struct packed_git *p;
 
-                       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+                       repo_for_each_pack(the_repository, p) {
                                if (!p->pack_promisor)
                                        continue;
                                if (find_pack_entry_one(oid, p))
index 9084058f1e9f138bda8525ce6db52df24b2fa95e..52f0483dd309d73a1866a1b63161df0fe63d389f 100644 (file)
@@ -603,19 +603,18 @@ static void get_head(struct strbuf *hdr, char *arg UNUSED)
 static void get_info_packs(struct strbuf *hdr, char *arg UNUSED)
 {
        size_t objdirlen = strlen(repo_get_object_directory(the_repository));
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct strbuf buf = STRBUF_INIT;
        struct packed_git *p;
        size_t cnt = 0;
 
        select_getanyfile(hdr);
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                if (p->pack_local)
                        cnt++;
        }
 
        strbuf_grow(&buf, cnt * 53 + 2);
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                if (p->pack_local)
                        strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
        }
diff --git a/http.c b/http.c
index 7e3af1e72f740124462a6de7901f9346b607b0e2..17130823f006f2cc351a186cba0030d4c08769bc 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2416,7 +2416,6 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url)
 static int fetch_and_setup_pack_index(struct packed_git **packs_head,
        unsigned char *sha1, const char *base_url)
 {
-       struct packfile_store *packs = the_repository->objects->packfiles;
        struct packed_git *new_pack, *p;
        char *tmp_idx = NULL;
        int ret;
@@ -2425,7 +2424,7 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
         * If we already have the pack locally, no need to fetch its index or
         * even add it to list; we already have all of its objects.
         */
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                if (hasheq(p->hash, sha1, the_repository->hash_algo))
                        return 0;
        }
index 4e62bfa330e5ab9e0d8699a683599fd7c7bb1f79..766c757042a38950f7b498dc7fa92b72befea264 100644 (file)
@@ -213,9 +213,11 @@ static void find_short_packed_object(struct disambiguate_state *ds)
                        unique_in_midx(m, ds);
        }
 
-       for (p = packfile_store_get_all_packs(ds->repo->objects->packfiles); p && !ds->ambiguous;
-            p = p->next)
+       repo_for_each_pack(ds->repo, p) {
+               if (ds->ambiguous)
+                       break;
                unique_in_pack(p, ds);
+       }
 }
 
 static int finish_object_disambiguation(struct disambiguate_state *ds,
@@ -805,7 +807,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
                        find_abbrev_len_for_midx(m, mad);
        }
 
-       for (p = packfile_store_get_all_packs(mad->repo->objects->packfiles); p; p = p->next)
+       repo_for_each_pack(mad->repo, p)
                find_abbrev_len_for_pack(p, mad);
 }
 
index ac71035d7715f7f9a86468fd2754bb5283a80e41..291e1a9cf471583aeed5b928288ca6c2f5d1ceaa 100644 (file)
@@ -664,7 +664,7 @@ static int open_pack_bitmap(struct repository *r,
        struct packed_git *p;
        int ret = -1;
 
-       for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) {
+       repo_for_each_pack(r, p) {
                if (open_pack_bitmap_1(bitmap_git, p) == 0) {
                        ret = 0;
                        /*
@@ -3347,6 +3347,7 @@ static int verify_bitmap_file(const struct git_hash_algo *algop,
 int verify_bitmap_files(struct repository *r)
 {
        struct odb_source *source;
+       struct packed_git *p;
        int res = 0;
 
        odb_prepare_alternates(r->objects);
@@ -3362,8 +3363,7 @@ int verify_bitmap_files(struct repository *r)
                free(midx_bitmap_name);
        }
 
-       for (struct packed_git *p = packfile_store_get_all_packs(r->objects->packfiles);
-            p; p = p->next) {
+       repo_for_each_pack(r, p) {
                char *pack_bitmap_name = pack_bitmap_filename(p);
                res |= verify_bitmap_file(r->hash_algo, pack_bitmap_name);
                free(pack_bitmap_name);
index d8eb679735484a17196ba9d77ac6c8c7bfff2536..d6adf0759ccd77baa97c8b99e77fd7ac75921939 100644 (file)
@@ -86,7 +86,6 @@ struct object_entry *packlist_find(struct packing_data *pdata,
 
 static void prepare_in_pack_by_idx(struct packing_data *pdata)
 {
-       struct packfile_store *packs = pdata->repo->objects->packfiles;
        struct packed_git **mapping, *p;
        int cnt = 0, nr = 1U << OE_IN_PACK_BITS;
 
@@ -96,13 +95,13 @@ static void prepare_in_pack_by_idx(struct packing_data *pdata)
         * (i.e. in_pack_idx also zero) should return NULL.
         */
        mapping[cnt++] = NULL;
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next, cnt++) {
+       repo_for_each_pack(pdata->repo, p) {
                if (cnt == nr) {
                        free(mapping);
                        return;
                }
                p->index = cnt;
-               mapping[cnt] = p;
+               mapping[cnt++] = p;
        }
        pdata->in_pack_by_idx = mapping;
 }
index db748b0bd48c2716d71a4c8b7fedb38a43e90a8f..ab5859518d45ea17a434dd2258c0882679886cec 100644 (file)
@@ -2099,7 +2099,7 @@ struct packed_git **kept_pack_cache(struct repository *r, unsigned flags)
                 * covers, one kept and one not kept, but the midx returns only
                 * the non-kept version.
                 */
-               for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) {
+               repo_for_each_pack(r, p) {
                        if ((p->pack_keep && (flags & ON_DISK_KEEP_PACKS)) ||
                            (p->pack_keep_in_core && (flags & IN_CORE_KEEP_PACKS))) {
                                ALLOC_GROW(packs, nr + 1, alloc);
@@ -2196,7 +2196,7 @@ int for_each_packed_object(struct repository *repo, each_packed_object_fn cb,
        int r = 0;
        int pack_errors = 0;
 
-       for (p = packfile_store_get_all_packs(repo->objects->packfiles); p; p = p->next) {
+       repo_for_each_pack(repo, p) {
                if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
                        continue;
                if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&
index 3f38c63476dcc164346061b220c679d1d4c77723..49484a9b09b5816b1ac21eb423b837471c05467a 100644 (file)
@@ -136,6 +136,14 @@ void packfile_store_reprepare(struct packfile_store *store);
 void packfile_store_add_pack(struct packfile_store *store,
                             struct packed_git *pack);
 
+/*
+ * Load and iterate through all packs of the given repository. This helper
+ * function will yield packfiles from all object sources connected to the
+ * repository.
+ */
+#define repo_for_each_pack(repo, p) \
+       for (p = packfile_store_get_all_packs(repo->objects->packfiles); p; p = p->next)
+
 /*
  * Get all packs managed by the given store, including packfiles that are
  * referenced by multi-pack indices.
index c51df367226d63d03403cd8f1355338f536f17b8..0653e88792332eb7f26eb5df81afc497256f583b 100644 (file)
@@ -7,12 +7,11 @@
 static void combine_small_cruft_packs(FILE *in, off_t combine_cruft_below_size,
                                      struct existing_packs *existing)
 {
-       struct packfile_store *packs = existing->repo->objects->packfiles;
        struct packed_git *p;
        struct strbuf buf = STRBUF_INIT;
        size_t i;
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(existing->repo, p) {
                if (!(p->is_cruft && p->pack_local))
                        continue;
 
index e2f9794d7debcea37fb5b5ac1bb47cf334db341d..b3e32cd07ec119d8b28776eaf4ca193df92cafe1 100644 (file)
@@ -29,11 +29,10 @@ void pack_geometry_init(struct pack_geometry *geometry,
                        struct existing_packs *existing,
                        const struct pack_objects_args *args)
 {
-       struct packfile_store *packs = existing->repo->objects->packfiles;
        struct packed_git *p;
        struct strbuf buf = STRBUF_INIT;
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(existing->repo, p) {
                if (args->local && !p->pack_local)
                        /*
                         * When asked to only repack local packfiles we skip
index 2ab33c665aeec317256cf1f714cf52cc6b74f0fb..596841027af93f08ef5b222648bcc5bb30eb03c3 100644 (file)
--- a/repack.c
+++ b/repack.c
@@ -123,11 +123,10 @@ int finish_pack_objects_cmd(const struct git_hash_algo *algop,
 void existing_packs_collect(struct existing_packs *existing,
                            const struct string_list *extra_keep)
 {
-       struct packfile_store *packs = existing->repo->objects->packfiles;
        struct packed_git *p;
        struct strbuf buf = STRBUF_INIT;
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(existing->repo, p) {
                size_t i;
                const char *base;
 
index 1d33de821e9f5e5b470dd618127b8354fb580009..b9a710544ab2854879593961dc9b2fc3350435ea 100644 (file)
@@ -287,13 +287,12 @@ static int compare_info(const void *a_, const void *b_)
 
 static void init_pack_info(struct repository *r, const char *infofile, int force)
 {
-       struct packfile_store *packs = r->objects->packfiles;
        struct packed_git *p;
        int stale;
        int i;
        size_t alloc = 0;
 
-       for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
+       repo_for_each_pack(r, p) {
                /* we ignore things on alternate path since they are
                 * not available to the pullers in general.
                 */
index e001dc3066db70ed08da78f1566eb9f764d93619..fc4b8a77b3007a1f28d89fce94f579b4a6f45f9c 100644 (file)
@@ -39,11 +39,12 @@ int cmd__find_pack(int argc, const char **argv)
        if (repo_get_oid(the_repository, argv[0], &oid))
                die("cannot parse %s as an object name", argv[0]);
 
-       for (p = packfile_store_get_all_packs(the_repository->objects->packfiles); p; p = p->next)
+       repo_for_each_pack(the_repository, p) {
                if (find_pack_entry_one(&oid, p)) {
                        printf("%s\n", p->pack_name);
                        actual_count++;
                }
+       }
 
        if (count > -1 && count != actual_count)
                die("bad packfile count %d instead of %d", actual_count, count);
index 7c428c16011a23d18855e87865e1d21d99bb27e0..7a8ee1de24ba83c1593960868a1b4dfdc57c24fa 100644 (file)
@@ -37,7 +37,7 @@ int cmd__pack_mtimes(int argc, const char **argv)
        if (argc != 2)
                usage(pack_mtimes_usage);
 
-       for (p = packfile_store_get_all_packs(the_repository->objects->packfiles); p; p = p->next) {
+       repo_for_each_pack(the_repository, p) {
                strbuf_addstr(&buf, basename(p->pack_name));
                strbuf_strip_suffix(&buf, ".pack");
                strbuf_addstr(&buf, ".mtimes");