Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx> --- midx.c | 17 +++++++++++++++++ object-store.h | 1 + t/helper/test-read-midx.c | 5 +++++ t/t5319-multi-pack-index.sh | 7 ++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/midx.c b/midx.c index f78c161422..ffe29af65d 100644 --- a/midx.c +++ b/midx.c @@ -37,6 +37,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir) uint32_t hash_version; char *midx_name = get_midx_filename(object_dir); uint32_t i; + const char *cur_pack_name; fd = git_open(midx_name); @@ -117,6 +118,22 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir) if (!m->chunk_pack_names) die(_("multi-pack-index missing required pack-name chunk")); + m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names)); + + cur_pack_name = (const char *)m->chunk_pack_names; + for (i = 0; i < m->num_packs; i++) { + m->pack_names[i] = cur_pack_name; + + cur_pack_name += strlen(cur_pack_name) + 1; + + if (i && strcmp(m->pack_names[i], m->pack_names[i - 1]) <= 0) { + error(_("multi-pack-index pack names out of order: '%s' before '%s'"), + m->pack_names[i - 1], + m->pack_names[i]); + goto cleanup_fail; + } + } + return m; cleanup_fail: diff --git a/object-store.h b/object-store.h index c87d051849..88169b33e9 100644 --- a/object-store.h +++ b/object-store.h @@ -99,6 +99,7 @@ struct multi_pack_index { const unsigned char *chunk_pack_names; + const char **pack_names; char object_dir[FLEX_ARRAY]; }; diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index a9232d8219..0b53a9e8b5 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -9,6 +9,7 @@ static int read_midx_file(const char *object_dir) { + uint32_t i; struct multi_pack_index *m = load_multi_pack_index(object_dir); if (!m) @@ -27,6 +28,10 @@ static int read_midx_file(const char *object_dir) printf("\n"); + printf("packs:\n"); + for (i = 0; i < m->num_packs; i++) + printf("%s\n", m->pack_names[i]); + printf("object_dir: %s\n", m->object_dir); return 0; diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index f458758945..4610352b69 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -8,8 +8,13 @@ midx_read_expect () { cat >expect <<-EOF header: 4d494458 1 1 $NUM_PACKS chunks: pack_names - object_dir: . + packs: EOF + if [ $NUM_PACKS -ge 1 ] + then + ls pack/ | grep idx | sort >> expect + fi + printf "object_dir: .\n" >>expect && test-tool read-midx . >actual && test_cmp expect actual } -- 2.18.0.118.gd4f65b8d14