Skip to content

Commit 64404a2

Browse files
derrickstoleegitster
authored andcommitted
midx: pass a repository pointer
Much of the multi-pack-index code focuses on the multi_pack_index struct, and so we only pass a pointer to the current one. However, we will insert a dependency on the packed_git linked list in a future change, so we will need a repository reference. Inserting these parameters is a significant enough change to split out. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83232e3 commit 64404a2

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

builtin/multi-pack-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int cmd_multi_pack_index(int argc, const char **argv,
4646
if (!strcmp(argv[0], "write"))
4747
return write_midx_file(opts.object_dir);
4848
if (!strcmp(argv[0], "verify"))
49-
return verify_midx_file(opts.object_dir);
49+
return verify_midx_file(the_repository, opts.object_dir);
5050

5151
die(_("unrecognized verb: %s"), argv[0]);
5252
}

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ static int want_object_in_pack(const struct object_id *oid,
10781078

10791079
for (m = get_multi_pack_index(the_repository); m; m = m->next) {
10801080
struct pack_entry e;
1081-
if (fill_midx_entry(oid, &e, m)) {
1081+
if (fill_midx_entry(the_repository, oid, &e, m)) {
10821082
struct packed_git *p = e.p;
10831083
off_t offset;
10841084

midx.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void close_midx(struct multi_pack_index *m)
201201
FREE_AND_NULL(m->pack_names);
202202
}
203203

204-
int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
204+
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id)
205205
{
206206
struct strbuf pack_name = STRBUF_INIT;
207207

@@ -261,7 +261,10 @@ static uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
261261
return get_be32(m->chunk_object_offsets + pos * MIDX_CHUNK_OFFSET_WIDTH);
262262
}
263263

264-
static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *e, uint32_t pos)
264+
static int nth_midxed_pack_entry(struct repository *r,
265+
struct multi_pack_index *m,
266+
struct pack_entry *e,
267+
uint32_t pos)
265268
{
266269
uint32_t pack_int_id;
267270
struct packed_git *p;
@@ -271,7 +274,7 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
271274

272275
pack_int_id = nth_midxed_pack_int_id(m, pos);
273276

274-
if (prepare_midx_pack(m, pack_int_id))
277+
if (prepare_midx_pack(r, m, pack_int_id))
275278
die(_("error preparing packfile from multi-pack-index"));
276279
p = m->packs[pack_int_id];
277280

@@ -301,14 +304,17 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
301304
return 1;
302305
}
303306

304-
int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m)
307+
int fill_midx_entry(struct repository * r,
308+
const struct object_id *oid,
309+
struct pack_entry *e,
310+
struct multi_pack_index *m)
305311
{
306312
uint32_t pos;
307313

308314
if (!bsearch_midx(oid, m, &pos))
309315
return 0;
310316

311-
return nth_midxed_pack_entry(m, e, pos);
317+
return nth_midxed_pack_entry(r, m, e, pos);
312318
}
313319

314320
/* Match "foo.idx" against either "foo.pack" _or_ "foo.idx". */
@@ -1020,7 +1026,7 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b)
10201026
display_progress(progress, _n); \
10211027
} while (0)
10221028

1023-
int verify_midx_file(const char *object_dir)
1029+
int verify_midx_file(struct repository *r, const char *object_dir)
10241030
{
10251031
struct pair_pos_vs_id *pairs = NULL;
10261032
uint32_t i;
@@ -1034,7 +1040,7 @@ int verify_midx_file(const char *object_dir)
10341040
progress = start_progress(_("Looking for referenced packfiles"),
10351041
m->num_packs);
10361042
for (i = 0; i < m->num_packs; i++) {
1037-
if (prepare_midx_pack(m, i))
1043+
if (prepare_midx_pack(r, m, i))
10381044
midx_report("failed to load pack in position %d", i);
10391045

10401046
display_progress(progress, i + 1);
@@ -1099,7 +1105,7 @@ int verify_midx_file(const char *object_dir)
10991105

11001106
nth_midxed_object_oid(&oid, m, pairs[i].pos);
11011107

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

midx.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
struct object_id;
77
struct pack_entry;
8+
struct repository;
89

910
#define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
1011

@@ -37,18 +38,18 @@ struct multi_pack_index {
3738
};
3839

3940
struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
40-
int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
41+
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
4142
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
4243
struct object_id *nth_midxed_object_oid(struct object_id *oid,
4344
struct multi_pack_index *m,
4445
uint32_t n);
45-
int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
46+
int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
4647
int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name);
4748
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
4849

4950
int write_midx_file(const char *object_dir);
5051
void clear_midx_file(struct repository *r);
51-
int verify_midx_file(const char *object_dir);
52+
int verify_midx_file(struct repository *r, const char *object_dir);
5253

5354
void close_midx(struct multi_pack_index *m);
5455

packfile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ struct packed_git *get_all_packs(struct repository *r)
10351035
for (m = r->objects->multi_pack_index; m; m = m->next) {
10361036
uint32_t i;
10371037
for (i = 0; i < m->num_packs; i++) {
1038-
if (!prepare_midx_pack(m, i)) {
1038+
if (!prepare_midx_pack(r, m, i)) {
10391039
m->packs[i]->next = p;
10401040
p = m->packs[i];
10411041
}
@@ -1998,7 +1998,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
19981998
return 0;
19991999

20002000
for (m = r->objects->multi_pack_index; m; m = m->next) {
2001-
if (fill_midx_entry(oid, e, m))
2001+
if (fill_midx_entry(r, oid, e, m))
20022002
return 1;
20032003
}
20042004

0 commit comments

Comments
 (0)