mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
fsck: check even zero-entry index files
Infb64ca526a
(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 beforefb64ca526a
, 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:
parent
592ec63b38
commit
8d3e7eac52
|
@ -1007,8 +1007,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
||||||
* while we're examining the index.
|
* while we're examining the index.
|
||||||
*/
|
*/
|
||||||
path = xstrdup(worktree_git_path(wt, "index"));
|
path = xstrdup(worktree_git_path(wt, "index"));
|
||||||
if (read_index_from(&istate, path,
|
read_index_from(&istate, path, get_worktree_git_dir(wt));
|
||||||
get_worktree_git_dir(wt)) > 0)
|
|
||||||
fsck_index(&istate, path, wt->is_current);
|
fsck_index(&istate, path, wt->is_current);
|
||||||
discard_index(&istate);
|
discard_index(&istate);
|
||||||
free(path);
|
free(path);
|
||||||
|
|
Loading…
Reference in a new issue