Skip to content

Commit bf971c4

Browse files
committed
Merge 'fscache' into HEAD
2 parents bc18d18 + 4ed3ad6 commit bf971c4

File tree

14 files changed

+636
-66
lines changed

14 files changed

+636
-66
lines changed

Documentation/config.txt

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

716+
core.fscache::
717+
Enable additional caching of file system data for some operations.
718+
+
719+
Git for Windows uses this to bulk-read and cache lstat data of entire
720+
directories (instead of doing lstat file by file).
721+
716722
core.createObject::
717723
You can set this to 'link', in which case a hardlink followed by
718724
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
@@ -1362,6 +1362,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13621362
PATHSPEC_PREFER_FULL,
13631363
prefix, argv);
13641364

1365+
enable_fscache(1);
13651366
read_cache_preload(&s.pathspec);
13661367
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13671368

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ enum hide_dotfiles_type {
683683
};
684684
extern enum hide_dotfiles_type hide_dotfiles;
685685

686+
extern int core_fscache;
687+
686688
enum branch_track {
687689
BRANCH_TRACK_UNSPECIFIED = -1,
688690
BRANCH_TRACK_NEVER = 0,

compat/mingw.c

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

496-
/*
497-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
498-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
499-
*/
500-
static inline long long filetime_to_hnsec(const FILETIME *ft)
501-
{
502-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
503-
/* Windows to Unix Epoch conversion */
504-
return winTime - 116444736000000000LL;
505-
}
506-
507-
static inline time_t filetime_to_time_t(const FILETIME *ft)
508-
{
509-
return (time_t)(filetime_to_hnsec(ft) / 10000000);
510-
}
511-
512496
/**
513497
* Verifies that safe_create_leading_directories() would succeed.
514498
*/
@@ -648,6 +632,8 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
648632
return do_lstat(follow, alt_name, buf);
649633
}
650634

635+
int (*lstat)(const char *file_name, struct stat *buf) = mingw_lstat;
636+
651637
int mingw_lstat(const char *file_name, struct stat *buf)
652638
{
653639
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
@@ -318,6 +318,22 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
318318
return 0;
319319
}
320320

321+
/*
322+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
323+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
324+
*/
325+
static inline long long filetime_to_hnsec(const FILETIME *ft)
326+
{
327+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
328+
/* Windows to Unix Epoch conversion */
329+
return winTime - 116444736000000000LL;
330+
}
331+
332+
static inline time_t filetime_to_time_t(const FILETIME *ft)
333+
{
334+
return (time_t)(filetime_to_hnsec(ft) / 10000000);
335+
}
336+
321337
/*
322338
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
323339
*/
@@ -341,7 +357,7 @@ int mingw_fstat(int fd, struct stat *buf);
341357
#ifdef lstat
342358
#undef lstat
343359
#endif
344-
#define lstat mingw_lstat
360+
extern int (*lstat)(const char *file_name, struct stat *buf);
345361

346362
#ifndef _stati64
347363
# 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)