Re: [PATCH v2 09/17] midx: return success/failure in chunk write methods
From: Junio C Hamano <hidden>
Date: 2021-02-04 23:00:25
"Derrick Stolee via GitGitGadget" [off-list ref] writes:
From: Derrick Stolee <redacted> Historically, the chunk-writing methods in midx.c have returned the amount of data written so the writer method could compare this with the table of contents. This presents with some interesting issues: 1. If a chunk writing method has a bug that miscalculates the written bytes, then we can satisfy the table of contents without actually writing the right amount of data to the hashfile. The commit-graph writing code checks the hashfile struct directly for a more robust verification. 2. There is no way for a chunk writing method to gracefully fail. Returning an int presents an opportunity to fail without a die(). 3. The current pattern doesn't match chunk_write_fn type exactly, so we cannot share code with commit-graph.c For these reasons, convert the midx chunk writer methods to return an 'int'. Since none of them fail at the moment, they all return 0.
OK, that makes sense. In this step I see the same "f->total + f->offset" sprinkled in some places, but they will all go away in the "midx: use chunk-format API in write_midx_internal()" step, so it is not such a huge deal. Thanks.