1
0
mirror of https://github.com/git/git synced 2024-07-05 00:58:49 +00:00

fsck: check even zero-entry index files

In fb64ca526a (fsck: check index files in all worktrees, 2023-02-24), we
swapped out a call to vanilla repo_read_index() for a series of
read_index_from() calls, one per worktree. The code for the latter was
copied from add_index_objects_to_pending(), which checks for a positive
return value from the index reading function, and we do the same here in
fsck now.

But this is probably the wrong thing. I had interpreted the check as
"don't operate on the index struct if there was an error". But in
reality, if there is an error then the index-reading code will simply
die (which admittedly is not great for fsck, but that is not a new
problem).

The return value here is actually the number of entries read. So it
makes sense for add_index_objects_to_pending() to ignore a zero-entry
index (there is nothing to add). But for fsck, we would still want to
check any extensions, etc (though presumably it is unlikely to have them
in an empty index, I don't think it's impossible).

So we should ignore the return value from read_index_from() entirely.
This matches the behavior before fb64ca526a, when we ignored the return
value from repo_read_index().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2023-02-26 17:29:43 -05:00 committed by Junio C Hamano
parent 592ec63b38
commit 8d3e7eac52

View File

@ -1007,9 +1007,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
* while we're examining the index.
*/
path = xstrdup(worktree_git_path(wt, "index"));
if (read_index_from(&istate, path,
get_worktree_git_dir(wt)) > 0)
fsck_index(&istate, path, wt->is_current);
read_index_from(&istate, path, get_worktree_git_dir(wt));
fsck_index(&istate, path, wt->is_current);
discard_index(&istate);
free(path);
}