Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 41bc59c

Browse files
committed
Merge remote-tracking branch 'kblees/kb/fscache-v4-tentative-1.8.5' into thicket-1.8.5.2
2 parents e52e4ef + 1a62aa8 commit 41bc59c

14 files changed

+636
-66
lines changed

Documentation/config.txt

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

634+
core.fscache::
635+
Enable additional caching of file system data for some operations.
636+
+
637+
Git for Windows uses this to bulk-read and cache lstat data of entire
638+
directories (instead of doing lstat file by file).
639+
634640
core.createObject::
635641
You can set this to 'link', in which case a hardlink followed by
636642
a delete of the source are used to make sure that object creation

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13681368
PATHSPEC_PREFER_FULL,
13691369
prefix, argv);
13701370

1371+
enable_fscache(1);
13711372
read_cache_preload(&s.pathspec);
13721373
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13731374

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ enum hide_dotfiles_type {
648648
};
649649
extern enum hide_dotfiles_type hide_dotfiles;
650650

651+
extern int core_fscache;
652+
651653
enum branch_track {
652654
BRANCH_TRACK_UNSPECIFIED = -1,
653655
BRANCH_TRACK_NEVER = 0,

compat/mingw.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -474,22 +474,6 @@ int mingw_chmod(const char *filename, int mode)
474474
return _wchmod(wfilename, mode);
475475
}
476476

477-
/*
478-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
479-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
480-
*/
481-
static inline long long filetime_to_hnsec(const FILETIME *ft)
482-
{
483-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
484-
/* Windows to Unix Epoch conversion */
485-
return winTime - 116444736000000000LL;
486-
}
487-
488-
static inline time_t filetime_to_time_t(const FILETIME *ft)
489-
{
490-
return (time_t)(filetime_to_hnsec(ft) / 10000000);
491-
}
492-
493477
/* We keep the do_lstat code in a separate function to avoid recursion.
494478
* When a path ends with a slash, the stat will fail with ENOENT. In
495479
* this case, we strip the trailing slashes and stat again.
@@ -590,6 +574,8 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
590574
return do_lstat(follow, alt_name, buf);
591575
}
592576

577+
int (*lstat)(const char *file_name, struct stat *buf) = mingw_lstat;
578+
593579
int mingw_lstat(const char *file_name, struct stat *buf)
594580
{
595581
return do_stat_internal(0, file_name, buf);

compat/mingw.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
277277
return 0;
278278
}
279279

280+
/*
281+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
282+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
283+
*/
284+
static inline long long filetime_to_hnsec(const FILETIME *ft)
285+
{
286+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
287+
/* Windows to Unix Epoch conversion */
288+
return winTime - 116444736000000000LL;
289+
}
290+
291+
static inline time_t filetime_to_time_t(const FILETIME *ft)
292+
{
293+
return (time_t)(filetime_to_hnsec(ft) / 10000000);
294+
}
295+
280296
/*
281297
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
282298
*/
@@ -298,7 +314,7 @@ int mingw_fstat(int fd, struct stat *buf);
298314
#ifdef lstat
299315
#undef lstat
300316
#endif
301-
#define lstat mingw_lstat
317+
extern int (*lstat)(const char *file_name, struct stat *buf);
302318

303319
#ifndef _stati64
304320
# 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)