Skip to content

Commit c780b9c

Browse files
benpeartgitster
authored andcommitted
config: add new index.threads config setting
Add support for a new index.threads config setting which will be used to control the threading code in do_read_index(). A value of 0 will tell the index code to automatically determine the correct number of threads to use. A value of 1 will make the code single threaded. A value greater than 1 will set the maximum number of threads to use. For testing purposes, this setting can be overwritten by setting the GIT_TEST_INDEX_THREADS=<n> environment variable to a value greater than 0. Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3b1d9e0 commit c780b9c

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

Documentation/config.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,13 @@ imap::
24132413
The configuration variables in the 'imap' section are described
24142414
in linkgit:git-imap-send[1].
24152415

2416+
index.threads::
2417+
Specifies the number of threads to spawn when loading the index.
2418+
This is meant to reduce index load time on multiprocessor machines.
2419+
Specifying 0 or 'true' will cause Git to auto-detect the number of
2420+
CPU's and set the number of threads accordingly. Specifying 1 or
2421+
'false' will disable multithreading. Defaults to 'true'.
2422+
24162423
index.version::
24172424
Specify the version with which new index files should be
24182425
initialized. This does not affect existing repositories.

config.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,24 @@ int git_config_get_fsmonitor(void)
22892289
return 0;
22902290
}
22912291

2292+
int git_config_get_index_threads(void)
2293+
{
2294+
int is_bool, val = 0;
2295+
2296+
val = git_env_ulong("GIT_TEST_INDEX_THREADS", 0);
2297+
if (val)
2298+
return val;
2299+
2300+
if (!git_config_get_bool_or_int("index.threads", &is_bool, &val)) {
2301+
if (is_bool)
2302+
return val ? 0 : 1;
2303+
else
2304+
return val;
2305+
}
2306+
2307+
return 0; /* auto */
2308+
}
2309+
22922310
NORETURN
22932311
void git_die_config_linenr(const char *key, const char *filename, int linenr)
22942312
{

config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ extern int git_config_get_untracked_cache(void);
250250
extern int git_config_get_split_index(void);
251251
extern int git_config_get_max_percent_split_change(void);
252252
extern int git_config_get_fsmonitor(void);
253+
extern int git_config_get_index_threads(void);
253254

254255
/* This dies if the configured or default date is in the future */
255256
extern int git_config_get_expiry(const char *key, const char **output);

t/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ GIT_TEST_COMMIT_GRAPH=<boolean>, when true, forces the commit-graph to
327327
be written after every 'git commit' command, and overrides the
328328
'core.commitGraph' setting to true.
329329

330+
GIT_TEST_INDEX_THREADS=<n> enables exercising the multi-threaded loading
331+
of the index for the whole test suite by bypassing the default number of
332+
cache entries and thread minimums. Setting this to 1 will make the
333+
index loading single threaded.
334+
330335
Naming Tests
331336
------------
332337

t/t1700-split-index.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ test_description='split index mode tests'
66

77
# We need total control of index splitting here
88
sane_unset GIT_TEST_SPLIT_INDEX
9+
10+
# Testing a hard coded SHA against an index with an extension
11+
# that can vary from run to run is problematic so we disable
12+
# those extensions.
913
sane_unset GIT_FSMONITOR_TEST
14+
sane_unset GIT_TEST_INDEX_THREADS
1015

1116
test_expect_success 'enable split index' '
1217
git config splitIndex.maxPercentChange 100 &&

0 commit comments

Comments
 (0)