pack-revindex: make `load_pack_revindex` take a repository

In a future commit, we will introduce a `pack.readReverseIndex` configuration, which forces Git to generate the reverse index from scratch instead of loading it from disk. In order to avoid reading this configuration value more than once, we'll use the `repo_settings` struct to lazily load this value. In order to access the `struct repo_settings`, add a repository argument to `load_pack_revindex`, and update all callers to pass the correct instance (in all cases, `the_repository`). In certain instances, a new function-local variable is introduced to take the place of a `struct repository *` argument to the function itself to avoid propagating the new parameter even further throughout the tree. Co-authored-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Acked-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 12, 2023 at 18:20 UTC 65308ad8f757a823ccf3175609d580da5f767a15
4 files changed +18 -14
pack-bitmap.c
+13 -10
@@ -463,7 +463,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
463 return 0;
464 }
465
466 -static int load_reverse_index(struct bitmap_index *bitmap_git)
466 +static int load_reverse_index(struct repository *r, struct bitmap_index *bitmap_git)
467 {
468 if (bitmap_is_midx(bitmap_git)) {
469 uint32_t i;
@@ -477,23 +477,23 @@ static int load_reverse_index(struct bitmap_index *bitmap_git)
477 * since we will need to make use of them in pack-objects.
478 */
479 for (i = 0; i < bitmap_git->midx->num_packs; i++) {
480 - ret = load_pack_revindex(bitmap_git->midx->packs[i]);
480 + ret = load_pack_revindex(r, bitmap_git->midx->packs[i]);
481 if (ret)
482 return ret;
483 }
484 return 0;
485 }
486 - return load_pack_revindex(bitmap_git->pack);
486 + return load_pack_revindex(r, bitmap_git->pack);
487 }
488
489 -static int load_bitmap(struct bitmap_index *bitmap_git)
489 +static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git)
490 {
491 assert(bitmap_git->map);
492
493 bitmap_git->bitmaps = kh_init_oid_map();
494 bitmap_git->ext_index.positions = kh_init_oid_pos();
495
496 - if (load_reverse_index(bitmap_git))
496 + if (load_reverse_index(r, bitmap_git))
497 goto failed;
498
499 if (!(bitmap_git->commits = read_bitmap_1(bitmap_git)) ||
@@ -580,7 +580,7 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
580 {
581 struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
582
583 - if (!open_bitmap(r, bitmap_git) && !load_bitmap(bitmap_git))
583 + if (!open_bitmap(r, bitmap_git) && !load_bitmap(r, bitmap_git))
584 return bitmap_git;
585
586 free_bitmap_index(bitmap_git);
@@ -589,9 +589,10 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
589
590 struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx)
591 {
592 + struct repository *r = the_repository;
593 struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
594
594 - if (!open_midx_bitmap_1(bitmap_git, midx) && !load_bitmap(bitmap_git))
595 + if (!open_midx_bitmap_1(bitmap_git, midx) && !load_bitmap(r, bitmap_git))
596 return bitmap_git;
597
598 free_bitmap_index(bitmap_git);
@@ -1592,7 +1593,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
1593 * from disk. this is the point of no return; after this the rev_list
1594 * becomes invalidated and we must perform the revwalk through bitmaps
1595 */
1595 - if (load_bitmap(bitmap_git) < 0)
1596 + if (load_bitmap(revs->repo, bitmap_git) < 0)
1597 goto cleanup;
1598
1599 object_array_clear(&revs->pending);
@@ -1742,6 +1743,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
1743 uint32_t *entries,
1744 struct bitmap **reuse_out)
1745 {
1746 + struct repository *r = the_repository;
1747 struct packed_git *pack;
1748 struct bitmap *result = bitmap_git->result;
1749 struct bitmap *reuse;
@@ -1752,7 +1754,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
1754
1755 assert(result);
1756
1755 - load_reverse_index(bitmap_git);
1757 + load_reverse_index(r, bitmap_git);
1758
1759 if (bitmap_is_midx(bitmap_git))
1760 pack = bitmap_git->midx->packs[midx_preferred_pack(bitmap_git)];
@@ -2132,11 +2134,12 @@ int rebuild_bitmap(const uint32_t *reposition,
2134 uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
2135 struct packing_data *mapping)
2136 {
2137 + struct repository *r = the_repository;
2138 uint32_t i, num_objects;
2139 uint32_t *reposition;
2140
2141 if (!bitmap_is_midx(bitmap_git))
2139 - load_reverse_index(bitmap_git);
2142 + load_reverse_index(r, bitmap_git);
2143 else if (load_midx_revindex(bitmap_git->midx) < 0)
2144 BUG("rebuild_existing_bitmaps: missing required rev-cache "
2145 "extension");
pack-revindex.c
+2 -2
@@ -283,7 +283,7 @@ cleanup:
283 return ret;
284 }
285
286 -int load_pack_revindex(struct packed_git *p)
286 +int load_pack_revindex(struct repository *r, struct packed_git *p)
287 {
288 if (p->revindex || p->revindex_data)
289 return 0;
@@ -356,7 +356,7 @@ int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
356 {
357 unsigned lo, hi;
358
359 - if (load_pack_revindex(p) < 0)
359 + if (load_pack_revindex(the_repository, p) < 0)
360 return -1;
361
362 lo = 0;
pack-revindex.h
+2 -1
@@ -39,6 +39,7 @@
39
40 struct packed_git;
41 struct multi_pack_index;
42 +struct repository;
43
44 /*
45 * load_pack_revindex populates the revindex's internal data-structures for the
@@ -47,7 +48,7 @@ struct multi_pack_index;
48 * If a '.rev' file is present it is mmap'd, and pointers are assigned into it
49 * (instead of using the in-memory variant).
50 */
50 -int load_pack_revindex(struct packed_git *p);
51 +int load_pack_revindex(struct repository *r, struct packed_git *p);
52
53 /*
54 * load_midx_revindex loads the '.rev' file corresponding to the given
packfile.c
+1 -1
@@ -2151,7 +2151,7 @@ int for_each_object_in_pack(struct packed_git *p,
2151 int r = 0;
2152
2153 if (flags & FOR_EACH_OBJECT_PACK_ORDER) {
2154 - if (load_pack_revindex(p))
2154 + if (load_pack_revindex(the_repository, p))
2155 return -1;
2156 }
2157