Skip to content

Commit f70573b

Browse files
kbleesGit for Windows Build Agent
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 1309d0d commit f70573b

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
@@ -760,6 +760,12 @@ relatively high IO latencies. When enabled, Git will do the
760760
index comparison to the filesystem data in parallel, allowing
761761
overlapping IO's. Defaults to true.
762762

763+
core.fscache::
764+
Enable additional caching of file system data for some operations.
765+
+
766+
Git for Windows uses this to bulk-read and cache lstat data of entire
767+
directories (instead of doing lstat file by file).
768+
763769
core.createObject::
764770
You can set this to 'link', in which case a hardlink followed by
765771
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
@@ -1379,6 +1379,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13791379
PATHSPEC_PREFER_FULL,
13801380
prefix, argv);
13811381

1382+
enable_fscache(1);
13821383
read_cache_preload(&s.pathspec);
13831384
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13841385

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ enum hide_dotfiles_type {
729729
};
730730
extern enum hide_dotfiles_type hide_dotfiles;
731731

732+
extern int core_fscache;
733+
732734
enum branch_track {
733735
BRANCH_TRACK_UNSPECIFIED = -1,
734736
BRANCH_TRACK_NEVER = 0,

config.c

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

1010+
if (!strcmp(var, "core.fscache")) {
1011+
core_fscache = git_config_bool(var, value);
1012+
return 0;
1013+
}
1014+
10101015
/* Add other config variables here and to Documentation/config.txt. */
10111016
return 0;
10121017
}

environment.c

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

6869
#ifndef PROTECT_HFS_DEFAULT
6970
#define PROTECT_HFS_DEFAULT 0

git-compat-util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,21 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
11011101
#define getc_unlocked(fh) getc(fh)
11021102
#endif
11031103

1104+
/*
1105+
* Enable/disable a read-only cache for file system data on platforms that
1106+
* support it.
1107+
*
1108+
* Implementing a live-cache is complicated and requires special platform
1109+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1110+
* to mark sections of git code that extensively read from the file system
1111+
* without modifying anything. Implementations can use this to cache e.g. stat
1112+
* data or even file content without the need to synchronize with the file
1113+
* system.
1114+
*/
1115+
#ifndef enable_fscache
1116+
#define enable_fscache(x) /* noop */
1117+
#endif
1118+
11041119
extern int cmd_main(int, const char **);
11051120

11061121
#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)