Skip to content

Commit 177e510

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 2590ea3 commit 177e510

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
@@ -10,6 +10,11 @@ static struct hashmap map;
1010
static CRITICAL_SECTION mutex;
1111
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
1212

13+
int fscache_is_enabled(void)
14+
{
15+
return enabled;
16+
}
17+
1318
/*
1419
* An entry in the file system cache. Used for both entire directory listings
1520
* 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
@@ -1068,16 +1068,31 @@ static int add_patterns(const char *fname, const char *base, int baselen,
10681068
size_t size = 0;
10691069
char *buf;
10701070

1071-
if (flags & PATTERN_NOFOLLOW)
1072-
fd = open_nofollow(fname, O_RDONLY);
1073-
else
1074-
fd = open(fname, O_RDONLY);
1075-
1076-
if (fd < 0 || fstat(fd, &st) < 0) {
1077-
if (fd < 0)
1078-
warn_on_fopen_errors(fname);
1071+
if (is_fscache_enabled()) {
1072+
if (lstat(fname, &st) < 0) {
1073+
fd = -1;
1074+
} else {
1075+
fd = open(fname, O_RDONLY);
1076+
if (fd < 0)
1077+
warn_on_fopen_errors(fname);
1078+
}
1079+
} else {
1080+
if (flags & PATTERN_NOFOLLOW)
1081+
fd = open_nofollow(fname, O_RDONLY);
10791082
else
1080-
close(fd);
1083+
fd = open(fname, O_RDONLY);
1084+
1085+
if (fd < 0 || fstat(fd, &st) < 0) {
1086+
if (fd < 0)
1087+
warn_on_fopen_errors(fname);
1088+
else {
1089+
close(fd);
1090+
fd = -1;
1091+
}
1092+
}
1093+
}
1094+
1095+
if (fd < 0) {
10811096
if (!istate)
10821097
return -1;
10831098
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
@@ -1583,6 +1583,10 @@ static inline int is_missing_file_error(int errno_)
15831583
#define enable_fscache(x) /* noop */
15841584
#endif
15851585

1586+
#ifndef is_fscache_enabled
1587+
#define is_fscache_enabled() (0)
1588+
#endif
1589+
15861590
int cmd_main(int, const char **);
15871591

15881592
/*

0 commit comments

Comments
 (0)