Skip to content

Commit 65308ad

Browse files
ttaylorrderrickstolee
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b77919e commit 65308ad

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

pack-bitmap.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
463463
return 0;
464464
}
465465

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)
467467
{
468468
if (bitmap_is_midx(bitmap_git)) {
469469
uint32_t i;
@@ -477,23 +477,23 @@ static int load_reverse_index(struct bitmap_index *bitmap_git)
477477
* since we will need to make use of them in pack-objects.
478478
*/
479479
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]);
481481
if (ret)
482482
return ret;
483483
}
484484
return 0;
485485
}
486-
return load_pack_revindex(bitmap_git->pack);
486+
return load_pack_revindex(r, bitmap_git->pack);
487487
}
488488

489-
static int load_bitmap(struct bitmap_index *bitmap_git)
489+
static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git)
490490
{
491491
assert(bitmap_git->map);
492492

493493
bitmap_git->bitmaps = kh_init_oid_map();
494494
bitmap_git->ext_index.positions = kh_init_oid_pos();
495495

496-
if (load_reverse_index(bitmap_git))
496+
if (load_reverse_index(r, bitmap_git))
497497
goto failed;
498498

499499
if (!(bitmap_git->commits = read_bitmap_1(bitmap_git)) ||
@@ -580,7 +580,7 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
580580
{
581581
struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
582582

583-
if (!open_bitmap(r, bitmap_git) && !load_bitmap(bitmap_git))
583+
if (!open_bitmap(r, bitmap_git) && !load_bitmap(r, bitmap_git))
584584
return bitmap_git;
585585

586586
free_bitmap_index(bitmap_git);
@@ -589,9 +589,10 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
589589

590590
struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx)
591591
{
592+
struct repository *r = the_repository;
592593
struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
593594

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))
595596
return bitmap_git;
596597

597598
free_bitmap_index(bitmap_git);
@@ -1592,7 +1593,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
15921593
* from disk. this is the point of no return; after this the rev_list
15931594
* becomes invalidated and we must perform the revwalk through bitmaps
15941595
*/
1595-
if (load_bitmap(bitmap_git) < 0)
1596+
if (load_bitmap(revs->repo, bitmap_git) < 0)
15961597
goto cleanup;
15971598

15981599
object_array_clear(&revs->pending);
@@ -1742,6 +1743,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
17421743
uint32_t *entries,
17431744
struct bitmap **reuse_out)
17441745
{
1746+
struct repository *r = the_repository;
17451747
struct packed_git *pack;
17461748
struct bitmap *result = bitmap_git->result;
17471749
struct bitmap *reuse;
@@ -1752,7 +1754,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
17521754

17531755
assert(result);
17541756

1755-
load_reverse_index(bitmap_git);
1757+
load_reverse_index(r, bitmap_git);
17561758

17571759
if (bitmap_is_midx(bitmap_git))
17581760
pack = bitmap_git->midx->packs[midx_preferred_pack(bitmap_git)];
@@ -2132,11 +2134,12 @@ int rebuild_bitmap(const uint32_t *reposition,
21322134
uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
21332135
struct packing_data *mapping)
21342136
{
2137+
struct repository *r = the_repository;
21352138
uint32_t i, num_objects;
21362139
uint32_t *reposition;
21372140

21382141
if (!bitmap_is_midx(bitmap_git))
2139-
load_reverse_index(bitmap_git);
2142+
load_reverse_index(r, bitmap_git);
21402143
else if (load_midx_revindex(bitmap_git->midx) < 0)
21412144
BUG("rebuild_existing_bitmaps: missing required rev-cache "
21422145
"extension");

pack-revindex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static int load_pack_revindex_from_disk(struct packed_git *p)
283283
return ret;
284284
}
285285

286-
int load_pack_revindex(struct packed_git *p)
286+
int load_pack_revindex(struct repository *r, struct packed_git *p)
287287
{
288288
if (p->revindex || p->revindex_data)
289289
return 0;
@@ -356,7 +356,7 @@ int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
356356
{
357357
unsigned lo, hi;
358358

359-
if (load_pack_revindex(p) < 0)
359+
if (load_pack_revindex(the_repository, p) < 0)
360360
return -1;
361361

362362
lo = 0;

pack-revindex.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
struct packed_git;
4141
struct multi_pack_index;
42+
struct repository;
4243

4344
/*
4445
* load_pack_revindex populates the revindex's internal data-structures for the
@@ -47,7 +48,7 @@ struct multi_pack_index;
4748
* If a '.rev' file is present it is mmap'd, and pointers are assigned into it
4849
* (instead of using the in-memory variant).
4950
*/
50-
int load_pack_revindex(struct packed_git *p);
51+
int load_pack_revindex(struct repository *r, struct packed_git *p);
5152

5253
/*
5354
* load_midx_revindex loads the '.rev' file corresponding to the given

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ int for_each_object_in_pack(struct packed_git *p,
21512151
int r = 0;
21522152

21532153
if (flags & FOR_EACH_OBJECT_PACK_ORDER) {
2154-
if (load_pack_revindex(p))
2154+
if (load_pack_revindex(the_repository, p))
21552155
return -1;
21562156
}
21572157

0 commit comments

Comments
 (0)