Skip to content

Commit 6ea19a9

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 136c2e1 commit 6ea19a9

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

Documentation/config.txt

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

883+
core.fscache::
884+
Enable additional caching of file system data for some operations.
885+
+
886+
Git for Windows uses this to bulk-read and cache lstat data of entire
887+
directories (instead of doing lstat file by file).
888+
883889
core.unsetenvvars::
884890
EXPERIMENTAL, Windows-only: comma-separated list of environment
885891
variables' names that need to be unset before spawning any other

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13221322
PATHSPEC_PREFER_FULL,
13231323
prefix, argv);
13241324

1325+
enable_fscache(1);
13251326
read_cache_preload(&s.pathspec);
13261327
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13271328

compat/mingw.c

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

212212
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
213213
static char *unset_environment_variables;
214+
int core_fscache;
214215

215216
int mingw_core_config(const char *var, const char *value, void *cb)
216217
{
@@ -222,6 +223,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
222223
return 0;
223224
}
224225

226+
if (!strcmp(var, "core.fscache")) {
227+
core_fscache = git_config_bool(var, value);
228+
return 0;
229+
}
230+
225231
if (!strcmp(var, "core.unsetenvvars")) {
226232
free(unset_environment_variables);
227233
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
extern 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
@@ -1217,6 +1217,21 @@ static inline int is_missing_file_error(int errno_)
12171217
return (errno_ == ENOENT || errno_ == ENOTDIR);
12181218
}
12191219

1220+
/*
1221+
* Enable/disable a read-only cache for file system data on platforms that
1222+
* support it.
1223+
*
1224+
* Implementing a live-cache is complicated and requires special platform
1225+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1226+
* to mark sections of git code that extensively read from the file system
1227+
* without modifying anything. Implementations can use this to cache e.g. stat
1228+
* data or even file content without the need to synchronize with the file
1229+
* system.
1230+
*/
1231+
#ifndef enable_fscache
1232+
#define enable_fscache(x) /* noop */
1233+
#endif
1234+
12201235
extern int cmd_main(int, const char **);
12211236

12221237
/*

preload-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static void preload_index(struct index_state *index,
9393
offset = 0;
9494
work = DIV_ROUND_UP(index->cache_nr, threads);
9595
memset(&data, 0, sizeof(data));
96+
enable_fscache(1);
9697
for (i = 0; i < threads; i++) {
9798
struct thread_data *p = data+i;
9899
p->index = index;
@@ -110,6 +111,7 @@ static void preload_index(struct index_state *index,
110111
die("unable to join threaded lstat");
111112
}
112113
trace_performance_since(start, "preload index");
114+
enable_fscache(0);
113115
}
114116
#endif
115117

0 commit comments

Comments
 (0)