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

Commit

Permalink
Merge remote-tracking branch 'kblees/kb/fscache-v4-tentative-1.8.5' i…
Browse files Browse the repository at this point in the history
…nto thicket-1.8.5.2
  • Loading branch information
dscho committed May 10, 2014
2 parents 2588ee0 + 738ce02 commit 231f538
Show file tree
Hide file tree
Showing 14 changed files with 589 additions and 66 deletions.
6 changes: 6 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,12 @@ relatively high IO latencies. With this set to 'true', Git will do the
index comparison to the filesystem data in parallel, allowing
overlapping IO's.

core.fscache::
Enable additional caching of file system data for some operations.
+
Git for Windows uses this to bulk-read and cache lstat data of entire
directories (instead of doing lstat file by file).

core.createObject::
You can set this to 'link', in which case a hardlink followed by
a delete of the source are used to make sure that object creation
Expand Down
1 change: 1 addition & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
PATHSPEC_PREFER_FULL,
prefix, argv);

enable_fscache(1);
read_cache_preload(&s.pathspec);
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);

Expand Down
2 changes: 2 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ enum hide_dotfiles_type {
};
extern enum hide_dotfiles_type hide_dotfiles;

extern int core_fscache;

enum branch_track {
BRANCH_TRACK_UNSPECIFIED = -1,
BRANCH_TRACK_NEVER = 0,
Expand Down
18 changes: 2 additions & 16 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,22 +474,6 @@ int mingw_chmod(const char *filename, int mode)
return _wchmod(wfilename, mode);
}

/*
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
*/
static inline long long filetime_to_hnsec(const FILETIME *ft)
{
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
/* Windows to Unix Epoch conversion */
return winTime - 116444736000000000LL;
}

static inline time_t filetime_to_time_t(const FILETIME *ft)
{
return (time_t)(filetime_to_hnsec(ft) / 10000000);
}

/* We keep the do_lstat code in a separate function to avoid recursion.
* When a path ends with a slash, the stat will fail with ENOENT. In
* this case, we strip the trailing slashes and stat again.
Expand Down Expand Up @@ -590,6 +574,8 @@ static int do_stat_internal(int follow, const char *file_name, struct stat *buf)
return do_lstat(follow, alt_name, buf);
}

int (*lstat)(const char *file_name, struct stat *buf) = mingw_lstat;

int mingw_lstat(const char *file_name, struct stat *buf)
{
return do_stat_internal(0, file_name, buf);
Expand Down
18 changes: 17 additions & 1 deletion compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
return 0;
}

/*
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
*/
static inline long long filetime_to_hnsec(const FILETIME *ft)
{
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
/* Windows to Unix Epoch conversion */
return winTime - 116444736000000000LL;
}

static inline time_t filetime_to_time_t(const FILETIME *ft)
{
return (time_t)(filetime_to_hnsec(ft) / 10000000);
}

/*
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
*/
Expand All @@ -295,7 +311,7 @@ int mingw_fstat(int fd, struct stat *buf);
#ifdef lstat
#undef lstat
#endif
#define lstat mingw_lstat
extern int (*lstat)(const char *file_name, struct stat *buf);

#ifndef _stati64
# define _stati64(x,y) mingw_stat(x,y)
Expand Down
87 changes: 47 additions & 40 deletions compat/win32/dirent.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#include "../../git-compat-util.h"

struct DIR {
typedef struct dirent_DIR {
struct DIR base_dir; /* extend base struct DIR */
struct dirent dd_dir; /* includes d_type */
HANDLE dd_handle; /* FindFirstFile handle */
int dd_stat; /* 0-based index */
};
char dd_name[MAX_PATH * 3]; /* file name (* 3 for UTF-8 conversion) */
} dirent_DIR;

DIR *(*opendir)(const char *dirname) = dirent_opendir;

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

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

