Skip to content

Commit 811c9c2

Browse files
committed
diff-lib: fix check_removed() when fsmonitor is active
`git diff-index` may return incorrect deleted entries when fsmonitor is used in a repository with git submodules. This can be observed on Mac machines, but it can affect all other supported platforms too. If fsmonitor is used, `stat *st` is left uninitialied if cache_entry has CE_FSMONITOR_VALID bit set. But, there are three call sites that rely on stat afterwards, which can result in incorrect results. We can fill members of "struct stat" that matters well enough using the information we have in "struct cache_entry" that fsmonitor told us is up-to-date to solve this. Helped-by: Josip Sokcevic <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9510fe8 commit 811c9c2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

diff-lib.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@
3838
*/
3939
static int check_removed(const struct cache_entry *ce, struct stat *st)
4040
{
41-
if (lstat(ce->name, st) < 0) {
41+
int stat_err;
42+
43+
if (!(ce->ce_flags & CE_FSMONITOR_VALID))
44+
stat_err = lstat(ce->name, st);
45+
else
46+
stat_err = fake_lstat(ce, st);
47+
if (stat_err < 0) {
4248
if (!is_missing_file_error(errno))
4349
return -1;
4450
return 1;

0 commit comments

Comments
 (0)