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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Apr 29, 2019 at 09:18 UTC 64404a24cf60761baba0e04a337c419f0e86c0f9
5 files changed +22 -15
builtin/multi-pack-index.c
+1 -1
@@ -46,7 +46,7 @@ int cmd_multi_pack_index(int argc, const char **argv,
46 if (!strcmp(argv[0], "write"))
47 return write_midx_file(opts.object_dir);
48 if (!strcmp(argv[0], "verify"))
49 - return verify_midx_file(opts.object_dir);
49 + return verify_midx_file(the_repository, opts.object_dir);
50
51 die(_("unrecognized verb: %s"), argv[0]);
52 }
builtin/pack-objects.c
+1 -1
@@ -1078,7 +1078,7 @@ static int want_object_in_pack(const struct object_id *oid,
1078
1079 for (m = get_multi_pack_index(the_repository); m; m = m->next) {
1080 struct pack_entry e;
1081 - if (fill_midx_entry(oid, &e, m)) {
1081 + if (fill_midx_entry(the_repository, oid, &e, m)) {
1082 struct packed_git *p = e.p;
1083 off_t offset;
1084
midx.c
+14 -8
@@ -201,7 +201,7 @@ void close_midx(struct multi_pack_index *m)
201 FREE_AND_NULL(m->pack_names);
202 }
203
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)
205 {
206 struct strbuf pack_name = STRBUF_INIT;
207
@@ -261,7 +261,10 @@ static uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
261 return get_be32(m->chunk_object_offsets + pos * MIDX_CHUNK_OFFSET_WIDTH);
262 }
263
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)
268 {
269 uint32_t pack_int_id;
270 struct packed_git *p;
@@ -271,7 +274,7 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
274
275 pack_int_id = nth_midxed_pack_int_id(m, pos);
276
274 - if (prepare_midx_pack(m, pack_int_id))
277 + if (prepare_midx_pack(r, m, pack_int_id))
278 die(_("error preparing packfile from multi-pack-index"));
279 p = m->packs[pack_int_id];
280
@@ -301,14 +304,17 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
304 return 1;
305 }
306
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)
311 {
312 uint32_t pos;
313
314 if (!bsearch_midx(oid, m, &pos))
315 return 0;
316
311 - return nth_midxed_pack_entry(m, e, pos);
317 + return nth_midxed_pack_entry(r, m, e, pos);
318 }
319
320 /* 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)
1026 display_progress(progress, _n); \
1027 } while (0)
1028
1023 -int verify_midx_file(const char *object_dir)
1029 +int verify_midx_file(struct repository *r, const char *object_dir)
1030 {
1031 struct pair_pos_vs_id *pairs = NULL;
1032 uint32_t i;
@@ -1034,7 +1040,7 @@ int verify_midx_file(const char *object_dir)
1040 progress = start_progress(_("Looking for referenced packfiles"),
1041 m->num_packs);
1042 for (i = 0; i < m->num_packs; i++) {
1037 - if (prepare_midx_pack(m, i))
1043 + if (prepare_midx_pack(r, m, i))
1044 midx_report("failed to load pack in position %d", i);
1045
1046 display_progress(progress, i + 1);
@@ -1099,7 +1105,7 @@ int verify_midx_file(const char *object_dir)
1105
1106 nth_midxed_object_oid(&oid, m, pairs[i].pos);
1107
1102 - if (!fill_midx_entry(&oid, &e, m)) {
1108 + if (!fill_midx_entry(r, &oid, &e, m)) {
1109 midx_report(_("failed to load pack entry for oid[%d] = %s"),
1110 pairs[i].pos, oid_to_hex(&oid));
1111 continue;
midx.h
+4 -3
@@ -5,6 +5,7 @@
5
6 struct object_id;
7 struct pack_entry;
8 +struct repository;
9
10 #define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
11
@@ -37,18 +38,18 @@ struct multi_pack_index {
38 };
39
40 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);
42 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
43 struct object_id *nth_midxed_object_oid(struct object_id *oid,
44 struct multi_pack_index *m,
45 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);
47 int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name);
48 int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
49
50 int write_midx_file(const char *object_dir);
51 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);
53
54 void close_midx(struct multi_pack_index *m);
55
packfile.c
+2 -2
@@ -1035,7 +1035,7 @@ struct packed_git *get_all_packs(struct repository *r)
1035 for (m = r->objects->multi_pack_index; m; m = m->next) {
1036 uint32_t i;
1037 for (i = 0; i < m->num_packs; i++) {
1038 - if (!prepare_midx_pack(m, i)) {
1038 + if (!prepare_midx_pack(r, m, i)) {
1039 m->packs[i]->next = p;
1040 p = m->packs[i];
1041 }
@@ -1998,7 +1998,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
1998 return 0;
1999
2000 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))
2002 return 1;
2003 }
2004