Skip to content

Commit 8ddaf0f

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 142faef commit 8ddaf0f

File tree

7 files changed

+32
-0
lines changed

7 files changed

+32
-0
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,

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,11 @@ static int git_default_core_config(const char *var, const char *value)
920920
return 0;
921921
}
922922

923+
if (!strcmp(var, "core.fscache")) {
924+
core_fscache = git_config_bool(var, value);
925+
return 0;
926+
}
927+
923928
/* Add other config variables here and to Documentation/config.txt. */
924929
return 0;
925930
}

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
6767
struct startup_info *startup_info;
6868
unsigned long pack_size_limit_cfg;
6969
enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
70+
int core_fscache;
7071

7172
#ifndef PROTECT_HFS_DEFAULT
7273
#define PROTECT_HFS_DEFAULT 0

git-compat-util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,4 +954,19 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
954954
#define mark_as_git_dir(x) /* noop */
955955
#endif
956956

957+
/*
958+
* Enable/disable a read-only cache for file system data on platforms that
959+
* support it.
960+
*
961+
* Implementing a live-cache is complicated and requires special platform
962+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
963+
* to mark sections of git code that extensively read from the file system
964+
* without modifying anything. Implementations can use this to cache e.g. stat
965+
* data or even file content without the need to synchronize with the file
966+
* system.
967+
*/
968+
#ifndef enable_fscache
969+
#define enable_fscache(x) /* noop */
970+
#endif
971+
957972
#endif

preload-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static void preload_index(struct index_state *index,
8484
offset = 0;
8585
work = DIV_ROUND_UP(index->cache_nr, threads);
8686
memset(&data, 0, sizeof(data));
87+
enable_fscache(1);
8788
for (i = 0; i < threads; i++) {
8889
struct thread_data *p = data+i;
8990
p->index = index;
@@ -100,6 +101,7 @@ static void preload_index(struct index_state *index,
100101
if (pthread_join(p->pthread, NULL))
101102
die("unable to join threaded lstat");
102103
}
104+
enable_fscache(0);
103105
}
104106
#endif
105107

0 commit comments

Comments
 (0)