Skip to content

Commit 2fcde08

Browse files
jeffhostetlerdscho
authored andcommitted
dir.c: make add_excludes aware of fscache during status
Teach read_directory_recursive() and add_excludes() to be aware of optional fscache and avoid trying to open() and fstat() non-existant ".gitignore" files in every directory in the worktree. The current code in add_excludes() calls open() and then fstat() for a ".gitignore" file in each directory present in the worktree. Change that when fscache is enabled to call lstat() first and if present, call open(). This seems backwards because both lstat needs to do more work than fstat. But when fscache is enabled, fscache will already know if the .gitignore file exists and can completely avoid the IO calls. This works because of the lstat diversion to mingw_lstat when fscache is enabled. This reduced status times on a 350K file enlistment of the Windows repo on a NVMe SSD by 0.25 seconds. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 07fe740 commit 2fcde08

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

compat/win32/fscache.c

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

15+
int fscache_is_enabled(void)
16+
{
17+
return enabled;
18+
}
19+
1520
/*
1621
* An entry in the file system cache. Used for both entire directory listings
1722
* 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: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,16 +1081,31 @@ static int add_patterns(const char *fname, const char *base, int baselen,
10811081
size_t size = 0;
10821082
char *buf;
10831083

1084-
if (flags & PATTERN_NOFOLLOW)
1085-
fd = open_nofollow(fname, O_RDONLY);
1086-
else
1087-
fd = open(fname, O_RDONLY);
1088-
1089-
if (fd < 0 || fstat(fd, &st) < 0) {
1090-
if (fd < 0)
1091-
warn_on_fopen_errors(fname);
1084+
if (is_fscache_enabled()) {
1085+
if (lstat(fname, &st) < 0) {
1086+
fd = -1;
1087+
} else {
1088+
fd = open(fname, O_RDONLY);
1089+
if (fd < 0)
1090+
warn_on_fopen_errors(fname);
1091+
}
1092+
} else {
1093+
if (flags & PATTERN_NOFOLLOW)
1094+
fd = open_nofollow(fname, O_RDONLY);
10921095
else
1093-
close(fd);
1096+
fd = open(fname, O_RDONLY);
1097+
1098+
if (fd < 0 || fstat(fd, &st) < 0) {
1099+
if (fd < 0)
1100+
warn_on_fopen_errors(fname);
1101+
else {
1102+
close(fd);
1103+
fd = -1;
1104+
}
1105+
}
1106+
}
1107+
1108+
if (fd < 0) {
10941109
if (!istate)
10951110
return -1;
10961111
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
@@ -1495,6 +1495,10 @@ static inline int is_missing_file_error(int errno_)
14951495
#define enable_fscache(x) /* noop */
14961496
#endif
14971497

1498+
#ifndef is_fscache_enabled
1499+
#define is_fscache_enabled() (0)
1500+
#endif
1501+
14981502
int cmd_main(int, const char **);
14991503

15001504
/*

0 commit comments

Comments
 (0)