diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-09-15 00:00:43 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-09-16 02:13:14 +0200 |
commit | 811c9c210265a16514fd1b5a513d4b028d711410 (patch) | |
tree | cb7f492efef466fef4c3a1446a10476099094773 /diff-lib.c | |
parent | Merge branch 'jc/fake-lstat' into jc/diff-cached-fsmonitor-fix (diff) | |
download | git-811c9c210265a16514fd1b5a513d4b028d711410.tar.xz git-811c9c210265a16514fd1b5a513d4b028d711410.zip |
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 <sokcevic@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff-lib.c')
-rw-r--r-- | diff-lib.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/diff-lib.c b/diff-lib.c index e533b436af..a834e5bad6 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -38,7 +38,13 @@ */ static int check_removed(const struct cache_entry *ce, struct stat *st) { - if (lstat(ce->name, st) < 0) { + int stat_err; + + if (!(ce->ce_flags & CE_FSMONITOR_VALID)) + stat_err = lstat(ce->name, st); + else + stat_err = fake_lstat(ce, st); + if (stat_err < 0) { if (!is_missing_file_error(errno)) return -1; return 1; |