Skip to content

Commit

Permalink
midx: read OOFF chunk with pair_chunk_expect()
Browse files Browse the repository at this point in the history
The `OOFF` chunk can benefit from the new chunk-format API function
described in the previous commit. Convert it to `pair_chunk_expect()`
accordingly.

Signed-off-by: Taylor Blau <[email protected]>
  • Loading branch information
ttaylorr committed Nov 9, 2023
1 parent c2b0e54 commit 44bd344
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
17 changes: 3 additions & 14 deletions midx.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ static int midx_read_oid_fanout(const unsigned char *chunk_start,
return 0;
}

static int midx_read_object_offsets(const unsigned char *chunk_start,
size_t chunk_size, void *data)
{
struct multi_pack_index *m = data;
m->chunk_object_offsets = chunk_start;

if (chunk_size != st_mult(m->num_objects, MIDX_CHUNK_OFFSET_WIDTH)) {
error(_("multi-pack-index object offset chunk is the wrong size"));
return 1;
}
return 0;
}

struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local)
{
struct multi_pack_index *m = NULL;
Expand Down Expand Up @@ -176,7 +163,9 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
if (pair_chunk_expect(cf, MIDX_CHUNKID_OIDLOOKUP, &m->chunk_oid_lookup,
m->hash_len, m->num_objects))
die(_("multi-pack-index required OID lookup chunk missing or corrupted"));
if (read_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS, midx_read_object_offsets, m))
if (pair_chunk_expect(cf, MIDX_CHUNKID_OBJECTOFFSETS,
&m->chunk_object_offsets, MIDX_CHUNK_OFFSET_WIDTH,
m->num_objects))
die(_("multi-pack-index required object offsets chunk missing or corrupted"));

pair_chunk(cf, MIDX_CHUNKID_LARGEOFFSETS, &m->chunk_large_offsets,
Expand Down
1 change: 0 additions & 1 deletion t/t5319-multi-pack-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ test_expect_success 'reader notices too-small object offset chunk' '
corrupt_chunk OOFF clear 00000000 &&
test_must_fail git log 2>err &&
cat >expect <<-\EOF &&
error: multi-pack-index object offset chunk is the wrong size
fatal: multi-pack-index required object offsets chunk missing or corrupted
EOF
test_cmp expect err
Expand Down

0 comments on commit 44bd344

Please sign in to comment.