Skip to content

Commit b3a99a2

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 91969fd commit b3a99a2

File tree

7 files changed

+26
-28
lines changed

7 files changed

+26
-28
lines changed

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17331733
struct multi_pack_index *m = get_multi_pack_index(source);
17341734
struct pack_entry e;
17351735

1736-
if (m && fill_midx_entry(the_repository, oid, &e, m)) {
1736+
if (m && fill_midx_entry(m, oid, &e)) {
17371737
want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime);
17381738
if (want != -1)
17391739
return want;

midx-write.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,
944944
*/
945945
if (flags & MIDX_WRITE_REV_INDEX ||
946946
preferred_pack_name) {
947-
if (prepare_midx_pack(ctx->repo, m,
948-
m->num_packs_in_base + i)) {
947+
if (prepare_midx_pack(m, m->num_packs_in_base + i)) {
949948
error(_("could not load pack"));
950949
return 1;
951950
}
@@ -1568,7 +1567,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
15681567
if (count[i])
15691568
continue;
15701569

1571-
if (prepare_midx_pack(r, m, i))
1570+
if (prepare_midx_pack(m, i))
15721571
continue;
15731572

15741573
if (m->packs[i]->pack_keep || m->packs[i]->is_cruft)
@@ -1614,13 +1613,12 @@ static int compare_by_mtime(const void *a_, const void *b_)
16141613
return 0;
16151614
}
16161615

1617-
static int want_included_pack(struct repository *r,
1618-
struct multi_pack_index *m,
1616+
static int want_included_pack(struct multi_pack_index *m,
16191617
int pack_kept_objects,
16201618
uint32_t pack_int_id)
16211619
{
16221620
struct packed_git *p;
1623-
if (prepare_midx_pack(r, m, pack_int_id))
1621+
if (prepare_midx_pack(m, pack_int_id))
16241622
return 0;
16251623
p = m->packs[pack_int_id];
16261624
if (!pack_kept_objects && p->pack_keep)
@@ -1642,7 +1640,7 @@ static void fill_included_packs_all(struct repository *r,
16421640
repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
16431641

16441642
for (i = 0; i < m->num_packs; i++) {
1645-
if (!want_included_pack(r, m, pack_kept_objects, i))
1643+
if (!want_included_pack(m, pack_kept_objects, i))
16461644
continue;
16471645

16481646
include_pack[i] = 1;
@@ -1666,7 +1664,7 @@ static void fill_included_packs_batch(struct repository *r,
16661664
for (i = 0; i < m->num_packs; i++) {
16671665
pack_info[i].pack_int_id = i;
16681666

1669-
if (prepare_midx_pack(r, m, i))
1667+
if (prepare_midx_pack(m, i))
16701668
continue;
16711669

16721670
pack_info[i].mtime = m->packs[i]->mtime;
@@ -1685,7 +1683,7 @@ static void fill_included_packs_batch(struct repository *r,
16851683
struct packed_git *p = m->packs[pack_int_id];
16861684
uint64_t expected_size;
16871685

1688-
if (!want_included_pack(r, m, pack_kept_objects, pack_int_id))
1686+
if (!want_included_pack(m, pack_kept_objects, pack_int_id))
16891687
continue;
16901688

16911689
/*

midx.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,10 @@ static uint32_t midx_for_pack(struct multi_pack_index **_m,
450450
return pack_int_id - m->num_packs_in_base;
451451
}
452452

453-
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
453+
int prepare_midx_pack(struct multi_pack_index *m,
454454
uint32_t pack_int_id)
455455
{
456+
struct repository *r = m->repo;
456457
struct strbuf pack_name = STRBUF_INIT;
457458
struct strbuf key = STRBUF_INIT;
458459
struct packed_git *p;
@@ -507,15 +508,15 @@ struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
507508

508509
#define MIDX_CHUNK_BITMAPPED_PACKS_WIDTH (2 * sizeof(uint32_t))
509510

510-
int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
511+
int nth_bitmapped_pack(struct multi_pack_index *m,
511512
struct bitmapped_pack *bp, uint32_t pack_int_id)
512513
{
513514
uint32_t local_pack_int_id = midx_for_pack(&m, pack_int_id);
514515

515516
if (!m->chunk_bitmapped_packs)
516517
return error(_("MIDX does not contain the BTMP chunk"));
517518

518-
if (prepare_midx_pack(r, m, pack_int_id))
519+
if (prepare_midx_pack(m, pack_int_id))
519520
return error(_("could not load bitmapped pack %"PRIu32), pack_int_id);
520521

521522
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)
600601
(off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
601602
}
602603

603-
int fill_midx_entry(struct repository *r,
604+
int fill_midx_entry(struct multi_pack_index *m,
604605
const struct object_id *oid,
605-
struct pack_entry *e,
606-
struct multi_pack_index *m)
606+
struct pack_entry *e)
607607
{
608608
uint32_t pos;
609609
uint32_t pack_int_id;
@@ -615,7 +615,7 @@ int fill_midx_entry(struct repository *r,
615615
midx_for_object(&m, pos);
616616
pack_int_id = nth_midxed_pack_int_id(m, pos);
617617

618-
if (prepare_midx_pack(r, m, pack_int_id))
618+
if (prepare_midx_pack(m, pack_int_id))
619619
return 0;
620620
p = m->packs[pack_int_id - m->num_packs_in_base];
621621

@@ -912,7 +912,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
912912
_("Looking for referenced packfiles"),
913913
m->num_packs + m->num_packs_in_base);
914914
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))
916916
midx_report("failed to load pack in position %d", i);
917917

918918
display_progress(progress, i + 1);
@@ -989,7 +989,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
989989

990990
nth_midxed_object_oid(&oid, m, pairs[i].pos);
991991

992-
if (!fill_midx_entry(r, &oid, &e, m)) {
992+
if (!fill_midx_entry(m, &oid, &e)) {
993993
midx_report(_("failed to load pack entry for oid[%d] = %s"),
994994
pairs[i].pos, oid_to_hex(&oid));
995995
continue;

midx.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,
103103
struct multi_pack_index *load_multi_pack_index(struct repository *r,
104104
const char *object_dir,
105105
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);
107107
struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
108108
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,
110110
struct bitmapped_pack *bp, uint32_t pack_int_id);
111111
int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
112112
uint32_t *result);
@@ -118,7 +118,7 @@ uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos);
118118
struct object_id *nth_midxed_object_oid(struct object_id *oid,
119119
struct multi_pack_index *m,
120120
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);
122122
int midx_contains_pack(struct multi_pack_index *m,
123123
const char *idx_or_pack_name);
124124
int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);

pack-bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
493493
}
494494

495495
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)) {
497497
warning(_("could not open pack %s"),
498498
bitmap_git->midx->pack_names[i]);
499499
goto cleanup;
@@ -2466,7 +2466,7 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
24662466
struct multi_pack_index *m = bitmap_git->midx;
24672467
for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
24682468
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) {
24702470
warning(_("unable to load pack: '%s', disabling pack-reuse"),
24712471
bitmap_git->midx->pack_names[i]);
24722472
free(packs);

packfile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ struct packed_git *get_all_packs(struct repository *r)
10911091
if (!m)
10921092
continue;
10931093
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);
10951095
}
10961096

10971097
return r->objects->packed_git;
@@ -2077,7 +2077,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
20772077
prepare_packed_git(r);
20782078

20792079
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))
20812081
return 1;
20822082

20832083
if (!r->objects->packed_git)

t/helper/test-read-midx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
6565
for (i = 0; i < m->num_objects; i++) {
6666
nth_midxed_object_oid(&oid, m,
6767
i + m->num_objects_in_base);
68-
fill_midx_entry(the_repository, &oid, &e, m);
68+
fill_midx_entry(m, &oid, &e);
6969

7070
printf("%s %"PRIu64"\t%s\n",
7171
oid_to_hex(&oid), e.offset, e.p->pack_name);
@@ -126,7 +126,7 @@ static int read_midx_bitmapped_packs(const char *object_dir)
126126
return 1;
127127

128128
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) {
130130
close_midx(midx);
131131
return 1;
132132
}

0 commit comments

Comments
 (0)