Skip to content

Commit 29841ac

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 0ebbf09 commit 29841ac

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

Documentation/config/core.txt

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

551+
core.fscache::
552+
Enable additional caching of file system data for some operations.
553+
+
554+
Git for Windows uses this to bulk-read and cache lstat data of entire
555+
directories (instead of doing lstat file by file).
556+
551557
core.unsetenvvars::
552558
Windows-only: comma-separated list of environment variables'
553559
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
@@ -1363,6 +1363,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13631363
PATHSPEC_PREFER_FULL,
13641364
prefix, argv);
13651365

1366+
enable_fscache(1);
13661367
if (status_format != STATUS_FORMAT_PORCELAIN &&
13671368
status_format != STATUS_FORMAT_PORCELAIN_V2)
13681369
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ enum hide_dotfiles_type {
227227

228228
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
229229
static char *unset_environment_variables;
230+
int core_fscache;
230231

231232
int mingw_core_config(const char *var, const char *value, void *cb)
232233
{
@@ -238,6 +239,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
238239
return 0;
239240
}
240241

242+
if (!strcmp(var, "core.fscache")) {
243+
core_fscache = git_config_bool(var, value);
244+
return 0;
245+
}
246+
241247
if (!strcmp(var, "core.unsetenvvars")) {
242248
free(unset_environment_variables);
243249
unset_environment_variables = xstrdup(value);

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ typedef _sigset_t sigset_t;
3030
#undef _POSIX_THREAD_SAFE_FUNCTIONS
3131
#endif
3232

33+
extern int core_fscache;
34+
3335
extern int mingw_core_config(const char *var, const char *value, void *cb);
3436
#define platform_core_config mingw_core_config
3537

git-compat-util.h

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

1247+
/*
1248+
* Enable/disable a read-only cache for file system data on platforms that
1249+
* support it.
1250+
*
1251+
* Implementing a live-cache is complicated and requires special platform
1252+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1253+
* to mark sections of git code that extensively read from the file system
1254+
* without modifying anything. Implementations can use this to cache e.g. stat
1255+
* data or even file content without the need to synchronize with the file
1256+
* system.
1257+
*/
1258+
#ifndef enable_fscache
1259+
#define enable_fscache(x) /* noop */
1260+
#endif
1261+
12471262
extern int cmd_main(int, const char **);
12481263

12491264
/*

preload-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void preload_index(struct index_state *index,
119119
pthread_mutex_init(&pd.mutex, NULL);
120120
}
121121

122+
enable_fscache(1);
122123
for (i = 0; i < threads; i++) {
123124
struct thread_data *p = data+i;
124125
int err;
@@ -144,6 +145,7 @@ void preload_index(struct index_state *index,
144145
stop_progress(&pd.progress);
145146

146147
trace_performance_leave("preload index");
148+
enable_fscache(0);
147149
}
148150

149151
int read_index_preload(struct index_state *index,

0 commit comments

Comments
 (0)