Skip to content

Commit ca2e5de

Browse files
committed
Merge pull request #1468 from atetubou/fscache_checkout_flush
checkout.c: enable fscache for checkout again Signed-off-by: Johannes Schindelin <[email protected]>
2 parents f5a5a1e + c1b4f66 commit ca2e5de

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

builtin/checkout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
386386
if (pc_workers > 1)
387387
init_parallel_checkout();
388388

389+
enable_fscache(1);
389390
for (pos = 0; pos < active_nr; pos++) {
390391
struct cache_entry *ce = active_cache[pos];
391392
if (ce->ce_flags & CE_MATCHED) {
@@ -410,6 +411,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
410411
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
411412
NULL, NULL);
412413
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
414+
enable_fscache(0);
413415
remove_marked_cache_entries(&the_index, 1);
414416
remove_scheduled_dirs();
415417
errs |= finish_delayed_checkout(&state, &nr_checkouts, opts->show_progress);

compat/win32/fscache.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,18 @@ int fscache_enable(int enable)
425425
return result;
426426
}
427427

428+
/*
429+
* Flush cached stats result when fscache is enabled.
430+
*/
431+
void fscache_flush(void)
432+
{
433+
if (enabled) {
434+
EnterCriticalSection(&mutex);
435+
fscache_clear();
436+
LeaveCriticalSection(&mutex);
437+
}
438+
}
439+
428440
/*
429441
* Lstat replacement, uses the cache if enabled, otherwise redirects to
430442
* mingw_lstat.

compat/win32/fscache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ int fscache_enable(int enable);
77
int fscache_enabled(const char *path);
88
#define is_fscache_enabled(path) fscache_enabled(path)
99

10+
void fscache_flush(void);
11+
#define flush_fscache() fscache_flush()
12+
1013
DIR *fscache_opendir(const char *dir);
1114
int fscache_lstat(const char *file_name, struct stat *buf);
1215

entry.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
386386
}
387387

388388
finish:
389+
/* Flush cached lstat in fscache after writing to disk. */
390+
flush_fscache();
391+
389392
if (state->refresh_cache) {
390393
if (!fstat_done && lstat(ce->name, &st) < 0)
391394
return error_errno("unable to stat just-written file %s",

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,10 @@ static inline int is_missing_file_error(int errno_)
13981398
#define is_fscache_enabled(path) (0)
13991399
#endif
14001400

1401+
#ifndef flush_fscache
1402+
#define flush_fscache() /* noop */
1403+
#endif
1404+
14011405
int cmd_main(int, const char **);
14021406

14031407
/*

t/t7201-co.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,42 @@ fill () {
3535
}
3636

3737

38+
test_expect_success MINGW 'fscache flush cache' '
39+
40+
git init fscache-test &&
41+
cd fscache-test &&
42+
git config core.fscache 1 &&
43+
echo A > test.txt &&
44+
git add test.txt &&
45+
git commit -m A &&
46+
echo B >> test.txt &&
47+
git checkout . &&
48+
test -z "$(git status -s)" &&
49+
echo A > expect.txt &&
50+
test_cmp expect.txt test.txt &&
51+
cd .. &&
52+
rm -rf fscache-test
53+
'
54+
55+
test_expect_success MINGW 'fscache flush cache dir' '
56+
57+
git init fscache-test &&
58+
cd fscache-test &&
59+
git config core.fscache 1 &&
60+
echo A > test.txt &&
61+
git add test.txt &&
62+
git commit -m A &&
63+
rm test.txt &&
64+
mkdir test.txt &&
65+
touch test.txt/test.txt &&
66+
git checkout . &&
67+
test -z "$(git status -s)" &&
68+
echo A > expect.txt &&
69+
test_cmp expect.txt test.txt &&
70+
cd .. &&
71+
rm -rf fscache-test
72+
'
73+
3874
test_expect_success setup '
3975
fill x y z >same &&
4076
fill 1 2 3 4 5 6 7 8 >one &&

0 commit comments

Comments
 (0)