Skip to content

Commit 6a044a2

Browse files
sokcevicGgitster
authored andcommitted
diff-lib: fix check_removed when fsmonitor is on
`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 not initialized if cache_entry has CE_FSMONITOR_VALID set. But, there are three call sites that rely on stat afterwards, which can result in incorrect results. This change partially reverts commit 4f3d6d0 (fsmonitor: skip lstat deletion check during git diff-index, 2021-03-17). Signed-off-by: Josip Sokcevic <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d27ae36 commit 6a044a2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

diff-lib.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
* exists for ce that is a submodule -- it is a submodule that is not
2929
* checked out). Return negative for an error.
3030
*/
31-
static int check_removed(const struct index_state *istate, const struct cache_entry *ce, struct stat *st)
31+
static int check_removed(const struct cache_entry *ce, struct stat *st)
3232
{
33-
assert(is_fsmonitor_refreshed(istate));
34-
if (!(ce->ce_flags & CE_FSMONITOR_VALID) && lstat(ce->name, st) < 0) {
33+
if (lstat(ce->name, st) < 0) {
3534
if (!is_missing_file_error(errno))
3635
return -1;
3736
return 1;
3837
}
38+
3939
if (has_symlink_leading_path(ce->name, ce_namelen(ce)))
4040
return 1;
4141
if (S_ISDIR(st->st_mode)) {
@@ -141,7 +141,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
141141
memset(&(dpath->parent[0]), 0,
142142
sizeof(struct combine_diff_parent)*5);
143143

144-
changed = check_removed(istate, ce, &st);
144+
changed = check_removed(ce, &st);
145145
if (!changed)
146146
wt_mode = ce_mode_from_stat(ce, st.st_mode);
147147
else {
@@ -221,7 +221,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
221221
} else {
222222
struct stat st;
223223

224-
changed = check_removed(istate, ce, &st);
224+
changed = check_removed(ce, &st);
225225
if (changed) {
226226
if (changed < 0) {
227227
perror(ce->name);
@@ -296,7 +296,7 @@ static int get_stat_data(const struct index_state *istate,
296296
if (!cached && !ce_uptodate(ce)) {
297297
int changed;
298298
struct stat st;
299-
changed = check_removed(istate, ce, &st);
299+
changed = check_removed(ce, &st);
300300
if (changed < 0)
301301
return -1;
302302
else if (changed) {

t/t7527-builtin-fsmonitor.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ my_match_and_clean () {
809809
status --porcelain=v2 >actual.without &&
810810
test_cmp actual.with actual.without &&
811811

812+
git -C super --no-optional-locks diff-index --name-status HEAD >actual.with &&
813+
git -C super --no-optional-locks -c core.fsmonitor=false \
814+
diff-index --name-status HEAD >actual.without &&
815+
test_cmp actual.with actual.without &&
816+
812817
git -C super/dir_1/dir_2/sub reset --hard &&
813818
git -C super/dir_1/dir_2/sub clean -d -f
814819
}

0 commit comments

Comments
 (0)