Skip to content

Commit 42a6dd4

Browse files
pks-tgitster
authored andcommitted
midx: stop duplicating info redundant with its owning source
Multi-pack indices store some information that is redundant with their owning source: - The locality bit that tracks whether the source is the primary object source or an alternate. - The object directory path the multi-pack index is located in. - The pointer to the owning parent directory. All of this information is already contained in `struct odb_source`. So now that we always have that struct available when loading a multi-pack index we have it readily accessible. Drop the redundant information and instead store a pointer to the object source. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c502d28 commit 42a6dd4

File tree

7 files changed

+36
-35
lines changed

7 files changed

+36
-35
lines changed

builtin/repack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ static void mark_packs_for_deletion(struct existing_packs *existing,
223223
static void remove_redundant_pack(const char *dir_name, const char *base_name)
224224
{
225225
struct strbuf buf = STRBUF_INIT;
226-
struct multi_pack_index *m = get_multi_pack_index(the_repository->objects->sources);
226+
struct odb_source *source = the_repository->objects->sources;
227+
struct multi_pack_index *m = get_multi_pack_index(source);
227228
strbuf_addf(&buf, "%s.pack", base_name);
228-
if (m && m->local && midx_contains_pack(m, buf.buf))
229+
if (m && source->local && midx_contains_pack(m, buf.buf))
229230
clear_midx_file(the_repository);
230231
strbuf_insertf(&buf, 0, "%s/", dir_name);
231232
unlink_pack_path(buf.buf, 1);

midx-write.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,10 +981,11 @@ static int link_midx_to_chain(struct multi_pack_index *m)
981981
for (i = 0; i < ARRAY_SIZE(midx_exts); i++) {
982982
const unsigned char *hash = get_midx_checksum(m);
983983

984-
get_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,
984+
get_midx_filename_ext(m->source->odb->repo->hash_algo, &from,
985+
m->source->path,
985986
hash, midx_exts[i].non_split);
986-
get_split_midx_filename_ext(m->repo->hash_algo, &to,
987-
m->object_dir, hash,
987+
get_split_midx_filename_ext(m->source->odb->repo->hash_algo, &to,
988+
m->source->path, hash,
988989
midx_exts[i].split);
989990

990991
if (link(from.buf, to.buf) < 0 && errno != ENOENT) {
@@ -1109,7 +1110,7 @@ static int write_midx_internal(struct odb_source *source,
11091110
if (flags & MIDX_WRITE_BITMAP && load_midx_revindex(m)) {
11101111
error(_("could not load reverse index for MIDX %s"),
11111112
hash_to_hex_algop(get_midx_checksum(m),
1112-
m->repo->hash_algo));
1113+
m->source->odb->repo->hash_algo));
11131114
result = 1;
11141115
goto cleanup;
11151116
}

midx.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name,
2626

2727
const unsigned char *get_midx_checksum(struct multi_pack_index *m)
2828
{
29-
return m->data + m->data_len - m->repo->hash_algo->rawsz;
29+
return m->data + m->data_len - m->source->odb->repo->hash_algo->rawsz;
3030
}
3131

3232
void get_midx_filename(const struct git_hash_algo *hash_algo,
@@ -128,11 +128,10 @@ static struct multi_pack_index *load_multi_pack_index_one(struct odb_source *sou
128128
midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);
129129
close(fd);
130130

131-
FLEX_ALLOC_STR(m, object_dir, source->path);
131+
CALLOC_ARRAY(m, 1);
132132
m->data = midx_map;
133133
m->data_len = midx_size;
134-
m->local = source->local;
135-
m->repo = r;
134+
m->source = source;
136135

137136
m->signature = get_be32(m->data);
138137
if (m->signature != MIDX_SIGNATURE)
@@ -446,7 +445,7 @@ static uint32_t midx_for_pack(struct multi_pack_index **_m,
446445
int prepare_midx_pack(struct multi_pack_index *m,
447446
uint32_t pack_int_id)
448447
{
449-
struct repository *r = m->repo;
448+
struct repository *r = m->source->odb->repo;
450449
struct strbuf pack_name = STRBUF_INIT;
451450
struct strbuf key = STRBUF_INIT;
452451
struct packed_git *p;
@@ -458,7 +457,7 @@ int prepare_midx_pack(struct multi_pack_index *m,
458457
if (m->packs[pack_int_id])
459458
return 0;
460459

461-
strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
460+
strbuf_addf(&pack_name, "%s/pack/%s", m->source->path,
462461
m->pack_names[pack_int_id]);
463462

464463
/* pack_map holds the ".pack" name, but we have the .idx */
@@ -469,7 +468,8 @@ int prepare_midx_pack(struct multi_pack_index *m,
469468
strhash(key.buf), key.buf,
470469
struct packed_git, packmap_ent);
471470
if (!p) {
472-
p = add_packed_git(r, pack_name.buf, pack_name.len, m->local);
471+
p = add_packed_git(r, pack_name.buf, pack_name.len,
472+
m->source->local);
473473
if (p) {
474474
install_packed_git(r, p);
475475
list_add_tail(&p->mru, &r->objects->packed_git_mru);
@@ -528,7 +528,8 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
528528
uint32_t *result)
529529
{
530530
int ret = bsearch_hash(oid->hash, m->chunk_oid_fanout,
531-
m->chunk_oid_lookup, m->repo->hash_algo->rawsz,
531+
m->chunk_oid_lookup,
532+
m->source->odb->repo->hash_algo->rawsz,
532533
result);
533534
if (result)
534535
*result += m->num_objects_in_base;
@@ -559,7 +560,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
559560
n = midx_for_object(&m, n);
560561

561562
oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
562-
m->repo->hash_algo);
563+
m->source->odb->repo->hash_algo);
563564
return oid;
564565
}
565566

@@ -734,7 +735,7 @@ int prepare_multi_pack_index_one(struct odb_source *source)
734735

735736
int midx_checksum_valid(struct multi_pack_index *m)
736737
{
737-
return hashfile_checksum_valid(m->repo->hash_algo,
738+
return hashfile_checksum_valid(m->source->odb->repo->hash_algo,
738739
m->data, m->data_len);
739740
}
740741

midx.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct odb_source;
3535
"GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL"
3636

3737
struct multi_pack_index {
38+
struct odb_source *source;
39+
3840
const unsigned char *data;
3941
size_t data_len;
4042

@@ -50,7 +52,6 @@ struct multi_pack_index {
5052
uint32_t num_objects;
5153
int preferred_pack_idx;
5254

53-
int local;
5455
int has_chain;
5556

5657
const unsigned char *chunk_pack_names;
@@ -71,10 +72,6 @@ struct multi_pack_index {
7172

7273
const char **pack_names;
7374
struct packed_git **packs;
74-
75-
struct repository *repo;
76-
77-
char object_dir[FLEX_ARRAY];
7875
};
7976

8077
#define MIDX_PROGRESS (1 << 0)

pack-bitmap.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static uint32_t bitmap_num_objects(struct bitmap_index *index)
216216
static struct repository *bitmap_repo(struct bitmap_index *bitmap_git)
217217
{
218218
if (bitmap_is_midx(bitmap_git))
219-
return bitmap_git->midx->repo;
219+
return bitmap_git->midx->source->odb->repo;
220220
return bitmap_git->pack->repo;
221221
}
222222

@@ -418,13 +418,13 @@ char *midx_bitmap_filename(struct multi_pack_index *midx)
418418
{
419419
struct strbuf buf = STRBUF_INIT;
420420
if (midx->has_chain)
421-
get_split_midx_filename_ext(midx->repo->hash_algo, &buf,
422-
midx->object_dir,
421+
get_split_midx_filename_ext(midx->source->odb->repo->hash_algo, &buf,
422+
midx->source->path,
423423
get_midx_checksum(midx),
424424
MIDX_EXT_BITMAP);
425425
else
426-
get_midx_filename_ext(midx->repo->hash_algo, &buf,
427-
midx->object_dir, get_midx_checksum(midx),
426+
get_midx_filename_ext(midx->source->odb->repo->hash_algo, &buf,
427+
midx->source->path, get_midx_checksum(midx),
428428
MIDX_EXT_BITMAP);
429429

430430
return strbuf_detach(&buf, NULL);
@@ -463,7 +463,8 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
463463

464464
if (bitmap_git->pack || bitmap_git->midx) {
465465
struct strbuf buf = STRBUF_INIT;
466-
get_midx_filename(midx->repo->hash_algo, &buf, midx->object_dir);
466+
get_midx_filename(midx->source->odb->repo->hash_algo, &buf,
467+
midx->source->path);
467468
trace2_data_string("bitmap", bitmap_repo(bitmap_git),
468469
"ignoring extra midx bitmap file", buf.buf);
469470
close(fd);

pack-revindex.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,25 +379,25 @@ int load_midx_revindex(struct multi_pack_index *m)
379379
* not want to accidentally call munmap() in the middle of the
380380
* MIDX.
381381
*/
382-
trace2_data_string("load_midx_revindex", m->repo,
382+
trace2_data_string("load_midx_revindex", m->source->odb->repo,
383383
"source", "midx");
384384
m->revindex_data = (const uint32_t *)m->chunk_revindex;
385385
return 0;
386386
}
387387

388-
trace2_data_string("load_midx_revindex", m->repo,
388+
trace2_data_string("load_midx_revindex", m->source->odb->repo,
389389
"source", "rev");
390390

391391
if (m->has_chain)
392-
get_split_midx_filename_ext(m->repo->hash_algo, &revindex_name,
393-
m->object_dir, get_midx_checksum(m),
392+
get_split_midx_filename_ext(m->source->odb->repo->hash_algo, &revindex_name,
393+
m->source->path, get_midx_checksum(m),
394394
MIDX_EXT_REV);
395395
else
396-
get_midx_filename_ext(m->repo->hash_algo, &revindex_name,
397-
m->object_dir, get_midx_checksum(m),
396+
get_midx_filename_ext(m->source->odb->repo->hash_algo, &revindex_name,
397+
m->source->path, get_midx_checksum(m),
398398
MIDX_EXT_REV);
399399

400-
ret = load_revindex_from_disk(m->repo->hash_algo,
400+
ret = load_revindex_from_disk(m->source->odb->repo->hash_algo,
401401
revindex_name.buf,
402402
m->num_objects,
403403
&m->revindex_map,

t/helper/test-read-midx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
6666
for (i = 0; i < m->num_packs; i++)
6767
printf("%s\n", m->pack_names[i]);
6868

69-
printf("object-dir: %s\n", m->object_dir);
69+
printf("object-dir: %s\n", m->source->path);
7070

7171
if (show_objects) {
7272
struct object_id oid;

0 commit comments

Comments
 (0)