midx: drop redundant `struct repository` parameter

There are a couple of functions that take both a `struct repository` and a `struct multi_pack_index`. This provides redundant information though without much benefit given that the multi-pack index already has a pointer to its owning repository. Drop the `struct repository` parameter from such functions. While at it, reorder the list of parameters of `fill_midx_entry()` so that the MIDX comes first to better align with our coding guidelines. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 11, 2025 at 15:46 UTC 9ff212961506679c1e2c1541b17ab2bd8563ff15
7 files changed +26 -28
builtin/pack-objects.c
+1 -1
@@ -1733,7 +1733,7 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
1733 struct multi_pack_index *m = get_multi_pack_index(source);
1734 struct pack_entry e;
1735
1736 - if (m && fill_midx_entry(the_repository, oid, &e, m)) {
1736 + if (m && fill_midx_entry(m, oid, &e)) {
1737 want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime);
1738 if (want != -1)
1739 return want;
midx-write.c
+7 -9
@@ -942,8 +942,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,
942 */
943 if (flags & MIDX_WRITE_REV_INDEX ||
944 preferred_pack_name) {
945 - if (prepare_midx_pack(ctx->repo, m,
946 - m->num_packs_in_base + i)) {
945 + if (prepare_midx_pack(m, m->num_packs_in_base + i)) {
946 error(_("could not load pack"));
947 return 1;
948 }
@@ -1566,7 +1565,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
1565 if (count[i])
1566 continue;
1567
1569 - if (prepare_midx_pack(r, m, i))
1568 + if (prepare_midx_pack(m, i))
1569 continue;
1570
1571 if (m->packs[i]->pack_keep || m->packs[i]->is_cruft)
@@ -1612,13 +1611,12 @@ static int compare_by_mtime(const void *a_, const void *b_)
1611 return 0;
1612 }
1613
1615 -static int want_included_pack(struct repository *r,
1616 - struct multi_pack_index *m,
1614 +static int want_included_pack(struct multi_pack_index *m,
1615 int pack_kept_objects,
1616 uint32_t pack_int_id)
1617 {
1618 struct packed_git *p;
1621 - if (prepare_midx_pack(r, m, pack_int_id))
1619 + if (prepare_midx_pack(m, pack_int_id))
1620 return 0;
1621 p = m->packs[pack_int_id];
1622 if (!pack_kept_objects && p->pack_keep)
@@ -1640,7 +1638,7 @@ static void fill_included_packs_all(struct repository *r,
1638 repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
1639
1640 for (i = 0; i < m->num_packs; i++) {
1643 - if (!want_included_pack(r, m, pack_kept_objects, i))
1641 + if (!want_included_pack(m, pack_kept_objects, i))
1642 continue;
1643
1644 include_pack[i] = 1;
@@ -1664,7 +1662,7 @@ static void fill_included_packs_batch(struct repository *r,
1662 for (i = 0; i < m->num_packs; i++) {
1663 pack_info[i].pack_int_id = i;
1664
1667 - if (prepare_midx_pack(r, m, i))
1665 + if (prepare_midx_pack(m, i))
1666 continue;
1667
1668 pack_info[i].mtime = m->packs[i]->mtime;
@@ -1683,7 +1681,7 @@ static void fill_included_packs_batch(struct repository *r,
1681 struct packed_git *p = m->packs[pack_int_id];
1682 uint64_t expected_size;
1683
1686 - if (!want_included_pack(r, m, pack_kept_objects, pack_int_id))
1684 + if (!want_included_pack(m, pack_kept_objects, pack_int_id))
1685 continue;
1686
1687 /*
midx.c
+9 -9
@@ -450,9 +450,10 @@ static uint32_t midx_for_pack(struct multi_pack_index **_m,
450 return pack_int_id - m->num_packs_in_base;
451 }
452
453 -int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
453 +int prepare_midx_pack(struct multi_pack_index *m,
454 uint32_t pack_int_id)
455 {
456 + struct repository *r = m->repo;
457 struct strbuf pack_name = STRBUF_INIT;
458 struct strbuf key = STRBUF_INIT;
459 struct packed_git *p;
@@ -507,7 +508,7 @@ struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
508
509 #define MIDX_CHUNK_BITMAPPED_PACKS_WIDTH (2 * sizeof(uint32_t))
510
510 -int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
511 +int nth_bitmapped_pack(struct multi_pack_index *m,
512 struct bitmapped_pack *bp, uint32_t pack_int_id)
513 {
514 uint32_t local_pack_int_id = midx_for_pack(&m, pack_int_id);
@@ -515,7 +516,7 @@ int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
516 if (!m->chunk_bitmapped_packs)
517 return error(_("MIDX does not contain the BTMP chunk"));
518
518 - if (prepare_midx_pack(r, m, pack_int_id))
519 + if (prepare_midx_pack(m, pack_int_id))
520 return error(_("could not load bitmapped pack %"PRIu32), pack_int_id);
521
522 bp->p = m->packs[local_pack_int_id];
@@ -600,10 +601,9 @@ uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
601 (off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
602 }
603
603 -int fill_midx_entry(struct repository *r,
604 +int fill_midx_entry(struct multi_pack_index *m,
605 const struct object_id *oid,
605 - struct pack_entry *e,
606 - struct multi_pack_index *m)
606 + struct pack_entry *e)
607 {
608 uint32_t pos;
609 uint32_t pack_int_id;
@@ -615,7 +615,7 @@ int fill_midx_entry(struct repository *r,
615 midx_for_object(&m, pos);
616 pack_int_id = nth_midxed_pack_int_id(m, pos);
617
618 - if (prepare_midx_pack(r, m, pack_int_id))
618 + if (prepare_midx_pack(m, pack_int_id))
619 return 0;
620 p = m->packs[pack_int_id - m->num_packs_in_base];
621
@@ -912,7 +912,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
912 _("Looking for referenced packfiles"),
913 m->num_packs + m->num_packs_in_base);
914 for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
915 - if (prepare_midx_pack(r, m, i))
915 + if (prepare_midx_pack(m, i))
916 midx_report("failed to load pack in position %d", i);
917
918 display_progress(progress, i + 1);
@@ -989,7 +989,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
989
990 nth_midxed_object_oid(&oid, m, pairs[i].pos);
991
992 - if (!fill_midx_entry(r, &oid, &e, m)) {
992 + if (!fill_midx_entry(m, &oid, &e)) {
993 midx_report(_("failed to load pack entry for oid[%d] = %s"),
994 pairs[i].pos, oid_to_hex(&oid));
995 continue;
midx.h
+3 -3
@@ -103,10 +103,10 @@ void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,
103 struct multi_pack_index *load_multi_pack_index(struct repository *r,
104 const char *object_dir,
105 int local);
106 -int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
106 +int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
107 struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
108 uint32_t pack_int_id);
109 -int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
109 +int nth_bitmapped_pack(struct multi_pack_index *m,
110 struct bitmapped_pack *bp, uint32_t pack_int_id);
111 int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
112 uint32_t *result);
@@ -118,7 +118,7 @@ uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos);
118 struct object_id *nth_midxed_object_oid(struct object_id *oid,
119 struct multi_pack_index *m,
120 uint32_t n);
121 -int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
121 +int fill_midx_entry(struct multi_pack_index *m, const struct object_id *oid, struct pack_entry *e);
122 int midx_contains_pack(struct multi_pack_index *m,
123 const char *idx_or_pack_name);
124 int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
pack-bitmap.c
+2 -2
@@ -493,7 +493,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
493 }
494
495 for (i = 0; i < bitmap_git->midx->num_packs + bitmap_git->midx->num_packs_in_base; i++) {
496 - if (prepare_midx_pack(bitmap_repo(bitmap_git), bitmap_git->midx, i)) {
496 + if (prepare_midx_pack(bitmap_git->midx, i)) {
497 warning(_("could not open pack %s"),
498 bitmap_git->midx->pack_names[i]);
499 goto cleanup;
@@ -2466,7 +2466,7 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2466 struct multi_pack_index *m = bitmap_git->midx;
2467 for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
2468 struct bitmapped_pack pack;
2469 - if (nth_bitmapped_pack(r, bitmap_git->midx, &pack, i) < 0) {
2469 + if (nth_bitmapped_pack(bitmap_git->midx, &pack, i) < 0) {
2470 warning(_("unable to load pack: '%s', disabling pack-reuse"),
2471 bitmap_git->midx->pack_names[i]);
2472 free(packs);
packfile.c
+2 -2
@@ -1091,7 +1091,7 @@ struct packed_git *get_all_packs(struct repository *r)
1091 if (!m)
1092 continue;
1093 for (uint32_t i = 0; i < m->num_packs + m->num_packs_in_base; i++)
1094 - prepare_midx_pack(r, m, i);
1094 + prepare_midx_pack(m, i);
1095 }
1096
1097 return r->objects->packed_git;
@@ -2077,7 +2077,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
2077 prepare_packed_git(r);
2078
2079 for (struct odb_source *source = r->objects->sources; source; source = source->next)
2080 - if (source->midx && fill_midx_entry(r, oid, e, source->midx))
2080 + if (source->midx && fill_midx_entry(source->midx, oid, e))
2081 return 1;
2082
2083 if (!r->objects->packed_git)
t/helper/test-read-midx.c
+2 -2
@@ -65,7 +65,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
65 for (i = 0; i < m->num_objects; i++) {
66 nth_midxed_object_oid(&oid, m,
67 i + m->num_objects_in_base);
68 - fill_midx_entry(the_repository, &oid, &e, m);
68 + fill_midx_entry(m, &oid, &e);
69
70 printf("%s %"PRIu64"\t%s\n",
71 oid_to_hex(&oid), e.offset, e.p->pack_name);
@@ -126,7 +126,7 @@ static int read_midx_bitmapped_packs(const char *object_dir)
126 return 1;
127
128 for (i = 0; i < midx->num_packs + midx->num_packs_in_base; i++) {
129 - if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) {
129 + if (nth_bitmapped_pack(midx, &pack, i) < 0) {
130 close_midx(midx);
131 return 1;
132 }