Skip to content

Commit 037d27a

Browse files
jeffhostetlermjcheetham
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 99e7e06 commit 037d27a

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
@@ -1113,16 +1113,31 @@ static int add_patterns(const char *fname, const char *base, int baselen,
11131113
size_t size = 0;
11141114
char *buf;
11151115

1116-
if (flags & PATTERN_NOFOLLOW)
1117-
fd = open_nofollow(fname, O_RDONLY);
1118-
else
1119-
fd = open(fname, O_RDONLY);
1120-
1121-
if (fd < 0 || fstat(fd, &st) < 0) {
1122-
if (fd < 0)
1123-
warn_on_fopen_errors(fname);
1116+
if (is_fscache_enabled()) {
1117+
if (lstat(fname, &st) < 0) {
1118+
fd = -1;
1119+
} else {
1120+
fd = open(fname, O_RDONLY);
1121+
if (fd < 0)
1122+
warn_on_fopen_errors(fname);
1123+
}
1124+
} else {
1125+
if (flags & PATTERN_NOFOLLOW)
1126+
fd = open_nofollow(fname, O_RDONLY);
11241127
else
1125-
close(fd);
1128+
fd = open(fname, O_RDONLY);
1129+
1130+
if (fd < 0 || fstat(fd, &st) < 0) {
1131+
if (fd < 0)
1132+
warn_on_fopen_errors(fname);
1133+
else {
1134+
close(fd);
1135+
fd = -1;
1136+
}
1137+
}
1138+
}
1139+
1140+
if (fd < 0) {
11261141
if (!istate)
11271142
return -1;
11281143
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
@@ -1537,6 +1537,10 @@ static inline int is_missing_file_error(int errno_)
15371537
#define enable_fscache(x) /* noop */
15381538
#endif
15391539

1540+
#ifndef is_fscache_enabled
1541+
#define is_fscache_enabled() (0)
1542+
#endif
1543+
15401544
int cmd_main(int, const char **);
15411545

15421546
/*

0 commit comments

Comments
 (0)