Skip to content

checkout.c: enable fscache for checkout again #1468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,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) {
Expand All @@ -373,6 +374,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))
Expand Down
12 changes: 12 additions & 0 deletions compat/win32/fscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ int fscache_enable(int enable)
return result;
}

/*
* Flush cached stats result when fscache is enabled.
*/
void fscache_flush()
{
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();
#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 @@ -366,6 +366,9 @@ static int write_entry(struct cache_entry *ce,
}

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

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.


if (state->refresh_cache) {
assert(state->istate);
if (!fstat_done)
Expand Down
4 changes: 4 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,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 **);

/*
Expand Down
36 changes: 36 additions & 0 deletions t/t7201-co.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down