Skip to content

Commit 1ad0b30

Browse files
kbleesdscho
authored andcommitted
add infrastructure for read-only file system level caches
Add a macro to mark code sections that only read from the file system, along with a config option and documentation. This facilitates implementation of relatively simple file system level caches without the need to synchronize with the file system. Enable read-only sections for 'git status' and preload_index. Signed-off-by: Karsten Blees <[email protected]>
1 parent cb6ccff commit 1ad0b30

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
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
@@ -1541,6 +1541,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15411541
PATHSPEC_PREFER_FULL,
15421542
prefix, argv);
15431543

1544+
enable_fscache(1);
15441545
if (status_format != STATUS_FORMAT_PORCELAIN &&
15451546
status_format != STATUS_FORMAT_PORCELAIN_V2)
15461547
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ enum hide_dotfiles_type {
232232
static int core_restrict_inherited_handles = -1;
233233
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
234234
static char *unset_environment_variables;
235+
int core_fscache;
235236

236237
int mingw_core_config(const char *var, const char *value, void *cb)
237238
{
@@ -243,6 +244,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
243244
return 0;
244245
}
245246

247+
if (!strcmp(var, "core.fscache")) {
248+
core_fscache = git_config_bool(var, value);
249+
return 0;
250+
}
251+
246252
if (!strcmp(var, "core.unsetenvvars")) {
247253
free(unset_environment_variables);
248254
unset_environment_variables = xstrdup(value);

compat/mingw.h

Lines changed: 2 additions & 0 deletions
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

git-compat-util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,21 @@ static inline int is_missing_file_error(int errno_)
13771377
return (errno_ == ENOENT || errno_ == ENOTDIR);
13781378
}
13791379

1380+
/*
1381+
* Enable/disable a read-only cache for file system data on platforms that
1382+
* support it.
1383+
*
1384+
* Implementing a live-cache is complicated and requires special platform
1385+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1386+
* to mark sections of git code that extensively read from the file system
1387+
* without modifying anything. Implementations can use this to cache e.g. stat
1388+
* data or even file content without the need to synchronize with the file
1389+
* system.
1390+
*/
1391+
#ifndef enable_fscache
1392+
#define enable_fscache(x) /* noop */
1393+
#endif
1394+
13801395
int cmd_main(int, const char **);
13811396

13821397
/*

preload-index.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void preload_index(struct index_state *index,
126126
pthread_mutex_init(&pd.mutex, NULL);
127127
}
128128

129+
enable_fscache(1);
129130
for (i = 0; i < threads; i++) {
130131
struct thread_data *p = data+i;
131132
int err;
@@ -155,6 +156,8 @@ void preload_index(struct index_state *index,
155156

156157
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
157158
trace2_region_leave("index", "preload", NULL);
159+
160+
enable_fscache(0);
158161
}
159162

160163
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)