Skip to content

Commit 81a696c

Browse files
committed
Merge branch 'fscache'
2 parents 24c99f4 + 0b571cf commit 81a696c

File tree

12 files changed

+647
-70
lines changed

12 files changed

+647
-70
lines changed

Documentation/config/core.txt

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

673+
core.fscache::
674+
Enable additional caching of file system data for some operations.
675+
+
676+
Git for Windows uses this to bulk-read and cache lstat data of entire
677+
directories (instead of doing lstat file by file).
678+
673679
core.unsetenvvars::
674680
Windows-only: comma-separated list of environment variables'
675681
names that need to be unset before spawning any other process.

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15541554
PATHSPEC_PREFER_FULL,
15551555
prefix, argv);
15561556

1557+
enable_fscache(1);
15571558
if (status_format != STATUS_FORMAT_PORCELAIN &&
15581559
status_format != STATUS_FORMAT_PORCELAIN_V2)
15591560
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ enum hide_dotfiles_type {
236236
static int core_restrict_inherited_handles = -1;
237237
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
238238
static char *unset_environment_variables;
239+
int core_fscache;
239240

240241
int mingw_core_config(const char *var, const char *value, void *cb)
241242
{
@@ -247,6 +248,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
247248
return 0;
248249
}
249250

251+
if (!strcmp(var, "core.fscache")) {
252+
core_fscache = git_config_bool(var, value);
253+
return 0;
254+
}
255+
250256
if (!strcmp(var, "core.unsetenvvars")) {
251257
free(unset_environment_variables);
252258
unset_environment_variables = xstrdup(value);
@@ -765,24 +771,6 @@ int mingw_chmod(const char *filename, int mode)
765771
return _wchmod(wfilename, mode);
766772
}
767773

768-
/*
769-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
770-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
771-
*/
772-
static inline long long filetime_to_hnsec(const FILETIME *ft)
773-
{
774-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
775-
/* Windows to Unix Epoch conversion */
776-
return winTime - 116444736000000000LL;
777-
}
778-
779-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
780-
{
781-
long long hnsec = filetime_to_hnsec(ft);
782-
ts->tv_sec = (time_t)(hnsec / 10000000);
783-
ts->tv_nsec = (hnsec % 10000000) * 100;
784-
}
785-
786774
/**
787775
* Verifies that safe_create_leading_directories() would succeed.
788776
*/
@@ -922,6 +910,8 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
922910
return do_lstat(follow, alt_name, buf);
923911
}
924912

913+
int (*lstat)(const char *file_name, struct stat *buf) = mingw_lstat;
914+
925915
static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
926916
{
927917
BY_HANDLE_FILE_INFORMATION fdata;

compat/mingw.h

Lines changed: 21 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
int mingw_core_config(const char *var, const char *value, void *cb);
1517
#define platform_core_config mingw_core_config
1618

@@ -351,6 +353,17 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
351353
return 0;
352354
}
353355

356+
/*
357+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
358+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
359+
*/
360+
static inline long long filetime_to_hnsec(const FILETIME *ft)
361+
{
362+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
363+
/* Windows to Unix Epoch conversion */
364+
return winTime - 116444736000000000LL;
365+
}
366+
354367
/*
355368
* Use mingw specific stat()/lstat()/fstat() implementations on Windows,
356369
* including our own struct stat with 64 bit st_size and nanosecond-precision
@@ -367,6 +380,13 @@ struct timespec {
367380
#endif
368381
#endif
369382

383+
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
384+
{
385+
long long hnsec = filetime_to_hnsec(ft);
386+
ts->tv_sec = (time_t)(hnsec / 10000000);
387+
ts->tv_nsec = (hnsec % 10000000) * 100;
388+
}
389+
370390
struct mingw_stat {
371391
_dev_t st_dev;
372392
_ino_t st_ino;
@@ -399,7 +419,7 @@ int mingw_fstat(int fd, struct stat *buf);
399419
#ifdef lstat
400420
#undef lstat
401421
#endif
402-
#define lstat mingw_lstat
422+
extern int (*lstat)(const char *file_name, struct stat *buf);
403423

404424

405425
int mingw_utime(const char *file_name, const struct utimbuf *times);

compat/win32/dirent.c

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

3-
struct DIR {
4-
struct dirent dd_dir; /* includes d_type */
3+
#pragma GCC diagnostic push
4+
#pragma GCC diagnostic ignored "-Wpedantic"
5+
typedef struct dirent_DIR {
6+
struct DIR base_dir; /* extend base struct DIR */
57
HANDLE dd_handle; /* FindFirstFile handle */
68
int dd_stat; /* 0-based index */
7-
};
9+
struct dirent dd_dir; /* includes d_type */
10+
} dirent_DIR;
11+
#pragma GCC diagnostic pop
12+
13+
DIR *(*opendir)(const char *dirname) = dirent_opendir;
814

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

1420
/* Set file type, based on WIN32_FIND_DATA */
1521
if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
@@ -18,41 +24,7 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1824
ent->d_type = DT_REG;
1925
}
2026

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)
27+
static struct dirent *dirent_readdir(dirent_DIR *dir)
5628
{
5729
if (!dir) {
5830
errno = EBADF; /* No set_errno for mingw */
@@ -79,7 +51,7 @@ struct dirent *readdir(DIR *dir)
7951
return &dir->dd_dir;
8052
}
8153

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

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[FLEX_ARRAY]; /* 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)