Skip to content

Commit 8b2de9f

Browse files
author
Git for Windows Build Agent
committed
Merge pull request #1407 from jeffhostetler/regression_1392
dir.c: regression fix for add_excludes with fscache
2 parents 8814e96 + 3179321 commit 8b2de9f

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

compat/win32/fscache.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ 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-
1712
/*
1813
* An entry in the file system cache. Used for both entire directory listings
1914
* and file entries.
@@ -257,7 +252,7 @@ static void fscache_clear(void)
257252
/*
258253
* Checks if the cache is enabled for the given path.
259254
*/
260-
static inline int fscache_enabled(const char *path)
255+
int fscache_enabled(const char *path)
261256
{
262257
return enabled > 0 && !is_absolute_path(path);
263258
}

compat/win32/fscache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
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())
7+
int fscache_enabled(const char *path);
8+
#define is_fscache_enabled(path) fscache_enabled(path)
99

1010
DIR *fscache_opendir(const char *dir);
1111
int fscache_lstat(const char *file_name, struct stat *buf);

dir.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,13 +805,41 @@ static int add_excludes(const char *fname, const char *base, int baselen,
805805
size_t size = 0;
806806
char *buf;
807807

808-
if (is_fscache_enabled()) {
808+
/*
809+
* A performance optimization for status.
810+
*
811+
* During a status scan, git looks in each directory for a .gitignore
812+
* file before scanning the directory. Since .gitignore files are not
813+
* that common, we can waste a lot of time looking for files that are
814+
* not there. Fortunately, the fscache already knows if the directory
815+
* contains a .gitignore file, since it has already read the directory
816+
* and it already has the stat-data.
817+
*
818+
* If the fscache is enabled, use the fscache-lstat() interlude to see
819+
* if the file exists (in the fscache hash maps) before trying to open()
820+
* it.
821+
*
822+
* This causes problem when the .gitignore file is a symlink, because
823+
* we call lstat() rather than stat() on the symlnk and the resulting
824+
* stat-data is for the symlink itself rather than the target file.
825+
* We CANNOT use stat() here because the fscache DOES NOT install an
826+
* interlude for stat() and mingw_stat() always calls "open-fstat-close"
827+
* on the file and defeats the purpose of the optimization here. Since
828+
* symlinks are even more rare than .gitignore files, we force a fstat()
829+
* after our open() to get stat-data for the target file.
830+
*/
831+
if (is_fscache_enabled(fname)) {
809832
if (lstat(fname, &st) < 0) {
810833
fd = -1;
811834
} else {
812835
fd = open(fname, O_RDONLY);
813836
if (fd < 0)
814837
warn_on_fopen_errors(fname);
838+
else if (S_ISLNK(st.st_mode) && fstat(fd, &st) < 0) {
839+
warn_on_fopen_errors(fname);
840+
close(fd);
841+
fd = -1;
842+
}
815843
}
816844
} else {
817845
fd = open(fname, O_RDONLY);

git-compat-util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ static inline int is_missing_file_error(int errno_)
12791279
#endif
12801280

12811281
#ifndef is_fscache_enabled
1282-
#define is_fscache_enabled() (0)
1282+
#define is_fscache_enabled(path) (0)
12831283
#endif
12841284

12851285
extern int cmd_main(int, const char **);

0 commit comments

Comments
 (0)