]> git.ipfire.org Git - thirdparty/git.git/commit
object-file: emit corruption errors when detected
authorJonathan Tan <jonathantanmy@google.com>
Wed, 14 Dec 2022 19:17:42 +0000 (11:17 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Dec 2022 00:05:55 +0000 (09:05 +0900)
commit9e59b38c88cdd79964cc92860906a0737bee3797
tree42519c8f6985b5f7f4ebaaa0adeb4934f59e8c79
parentae285ac4492d73f83a45850267947e29a48e1469
object-file: emit corruption errors when detected

Instead of relying on errno being preserved across function calls, teach
do_oid_object_info_extended() to itself report object corruption when
it first detects it. There are 3 types of corruption being detected:
 - when a replacement object is missing
 - when a loose object is corrupt
 - when a packed object is corrupt and the object cannot be read
   in another way

Note that in the RHS of this patch's diff, a check for ENOENT that was
introduced in 3ba7a06552 (A loose object is not corrupt if it cannot
be read due to EMFILE, 2010-10-28) is also removed. The purpose of this
check is to avoid a false report of corruption if the errno contains
something like EMFILE (or anything that is not ENOENT), in which case
a more generic report is presented. Because, as of this patch, we no
longer rely on such a heuristic to determine corruption, but surface
the error message at the point when we read something that we did not
expect, this check is no longer necessary.

Besides being more resilient, this also prepares for a future patch in
which an indirect caller of do_oid_object_info_extended() will need
such functionality.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
object-store.h