diff --git a/builtin/checkout.c b/builtin/checkout.c index 29ef50013dccbd..07cc016e5cc3bd 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -360,6 +360,7 @@ static int checkout_paths(const struct checkout_opts *opts, state.istate = &the_index; enable_delayed_checkout(&state); + enable_fscache(1); for (pos = 0; pos < active_nr; pos++) { struct cache_entry *ce = active_cache[pos]; if (ce->ce_flags & CE_MATCHED) { @@ -374,6 +375,7 @@ static int checkout_paths(const struct checkout_opts *opts, pos = skip_same_name(ce, pos) - 1; } } + enable_fscache(0); errs |= finish_delayed_checkout(&state); if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) diff --git a/compat/win32/fscache.c b/compat/win32/fscache.c index ee2b0dea0cfcc9..ff0bf80db31575 100644 --- a/compat/win32/fscache.c +++ b/compat/win32/fscache.c @@ -411,6 +411,18 @@ int fscache_enable(int enable) return result; } +/* + * Flush cached stats result when fscache is enabled. + */ +void fscache_flush(void) +{ + if (enabled) { + EnterCriticalSection(&mutex); + fscache_clear(); + LeaveCriticalSection(&mutex); + } +} + /* * Lstat replacement, uses the cache if enabled, otherwise redirects to * mingw_lstat. diff --git a/compat/win32/fscache.h b/compat/win32/fscache.h index 660ada053b4309..2f06f8df97dcd0 100644 --- a/compat/win32/fscache.h +++ b/compat/win32/fscache.h @@ -7,6 +7,9 @@ int fscache_enable(int enable); int fscache_enabled(const char *path); #define is_fscache_enabled(path) fscache_enabled(path) +void fscache_flush(void); +#define flush_fscache() fscache_flush() + DIR *fscache_opendir(const char *dir); int fscache_lstat(const char *file_name, struct stat *buf); diff --git a/entry.c b/entry.c index 2a2ab6c839490a..0712743a43d0a7 100644 --- a/entry.c +++ b/entry.c @@ -367,6 +367,9 @@ static int write_entry(struct cache_entry *ce, } finish: + /* Flush cached lstat in fscache after writing to disk. */ + flush_fscache(); + if (state->refresh_cache) { assert(state->istate); if (!fstat_done) diff --git a/git-compat-util.h b/git-compat-util.h index 1ea0f742aed75f..43dbe27325f076 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1290,6 +1290,10 @@ static inline int is_missing_file_error(int errno_) #define is_fscache_enabled(path) (0) #endif +#ifndef flush_fscache +#define flush_fscache() /* noop */ +#endif + extern int cmd_main(int, const char **); /* diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 324933acfe9415..0b499a4ebecc15 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -32,6 +32,42 @@ fill () { } +test_expect_success MINGW 'fscache flush cache' ' + + git init fscache-test && + cd fscache-test && + git config core.fscache 1 && + echo A > test.txt && + git add test.txt && + git commit -m A && + echo B >> test.txt && + git checkout . && + test -z "$(git status -s)" && + echo A > expect.txt && + test_cmp expect.txt test.txt && + cd .. && + rm -rf fscache-test +' + +test_expect_success MINGW 'fscache flush cache dir' ' + + git init fscache-test && + cd fscache-test && + git config core.fscache 1 && + echo A > test.txt && + git add test.txt && + git commit -m A && + rm test.txt && + mkdir test.txt && + touch test.txt/test.txt && + git checkout . && + test -z "$(git status -s)" && + echo A > expect.txt && + test_cmp expect.txt test.txt && + cd .. && + rm -rf fscache-test +' + test_expect_success setup ' fill x y z > same &&