Skip to content

Commit 26b6ffb

Browse files
committed
Merge 'fscache' into HEAD
2 parents b439d17 + 58358e7 commit 26b6ffb

File tree

11 files changed

+636
-66
lines changed

11 files changed

+636
-66
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,12 @@ relatively high IO latencies. When enabled, Git will do the
760760
index comparison to the filesystem data in parallel, allowing
761761
overlapping IO's. Defaults to true.
762762

763+
core.fscache::
764+
Enable additional caching of file system data for some operations.
765+
+
766+
Git for Windows uses this to bulk-read and cache lstat data of entire
767+
directories (instead of doing lstat file by file).
768+
763769
core.unsetenvvars::
764770
EXPERIMENTAL, Windows-only: comma-separated list of environment
765771
variables' names that need to be unset before spawning any other

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13771377
PATHSPEC_PREFER_FULL,
13781378
prefix, argv);
13791379

1380+
enable_fscache(1);
13801381
read_cache_preload(&s.pathspec);
13811382
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13821383

compat/mingw.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ enum hide_dotfiles_type {
211211

212212
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
213213
static char *unset_environment_variables;
214+
int core_fscache;
214215

215216
int mingw_core_config(const char *var, const char *value)
216217
{
@@ -222,6 +223,11 @@ int mingw_core_config(const char *var, const char *value)
222223
return 0;
223224
}
224225

226+
if (!strcmp(var, "core.fscache")) {
227+
core_fscache = git_config_bool(var, value);
228+
return 0;
229+
}
230+
225231
if (!strcmp(var, "core.unsetenvvars")) {
226232
free(unset_environment_variables);
227233
unset_environment_variables = xstrdup(value);
@@ -541,22 +547,6 @@ int mingw_chmod(const char *filename, int mode)
541547
return _wchmod(wfilename, mode);
542548
}
543549

544-
/*
545-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
546-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
547-
*/
548-
static inline long long filetime_to_hnsec(const FILETIME *ft)
549-
{
550-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
551-
/* Windows to Unix Epoch conversion */
552-
return winTime - 116444736000000000LL;
553-
}
554-
555-
static inline time_t filetime_to_time_t(const FILETIME *ft)
556-
{
557-
return (time_t)(filetime_to_hnsec(ft) / 10000000);
558-
}
559-
560550
/**
561551
* Verifies that safe_create_leading_directories() would succeed.
562552
*/
@@ -696,6 +686,8 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
696686
return do_lstat(follow, alt_name, buf);
697687
}
698688

689+
int (*lstat)(const char *file_name, struct stat *buf) = mingw_lstat;
690+
699691
int mingw_lstat(const char *file_name, struct stat *buf)
700692
{
701693
return do_stat_internal(0, file_name, buf);

compat/mingw.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ typedef _sigset_t sigset_t;
1111
#undef _POSIX_THREAD_SAFE_FUNCTIONS
1212
#endif
1313

14+
extern int core_fscache;
15+
1416
extern int mingw_core_config(const char *var, const char *value);
1517
#define platform_core_config mingw_core_config
1618

@@ -329,6 +331,22 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
329331
return 0;
330332
}
331333

334+
/*
335+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
336+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
337+
*/
338+
static inline long long filetime_to_hnsec(const FILETIME *ft)
339+
{
340+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
341+
/* Windows to Unix Epoch conversion */
342+
return winTime - 116444736000000000LL;
343+
}
344+
345+
static inline time_t filetime_to_time_t(const FILETIME *ft)
346+
{
347+
return (time_t)(filetime_to_hnsec(ft) / 10000000);
348+
}
349+
332350
/*
333351
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
334352
*/
@@ -352,7 +370,7 @@ int mingw_fstat(int fd, struct stat *buf);
352370
#ifdef lstat
353371
#undef lstat
354372
#endif
355-
#define lstat mingw_lstat
373+
extern int (*lstat)(const char *file_name, struct stat *buf);
356374

357375
#ifndef _stati64
358376
# define _stati64(x,y) mingw_stat(x,y)

compat/win32/dirent.c

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#include "../../git-compat-util.h"
22

3-
struct DIR {
3+
typedef struct dirent_DIR {
4+
struct DIR base_dir; /* extend base struct DIR */
45
struct dirent dd_dir; /* includes d_type */
56
HANDLE dd_handle; /* FindFirstFile handle */
67
int dd_stat; /* 0-based index */
7-
};
8+
char dd_name[MAX_PATH * 3]; /* file name (* 3 for UTF-8 conversion) */
9+
} dirent_DIR;
10+
11+
DIR *(*opendir)(const char *dirname) = dirent_opendir;
812

913
static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1014
{
11-
/* convert UTF-16 name to UTF-8 */
12-
xwcstoutf(ent->d_name, fdata->cFileName, sizeof(ent->d_name));
15+
/* convert UTF-16 name to UTF-8 (d_name points to dirent_DIR.dd_name) */
16+
xwcstoutf(ent->d_name, fdata->cFileName, MAX_PATH * 3);
1317

1418
/* Set file type, based on WIN32_FIND_DATA */
1519
if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
@@ -18,41 +22,7 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1822
ent->d_type = DT_REG;
1923
}
2024

