Skip to content

Commit 03537b5

Browse files
committed
Merge branch 'fscache'
2 parents 7217678 + 375e03b commit 03537b5

File tree

12 files changed

+635
-70
lines changed

12 files changed

+635
-70
lines changed

Documentation/config/core.txt

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

595+
core.fscache::
596+
Enable additional caching of file system data for some operations.
597+
+
598+
Git for Windows uses this to bulk-read and cache lstat data of entire
599+
directories (instead of doing lstat file by file).
600+
595601
core.unsetenvvars::
596602
Windows-only: comma-separated list of environment variables'
597603
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
@@ -1538,6 +1538,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15381538
PATHSPEC_PREFER_FULL,
15391539
prefix, argv);
15401540

1541+
enable_fscache(1);
15411542
if (status_format != STATUS_FORMAT_PORCELAIN &&
15421543
status_format != STATUS_FORMAT_PORCELAIN_V2)
15431544
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ enum hide_dotfiles_type {
229229
static int core_restrict_inherited_handles = -1;
230230
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
231231
static char *unset_environment_variables;
232+
int core_fscache;
232233

233234
int mingw_core_config(const char *var, const char *value, void *cb)
234235
{
@@ -240,6 +241,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
240241
return 0;
241242
}
242243

244+
if (!strcmp(var, "core.fscache")) {
245+
core_fscache = git_config_bool(var, value);
246+
return 0;
247+
}
248+
243249
if (!strcmp(var, "core.unsetenvvars")) {
244250
free(unset_environment_variables);
245251
unset_environment_variables = xstrdup(value);
@@ -730,24 +736,6 @@ int mingw_chmod(const char *filename, int mode)
730736
return _wchmod(wfilename, mode);
731737
}
732738

733-
/*
734-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
735-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
736-
*/
737-
static inline long long filetime_to_hnsec(const FILETIME *ft)
738-
{
739-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
740-
/* Windows to Unix Epoch conversion */
741-
return winTime - 116444736000000000LL;
742-
}
743-
744-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
745-
{
746-
long long hnsec = filetime_to_hnsec(ft);
747-
ts->tv_sec = (time_t)(hnsec / 10000000);
748-
ts->tv_nsec = (hnsec % 10000000) * 100;
749-
}
750-
751739
/**
752740
* Verifies that safe_create_leading_directories() would succeed.
753741
*/
@@ -887,6 +875,8 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
887875
return do_lstat(follow, alt_name, buf);
888876
}
889877

878+
int (*lstat)(const char *file_name, struct stat *buf) = mingw_lstat;
879+
890880
static int get_file_info_by_handle(HANDLE hnd, struct stat *buf)
891881
{
892882
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

@@ -345,6 +347,17 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
345347
return 0;
346348
}
347349

350+
/*
351+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
352+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
353+
*/
354+
static inline long long filetime_to_hnsec(const FILETIME *ft)
355+
{
356+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
357+
/* Windows to Unix Epoch conversion */
358+
return winTime - 116444736000000000LL;
359+
}
360+
348361
/*
349362
* Use mingw specific stat()/lstat()/fstat() implementations on Windows,
350363
* including our own struct stat with 64 bit st_size and nanosecond-precision
@@ -361,6 +374,13 @@ struct timespec {
361374
#endif
362375
#endif
363376

377+
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
378+
{
379+
long long hnsec = filetime_to_hnsec(ft);
380+
ts->tv_sec = (time_t)(hnsec / 10000000);
381+
ts->tv_nsec = (hnsec % 10000000) * 100;
382+
}
383+
364384
struct mingw_stat {
365385
_dev_t st_dev;
366386
_ino_t st_ino;
@@ -393,7 +413,7 @@ int mingw_fstat(int fd, struct stat *buf);
393413
#ifdef lstat
394414
#undef lstat
395415
#endif
396-
#define lstat mingw_lstat
416+
extern int (*lstat)(const char *file_name, struct stat *buf);
397417

398418

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

compat/win32/dirent.c

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

3-
struct DIR {
4-
struct dirent dd_dir; /* includes d_type */
3+
typedef struct dirent_DIR {
4+
struct DIR base_dir; /* extend base struct DIR */
55
HANDLE dd_handle; /* FindFirstFile handle */
66
int dd_stat; /* 0-based index */
7-
};
7+
struct dirent dd_dir; /* includes d_type */
8+
} dirent_DIR;
9+
10+
DIR *(*opendir)(const char *dirname) = dirent_opendir;
811

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

1417
/* Set file type, based on WIN32_FIND_DATA */
1518
if (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
@@ -18,41 +21,7 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1821
ent->d_type = DT_REG;
1922
}
2023

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)
24+
static struct dirent *dirent_readdir(dirent_DIR *dir)
5625
{
5726
if (!dir) {
5827
errno = EBADF; /* No set_errno for mingw */
@@ -79,7 +48,7 @@ struct dirent *readdir(DIR *dir)
7948
return &dir->dd_dir;
8049
}
8150

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

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)