Skip to content

Commit fa8c746

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 cfa567e + ffebe8a commit fa8c746

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
@@ -391,6 +391,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
391391
if (pc_workers > 1)
392392
init_parallel_checkout();
393393

394+
enable_fscache(1);
394395
for (pos = 0; pos < active_nr; pos++) {
395396
struct cache_entry *ce = active_cache[pos];
396397
if (ce->ce_flags & CE_MATCHED) {
@@ -415,6 +416,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
415416
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
416417
NULL, NULL);
417418
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
419+
enable_fscache(0);
418420
remove_marked_cache_entries(&the_index, 1);
419421
remove_scheduled_dirs();
420422
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
@@ -426,6 +426,18 @@ int fscache_enable(int enable)
426426
return result;
427427
}
428428

429+
/*
430+
* Flush cached stats result when fscache is enabled.
431+
*/
432+
void fscache_flush(void)
433+
{
434+
if (enabled) {
435+
EnterCriticalSection(&mutex);
436+
fscache_clear();
437+
LeaveCriticalSection(&mutex);
438+
}
439+
}
440+
429441
/*
430442
* Lstat replacement, uses the cache if enabled, otherwise redirects to
431443
* 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
@@ -1425,6 +1425,10 @@ static inline int is_missing_file_error(int errno_)
14251425
#define is_fscache_enabled(path) (0)
14261426
#endif
14271427

1428+
#ifndef flush_fscache
1429+
#define flush_fscache() /* noop */
1430+
#endif
1431+
14281432
int cmd_main(int, const char **);
14291433

14301434
/*

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)