Skip to content

Commit 1c6a5aa

Browse files
committed
Merge pull request git-for-windows#1344 from jeffhostetler/perf_add_excludes_with_fscache
dir.c: make add_excludes aware of fscache during status
2 parents 8cea276 + 6221b5c commit 1c6a5aa

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

compat/win32/fscache.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ static struct hashmap map;
99
static CRITICAL_SECTION mutex;
1010
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
1111

12+
int fscache_is_enabled(void)
13+
{
14+
return enabled;
15+
}
16+
1217
/*
1318
* An entry in the file system cache. Used for both entire directory listings
1419
* and file entries.

compat/win32/fscache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
int fscache_enable(int enable);
55
#define enable_fscache(x) fscache_enable(x)
66

7+
int fscache_is_enabled(void);
8+
#define is_fscache_enabled() (fscache_is_enabled())
9+
710
DIR *fscache_opendir(const char *dir);
811
int fscache_lstat(const char *file_name, struct stat *buf);
912

dir.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,27 @@ static int add_excludes(const char *fname, const char *base, int baselen,
817817
size_t size = 0;
818818
char *buf;
819819

820-
fd = open(fname, O_RDONLY);
821-
if (fd < 0 || fstat(fd, &st) < 0) {
822-
if (fd < 0)
823-
warn_on_fopen_errors(fname);
824-
else
825-
close(fd);
820+
if (is_fscache_enabled()) {
821+
if (lstat(fname, &st) < 0) {
822+
fd = -1;
823+
} else {
824+
fd = open(fname, O_RDONLY);
825+
if (fd < 0)
826+
warn_on_fopen_errors(fname);
827+
}
828+
} else {
829+
fd = open(fname, O_RDONLY);
830+
if (fd < 0 || fstat(fd, &st) < 0) {
831+
if (fd < 0)
832+
warn_on_fopen_errors(fname);
833+
else {
834+
close(fd);
835+
fd = -1;
836+
}
837+
}
838+
}
839+
840+
if (fd < 0) {
826841
if (!istate)
827842
return -1;
828843
r = read_skip_worktree_file_from_index(istate, fname,

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,10 @@ static inline int is_missing_file_error(int errno_)
12861286
#define enable_fscache(x) /* noop */
12871287
#endif
12881288

1289+
#ifndef is_fscache_enabled
1290+
#define is_fscache_enabled() (0)
1291+
#endif
1292+
12891293
extern int cmd_main(int, const char **);
12901294

12911295
/*

0 commit comments

Comments
 (0)