chunk-format: create read chunk API
authorDerrick Stolee <dstolee@microsoft.com>
Thu, 18 Feb 2021 14:07:34 +0000 (14:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Feb 2021 21:38:16 +0000 (13:38 -0800)
commit5f0879f54b1f5cda348528a49af57a9c3fd620f9
tree9931f4a58baaf254e8e7bb1f6d96c3469c13f476
parent63a8f0e9b9d9ce636738094391619c35856f7665
chunk-format: create read chunk API

Add the capability to read the table of contents, then pair the chunks
with necessary logic using read_chunk_fn pointers. Callers will be added
in future changes, but the typical outline will be:

 1. initialize a 'struct chunkfile' with init_chunkfile(NULL).
 2. call read_table_of_contents().
 3. for each chunk to parse,
    a. call pair_chunk() to assign a pointer with the chunk position, or
    b. call read_chunk() to run a callback on the chunk start and size.
 4. call free_chunkfile() to clear the 'struct chunkfile' data.

We are re-using the anonymous 'struct chunkfile' data, as it is internal
to the chunk-format API. This gives it essentially two modes: write and
read. If the same struct instance was used for both reads and writes,
then there would be failures.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
chunk-format.c
chunk-format.h