DIR *opendir(const char *name)
{
wchar_t pattern[MAX_PATH + 2]; /* + 2 for '/' '*' */
WIN32_FIND_DATAW fdata;
HANDLE h;
int len;
DIR *dir;

/* convert name to UTF-16 and check length < MAX_PATH */
if ((len = xutftowcs_path(pattern, name)) < 0)
return NULL;

/* append optional '/' and wildcard '*' */
if (len && !is_dir_sep(pattern[len - 1]))
pattern[len++] = '/';
pattern[len++] = '*';
pattern[len] = 0;

/* open find handle */
h = FindFirstFileW(pattern, &fdata);
if (h == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
return NULL;
}

/* initialize DIR structure and copy first dir entry */
dir = xmalloc(sizeof(DIR));
dir->dd_handle = h;
dir->dd_stat = 0;
finddata2dirent(&dir->dd_dir, &fdata);
return dir;
}

struct dirent *readdir(DIR *dir)
static struct dirent *dirent_readdir(dirent_DIR *dir)
{
if (!dir) {
errno = EBADF; /* No set_errno for mingw */
Expand All @@ -79,7 +49,7 @@ struct dirent *readdir(DIR *dir)
return &dir->dd_dir;
}

int closedir(DIR *dir)
static int dirent_closedir(dirent_DIR *dir)
{
if (!dir) {
errno = EBADF;
Expand All @@ -90,3 +60,40 @@ int closedir(DIR *dir)
free(dir);
return 0;
}

DIR *dirent_opendir(const char *name)
{
wchar_t pattern[MAX_PATH + 2]; /* + 2 for '/' '*' */
WIN32_FIND_DATAW fdata;
HANDLE h;
int len;
dirent_DIR *dir;

/* convert name to UTF-16 and check length < MAX_PATH */
if ((len = xutftowcs_path(pattern, name)) < 0)
return NULL;

/* append optional '/' and wildcard '*' */
if (len && !is_dir_sep(pattern[len - 1]))
pattern[len++] = '/';
pattern[len++] = '*';
pattern[len] = 0;

/* open find handle */
h = FindFirstFileW(pattern, &fdata);
if (h == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
return NULL;
}

/* initialize DIR structure and copy first dir entry */
dir = xmalloc(sizeof(dirent_DIR));
dir->base_dir.preaddir = (struct dirent *(*)(DIR *dir)) dirent_readdir;
dir->base_dir.pclosedir = (int (*)(DIR *dir)) dirent_closedir;
dir->dd_dir.d_name = dir->dd_name;
dir->dd_handle = h;
dir->dd_stat = 0;
finddata2dirent(&dir->dd_dir, &fdata);
return (DIR*) dir;
}
26 changes: 19 additions & 7 deletions compat/win32/dirent.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
#ifndef DIRENT_H
#define DIRENT_H

typedef struct DIR DIR;

#define DT_UNKNOWN 0
#define DT_DIR 1
#define DT_REG 2
#define DT_LNK 3

struct dirent {
unsigned char d_type; /* file type to prevent lstat after readdir */
char d_name[MAX_PATH * 3]; /* file name (* 3 for UTF-8 conversion) */
unsigned char d_type; /* file type to prevent lstat after readdir */
char *d_name; /* file name */
};

DIR *opendir(const char *dirname);
struct dirent *readdir(DIR *dir);
int closedir(DIR *dir);
/*
* Base DIR structure, contains pointers to readdir/closedir implementations so
* that opendir may choose a concrete implementation on a call-by-call basis.
*/
typedef struct DIR {
struct dirent *(*preaddir)(struct DIR *dir);
int (*pclosedir)(struct DIR *dir);
} DIR;

/* default dirent implementation */
extern DIR *dirent_opendir(const char *dirname);

/* current dirent implementation */
extern DIR *(*opendir)(const char *dirname);

#define readdir(dir) (dir->preaddir(dir))
#define closedir(dir) (dir->pclosedir(dir))

#endif /* DIRENT_H */
Loading

0 comments on commit 231f538

Please sign in to comment.