Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/midx.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2018-09-13 21:02:25 +0300
committerJunio C Hamano <gitster@pobox.com>2018-09-17 23:49:41 +0300
commitcc6af73c029da23f7b2c98c60e4fba1ca2db215b (patch)
treeaf566e0acf04339045aa56a41a1cf3e2e67e04f8 /midx.c
parentd8ac9ee109ade79783ea398200219960d352f503 (diff)
multi-pack-index: verify object offsets
The 'git multi-pack-index verify' command must verify the object offsets stored in the multi-pack-index are correct. There are two ways the offset chunk can be incorrect: the pack-int-id and the object offset. Replace the BUG() statement with a die() statement, now that we may hit a bad pack-int-id during a 'verify' command on a corrupt multi-pack-index, and it is covered by a test. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'midx.c')
-rw-r--r--midx.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/midx.c b/midx.c
index db9c49bb2b..ef4a6969df 100644
--- a/midx.c
+++ b/midx.c
@@ -197,7 +197,8 @@ int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
struct strbuf pack_name = STRBUF_INIT;
if (pack_int_id >= m->num_packs)
- BUG("bad pack-int-id");
+ die(_("bad pack-int-id: %u (%u total packs"),
+ pack_int_id, m->num_packs);
if (m->packs[pack_int_id])
return 0;
@@ -970,5 +971,31 @@ int verify_midx_file(const char *object_dir)
i, oid_to_hex(&oid1), oid_to_hex(&oid2), i + 1);
}
+ for (i = 0; i < m->num_objects; i++) {
+ struct object_id oid;
+ struct pack_entry e;
+ off_t m_offset, p_offset;
+
+ nth_midxed_object_oid(&oid, m, i);
+ if (!fill_midx_entry(&oid, &e, m)) {
+ midx_report(_("failed to load pack entry for oid[%d] = %s"),
+ i, oid_to_hex(&oid));
+ continue;
+ }
+
+ if (open_pack_index(e.p)) {
+ midx_report(_("failed to load pack-index for packfile %s"),
+ e.p->pack_name);
+ break;
+ }
+
+ m_offset = e.offset;
+ p_offset = find_pack_entry_one(oid.hash, e.p);
+
+ if (m_offset != p_offset)
+ midx_report(_("incorrect object offset for oid[%d] = %s: %"PRIx64" != %"PRIx64),
+ i, oid_to_hex(&oid), m_offset, p_offset);
+ }
+
return verify_midx_error;
}