21-
DIR *opendir(const char *name)
22-
{
23-
wchar_t pattern[MAX_PATH + 2]; /* + 2 for '/' '*' */
24-
WIN32_FIND_DATAW fdata;
25-
HANDLE h;
26-
int len;
27-
DIR *dir;
28-
29-
/* convert name to UTF-16 and check length < MAX_PATH */
30-
if ((len = xutftowcs_path(pattern, name)) < 0)
31-
return NULL;
32-
33-
/* append optional '/' and wildcard '*' */
34-
if (len && !is_dir_sep(pattern[len - 1]))
35-
pattern[len++] = '/';
36-
pattern[len++] = '*';
37-
pattern[len] = 0;
38-
39-
/* open find handle */
40-
h = FindFirstFileW(pattern, &fdata);
41-
if (h == INVALID_HANDLE_VALUE) {
42-
DWORD err = GetLastError();
43-
errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
44-
return NULL;
45-
}
46-
47-
/* initialize DIR structure and copy first dir entry */
48-
dir = xmalloc(sizeof(DIR));
49-
dir->dd_handle = h;
50-
dir->dd_stat = 0;
51-
finddata2dirent(&dir->dd_dir, &fdata);
52-
return dir;
53-
}
54-
55-
struct dirent *readdir(DIR *dir)
25+
static struct dirent *dirent_readdir(dirent_DIR *dir)
5626
{
5727
if (!dir) {
5828
errno = EBADF; /* No set_errno for mingw */
@@ -79,7 +49,7 @@ struct dirent *readdir(DIR *dir)
7949
return &dir->dd_dir;
8050
}
8151

82-
int closedir(DIR *dir)
52+
static int dirent_closedir(dirent_DIR *dir)
8353
{
8454
if (!dir) {
8555
errno = EBADF;
@@ -90,3 +60,40 @@ int closedir(DIR *dir)
9060
free(dir);
9161
return 0;
9262
}
63+
64+
DIR *dirent_opendir(const char *name)
65+
{
66+
wchar_t pattern[MAX_PATH + 2]; /* + 2 for '/' '*' */
67+
WIN32_FIND_DATAW fdata;
68+
HANDLE h;
69+
int len;
70+
dirent_DIR *dir;
71+
72+
/* convert name to UTF-16 and check length < MAX_PATH */
73+
if ((len = xutftowcs_path(pattern, name)) < 0)
74+
return NULL;
75+
76+
/* append optional '/' and wildcard '*' */
77+
if (len && !is_dir_sep(pattern[len - 1]))
78+
pattern[len++] = '/';
79+
pattern[len++] = '*';
80+
pattern[len] = 0;
81+
82+
/* open find handle */
83+
h = FindFirstFileW(pattern, &fdata);
84+
if (h == INVALID_HANDLE_VALUE) {
85+
DWORD err = GetLastError();
86+
errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
87+
return NULL;
88+
}
89+
90+
/* initialize DIR structure and copy first dir entry */
91+
dir = xmalloc(sizeof(dirent_DIR));
92+
dir->base_dir.preaddir = (struct dirent *(*)(DIR *dir)) dirent_readdir;
93+
dir->base_dir.pclosedir = (int (*)(DIR *dir)) dirent_closedir;
94+
dir->dd_dir.d_name = dir->dd_name;
95+
dir->dd_handle = h;
96+
dir->dd_stat = 0;
97+
finddata2dirent(&dir->dd_dir, &fdata);
98+
return (DIR*) dir;
99+
}

compat/win32/dirent.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
#ifndef DIRENT_H
22
#define DIRENT_H
33

4-
typedef struct DIR DIR;
5-
64
#define DT_UNKNOWN 0
75
#define DT_DIR 1
86
#define DT_REG 2
97
#define DT_LNK 3
108

119
struct dirent {
12-
unsigned char d_type; /* file type to prevent lstat after readdir */
13-
char d_name[MAX_PATH * 3]; /* file name (* 3 for UTF-8 conversion) */
10+
unsigned char d_type; /* file type to prevent lstat after readdir */
11+
char *d_name; /* file name */
1412
};
1513

16-
DIR *opendir(const char *dirname);
17-
struct dirent *readdir(DIR *dir);
18-
int closedir(DIR *dir);
14+
/*
15+
* Base DIR structure, contains pointers to readdir/closedir implementations so
16+
* that opendir may choose a concrete implementation on a call-by-call basis.
17+
*/
18+
typedef struct DIR {
19+
struct dirent *(*preaddir)(struct DIR *dir);
20+
int (*pclosedir)(struct DIR *dir);
21+
} DIR;
22+
23+
/* default dirent implementation */
24+
extern DIR *dirent_opendir(const char *dirname);
25+
26+
/* current dirent implementation */
27+
extern DIR *(*opendir)(const char *dirname);
28+
29+
#define readdir(dir) (dir->preaddir(dir))
30+
#define closedir(dir) (dir->pclosedir(dir))
1931

2032
#endif /* DIRENT_H */

0 commit comments

Comments
 (0)