]> git.ipfire.org Git - thirdparty/git.git/commit
cache-tree: refactor verification to return error codes
authorPatrick Steinhardt <ps@pks.im>
Mon, 7 Oct 2024 04:38:15 +0000 (06:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Oct 2024 22:08:11 +0000 (15:08 -0700)
commit9f119599a69eb11f0712cab3bdbc2000eb91abd7
treed0981b5ce769a1482e7561cbd6ceb54db7354139
parent3969d78396e707c5a900dd5e15c365c54bef0283
cache-tree: refactor verification to return error codes

The function `cache_tree_verify()` will `BUG()` whenever it finds that
the cache-tree extension of the index is corrupt. The function is thus
inherently untestable because the resulting call to `abort()` will be
detected by our testing framework and labelled an error. And rightfully
so: it shouldn't ever be possible to hit bugs, as they should indicate a
programming error rather than corruption of on-disk state.

Refactor the function to instead return error codes. This also ensures
that the function can be used e.g. by git-fsck(1) without the whole
process dying. Furthermore, this refactoring plugs some memory leaks
when returning early by creating a common exit path.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache-tree.c
cache-tree.h
read-cache.c
unpack-trees.c