Skip to content

Commit fec20ff

Browse files
committed
Merge pull request #1468 from atetubou/fscache_checkout_flush
checkout.c: enable fscache for checkout again Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 parents f8a0127 + 4cf12f1 commit fec20ff

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

builtin/checkout.c

+2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
407407
if (pc_workers > 1)
408408
init_parallel_checkout();
409409

410+
enable_fscache(1);
410411
for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
411412
struct cache_entry *ce = the_repository->index->cache[pos];
412413
if (ce->ce_flags & CE_MATCHED) {
@@ -432,6 +433,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
432433
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
433434
NULL, NULL);
434435
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
436+
enable_fscache(0);
435437
remove_marked_cache_entries(the_repository->index, 1);
436438
remove_scheduled_dirs();
437439
errs |= finish_delayed_checkout(&state, opts->show_progress);

compat/win32/fscache.c

+12
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ int fscache_enable(int enable)
428428
return result;
429429
}
430430

431+
/*
432+
* Flush cached stats result when fscache is enabled.
433+
*/
434+
void fscache_flush(void)
435+
{
436+
if (enabled) {
437+
EnterCriticalSection(&mutex);
438+
fscache_clear();
439+
LeaveCriticalSection(&mutex);
440+
}
441+
}
442+
431443
/*
432444
* Lstat replacement, uses the cache if enabled, otherwise redirects to
433445
* mingw_lstat.

compat/win32/fscache.h

+3
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

+3
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
411411
}
412412

413413
finish:
414+
/* Flush cached lstat in fscache after writing to disk. */
415+
flush_fscache();
416+
414417
if (state->refresh_cache) {
415418
if (!fstat_done && lstat(ce->name, &st) < 0)
416419
return error_errno("unable to stat just-written file %s",

git-compat-util.h

+4
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,10 @@ static inline int is_missing_file_error(int errno_)
10691069
#define is_fscache_enabled(path) (0)
10701070
#endif
10711071

1072+
#ifndef flush_fscache
1073+
#define flush_fscache() /* noop */
1074+
#endif
1075+
10721076
int cmd_main(int, const char **);
10731077

10741078
/*

parallel-checkout.c

+1
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ static void write_items_sequentially(struct checkout *state)
639639
{
640640
size_t i;
641641

642+
flush_fscache();
642643
for (i = 0; i < parallel_checkout.nr; i++) {
643644
struct parallel_checkout_item *pc_item = &parallel_checkout.items[i];
644645
write_pc_item(pc_item, state);

t/t7201-co.sh

+36
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)