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

Commit 4c9da8f

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 ee2e7ac commit 4c9da8f

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
@@ -624,6 +624,12 @@ relatively high IO latencies. With this set to 'true', Git will do the
624624
index comparison to the filesystem data in parallel, allowing
625625
overlapping IO's.
626626

627+
core.fscache::
628+
Enable additional caching of file system data for some operations.
629+
+
630+
Git for Windows uses this to bulk-read and cache lstat data of entire
631+
directories (instead of doing lstat file by file).
632+
627633
core.createObject::
628634
You can set this to 'link', in which case a hardlink followed by
629635
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
@@ -1289,6 +1289,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12891289
PATHSPEC_PREFER_FULL,
12901290
prefix, argv);
12911291

1292+
enable_fscache(1);
12921293
read_cache_preload(&s.pathspec);
12931294
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
12941295

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ enum hide_dotfiles_type {
599599
};
600600
extern enum hide_dotfiles_type hide_dotfiles;
601601

602+
extern int core_fscache;
603+
602604
enum branch_track {
603605
BRANCH_TRACK_UNSPECIFIED = -1,
604606
BRANCH_TRACK_NEVER = 0,

config.c

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

893+
if (!strcmp(var, "core.fscache")) {
894+
core_fscache = git_config_bool(var, value);
895+
return 0;
896+
}
897+
893898
/* Add other config variables here and to Documentation/config.txt. */
894899
return 0;
895900
}

environment.c

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

6869
/*
6970
* The character that begins a commented line in user-editable file

git-compat-util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,4 +733,19 @@ struct passwd *xgetpwuid_self(void);
733733
#define get_home_directory() getenv("HOME")
734734
#endif
735735

736+
/*
737+
* Enable/disable a read-only cache for file system data on platforms that
738+
* support it.
739+
*
740+
* Implementing a live-cache is complicated and requires special platform
741+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
742+
* to mark sections of git code that extensively read from the file system
743+
* without modifying anything. Implementations can use this to cache e.g. stat
744+
* data or even file content without the need to synchronize with the file
745+
* system.
746+
*/
747+
#ifndef enable_fscache
748+
#define enable_fscache(x) /* noop */
749+
#endif
750+
736751
#endif

preload-index.c

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

0 commit comments

Comments
 (0)