Skip to content

Commit

Permalink
Merge pull request #1468 from atetubou/fscache_checkout_flush
Browse files Browse the repository at this point in the history
checkout.c: enable fscache for checkout again

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Oct 9, 2024
2 parents 100a7f0 + 93205f0 commit 910fa49
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
if (pc_workers > 1)
init_parallel_checkout();

enable_fscache(1);
for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
struct cache_entry *ce = the_repository->index->cache[pos];
if (ce->ce_flags & CE_MATCHED) {
Expand All @@ -430,6 +431,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
NULL, NULL);
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
enable_fscache(0);
remove_marked_cache_entries(the_repository->index, 1);
remove_scheduled_dirs();
errs |= finish_delayed_checkout(&state, opts->show_progress);
Expand Down
12 changes: 12 additions & 0 deletions compat/win32/fscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,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.
Expand Down
3 changes: 3 additions & 0 deletions compat/win32/fscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
}

finish:
/* Flush cached lstat in fscache after writing to disk. */
flush_fscache();

if (state->refresh_cache) {
if (!fstat_done && lstat(ce->name, &st) < 0)
return error_errno("unable to stat just-written file %s",
Expand Down
4 changes: 4 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,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

int cmd_main(int, const char **);

/*
Expand Down
1 change: 1 addition & 0 deletions parallel-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ static void write_items_sequentially(struct checkout *state)
{
size_t i;

flush_fscache();
for (i = 0; i < parallel_checkout.nr; i++) {
struct parallel_checkout_item *pc_item = &parallel_checkout.items[i];
write_pc_item(pc_item, state);
Expand Down
36 changes: 36 additions & 0 deletions t/t7201-co.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 &&
fill 1 2 3 4 5 6 7 8 >one &&
Expand Down

0 comments on commit 910fa49

Please sign in to comment.