]> git.ipfire.org Git - thirdparty/git.git/commit - diagnose.c
diagnose.c: refactor to safely use 'd_type'
authorVictoria Dye <vdye@github.com>
Sat, 17 Sep 2022 18:16:55 +0000 (18:16 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Sep 2022 17:25:01 +0000 (10:25 -0700)
commitcb98e1d50a7a4a84b76f72dad694d49d2276eef3
tree5f0c3ca4646fa797b8a5b93bcbb62a4fc6ad879c
parent43370b1e910f767b327046b1c4253c82e9695052
diagnose.c: refactor to safely use 'd_type'

Refactor usage of the 'd_type' property of 'struct dirent' in 'diagnose.c'
to instead utilize the compatibility macro 'DTYPE()'. On systems where
'd_type' is not present in 'struct dirent', this macro will always return
'DT_UNKNOWN'. In that case, instead fall back on using the 'stat.st_mode' to
determine whether the dirent points to a dir, file, or link.

Additionally, add a test to 't0092-diagnose.sh' to verify that files (e.g.,
loose objects) are counted properly.

Note that the new function 'get_dtype()' is based on 'resolve_dtype()' in
'dir.c' (which itself was refactored from a prior 'get_dtype()' in
ad6f2157f9 (dir: restructure in a way to avoid passing around a struct
dirent, 2020-01-16)), but differs in that it is meant for use on arbitrary
files, such as those inside the '.git' dir. Because of this, it does not
search the index for a matching entry to derive the 'd_type'.

Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diagnose.c
t/t0092-diagnose.sh