Merge branch 'atetubou/fscache_checkout_flush'

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2019-02-07 14:33:13 +01:00
8 changed files with 119 additions and 7 deletions

View File

@@ -372,6 +372,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) {
@@ -390,6 +391,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, &nr_checkouts);
if (opts->count_checkout_paths) {

View File

@@ -259,7 +259,7 @@ static void fscache_clear(void)
/*
* Checks if the cache is enabled for the given path.
*/
static inline int fscache_enabled(const char *path)
int fscache_enabled(const char *path)
{
return enabled > 0 && !is_absolute_path(path);
}
@@ -430,6 +430,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.

View File

@@ -4,6 +4,12 @@
int fscache_enable(int enable);
#define enable_fscache(x) fscache_enable(x)
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);

55
dir.c
View File

@@ -786,12 +786,55 @@ static int add_excludes(const char *fname, const char *base, int baselen,
size_t size = 0;
char *buf;
fd = open(fname, O_RDONLY);
if (fd < 0 || fstat(fd, &st) < 0) {
if (fd < 0)
warn_on_fopen_errors(fname);
else
close(fd);
/*
* A performance optimization for status.
*
* During a status scan, git looks in each directory for a .gitignore
* file before scanning the directory. Since .gitignore files are not
* that common, we can waste a lot of time looking for files that are
* not there. Fortunately, the fscache already knows if the directory
* contains a .gitignore file, since it has already read the directory
* and it already has the stat-data.
*
* If the fscache is enabled, use the fscache-lstat() interlude to see
* if the file exists (in the fscache hash maps) before trying to open()
* it.
*
* This causes problem when the .gitignore file is a symlink, because
* we call lstat() rather than stat() on the symlnk and the resulting
* stat-data is for the symlink itself rather than the target file.
* We CANNOT use stat() here because the fscache DOES NOT install an
* interlude for stat() and mingw_stat() always calls "open-fstat-close"
* on the file and defeats the purpose of the optimization here. Since
* symlinks are even more rare than .gitignore files, we force a fstat()
* after our open() to get stat-data for the target file.
*/
if (is_fscache_enabled(fname)) {
if (lstat(fname, &st) < 0) {
fd = -1;
} else {
fd = open(fname, O_RDONLY);
if (fd < 0)
warn_on_fopen_errors(fname);
else if (S_ISLNK(st.st_mode) && fstat(fd, &st) < 0) {
warn_on_fopen_errors(fname);
close(fd);
fd = -1;
}
}
} else {
fd = open(fname, O_RDONLY);
if (fd < 0 || fstat(fd, &st) < 0) {
if (fd < 0)
warn_on_fopen_errors(fname);
else {
close(fd);
fd = -1;
}
}
}
if (fd < 0) {
if (!istate)
return -1;
r = read_skip_worktree_file_from_index(istate, fname,

View File

@@ -367,6 +367,9 @@ static int write_entry(struct cache_entry *ce,
}
finish:
/* Flush cached lstat in fscache after writing to disk. */
flush_fscache();
if (state->refresh_cache) {
assert(state->istate);
if (!fstat_done)

View File

@@ -667,6 +667,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
save_commit_buffer = 0;
enable_fscache(1);
for (ref = *refs; ref; ref = ref->next) {
struct object *o;
@@ -687,6 +688,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
cutoff = commit->date;
}
}
enable_fscache(0);
if (!args->deepen) {
for_each_ref(mark_complete_oid, NULL);

View File

@@ -1275,6 +1275,14 @@ static inline int is_missing_file_error(int errno_)
#define enable_fscache(x) /* noop */
#endif
#ifndef is_fscache_enabled
#define is_fscache_enabled(path) (0)
#endif
#ifndef flush_fscache
#define flush_fscache() /* noop */
#endif
extern int cmd_main(int, const char **);
/*

View File

@@ -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 &&