Skip to content

Commit 3592796

Browse files
ttaylorrgitster
authored andcommitted
midx: implement verification support for incremental MIDXs
Teach the verification implementation used by `git multi-pack-index verify` to perform verification for incremental MIDX chains by independently validating each layer within the chain. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b80236d commit 3592796

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

midx.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
470470
return 0;
471471
}
472472

473+
struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
474+
uint32_t pack_int_id)
475+
{
476+
uint32_t local_pack_int_id = midx_for_pack(&m, pack_int_id);
477+
return m->packs[local_pack_int_id];
478+
}
479+
473480
#define MIDX_CHUNK_BITMAPPED_PACKS_WIDTH (2 * sizeof(uint32_t))
474481

475482
int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
@@ -818,6 +825,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
818825
uint32_t i;
819826
struct progress *progress = NULL;
820827
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
828+
struct multi_pack_index *curr;
821829
verify_midx_error = 0;
822830

823831
if (!m) {
@@ -840,8 +848,8 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
840848

841849
if (flags & MIDX_PROGRESS)
842850
progress = start_delayed_progress(_("Looking for referenced packfiles"),
843-
m->num_packs);
844-
for (i = 0; i < m->num_packs; i++) {
851+
m->num_packs + m->num_packs_in_base);
852+
for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
845853
if (prepare_midx_pack(r, m, i))
846854
midx_report("failed to load pack in position %d", i);
847855

@@ -861,17 +869,20 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
861869
if (flags & MIDX_PROGRESS)
862870
progress = start_sparse_progress(_("Verifying OID order in multi-pack-index"),
863871
m->num_objects - 1);
864-
for (i = 0; i < m->num_objects - 1; i++) {
865-
struct object_id oid1, oid2;
866872

867-
nth_midxed_object_oid(&oid1, m, i);
868-
nth_midxed_object_oid(&oid2, m, i + 1);
873+
for (curr = m; curr; curr = curr->base_midx) {
874+
for (i = 0; i < m->num_objects - 1; i++) {
875+
struct object_id oid1, oid2;
869876

870-
if (oidcmp(&oid1, &oid2) >= 0)
871-
midx_report(_("oid lookup out of order: oid[%d] = %s >= %s = oid[%d]"),
872-
i, oid_to_hex(&oid1), oid_to_hex(&oid2), i + 1);
877+
nth_midxed_object_oid(&oid1, m, m->num_objects_in_base + i);
878+
nth_midxed_object_oid(&oid2, m, m->num_objects_in_base + i + 1);
873879

874-
midx_display_sparse_progress(progress, i + 1);
880+
if (oidcmp(&oid1, &oid2) >= 0)
881+
midx_report(_("oid lookup out of order: oid[%d] = %s >= %s = oid[%d]"),
882+
i, oid_to_hex(&oid1), oid_to_hex(&oid2), i + 1);
883+
884+
midx_display_sparse_progress(progress, i + 1);
885+
}
875886
}
876887
stop_progress(&progress);
877888

@@ -881,8 +892,8 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
881892
* each of the objects and only require 1 packfile to be open at a
882893
* time.
883894
*/
884-
ALLOC_ARRAY(pairs, m->num_objects);
885-
for (i = 0; i < m->num_objects; i++) {
895+
ALLOC_ARRAY(pairs, m->num_objects + m->num_objects_in_base);
896+
for (i = 0; i < m->num_objects + m->num_objects_in_base; i++) {
886897
pairs[i].pos = i;
887898
pairs[i].pack_int_id = nth_midxed_pack_int_id(m, i);
888899
}
@@ -896,16 +907,18 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
896907

897908
if (flags & MIDX_PROGRESS)
898909
progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects);
899-
for (i = 0; i < m->num_objects; i++) {
910+
for (i = 0; i < m->num_objects + m->num_objects_in_base; i++) {
900911
struct object_id oid;
901912
struct pack_entry e;
902913
off_t m_offset, p_offset;
903914

904915
if (i > 0 && pairs[i-1].pack_int_id != pairs[i].pack_int_id &&
905-
m->packs[pairs[i-1].pack_int_id])
906-
{
907-
close_pack_fd(m->packs[pairs[i-1].pack_int_id]);
908-
close_pack_index(m->packs[pairs[i-1].pack_int_id]);
916+
nth_midxed_pack(m, pairs[i-1].pack_int_id)) {
917+
uint32_t pack_int_id = pairs[i-1].pack_int_id;
918+
struct packed_git *p = nth_midxed_pack(m, pack_int_id);
919+
920+
close_pack_fd(p);
921+
close_pack_index(p);
909922
}
910923

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

midx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,
9595

9696
struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
9797
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
98+
struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
99+
uint32_t pack_int_id);
98100
int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
99101
struct bitmapped_pack *bp, uint32_t pack_int_id);
100102
int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,

0 commit comments

Comments
 (0)