Skip to content

Commit 2a9dede

Browse files
jrngitster
authored andcommitted
index: make index.threads=true enable ieot and eoie
If a user explicitly sets [index] threads = true to read the index using multiple threads, ensure that index writes include the offset table by default to make that possible. This ensures that the user's intent of turning on threading is respected. In other words, permit the following configurations: - index.threads and index.recordOffsetTable unspecified: do not write the offset table yet (to avoid alarming the user with "ignoring IEOT extension" messages when an older version of Git accesses the repository) but do make use of multiple threads to read the index if the supporting offset table is present. This can also be requested explicitly by setting index.threads=true, 0, or >1 and index.recordOffsetTable=false. - index.threads=false or 1: do not write the offset table, and do not make use of the offset table. One can set index.recordOffsetTable=false as well, to be more explicit. - index.threads=true, 0, or >1 and index.recordOffsetTable unspecified: write the offset table and make use of threads at read time. This can also be requested by setting index.threads=true, 0, >1, or unspecified and index.recordOffsetTable=true. Fortunately the complication is temporary: once most Git installations have upgraded to a version with support for the IEOT and EOIE extensions, we can flip the defaults for index.recordEndOfIndexEntries and index.recordOffsetTable to true and eliminate the settings. Helped-by: Ben Peart <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4291605 commit 2a9dede

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

Documentation/config/index.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ index.recordEndOfIndexEntries::
33
Entry" section. This reduces index load time on multiprocessor
44
machines but produces a message "ignoring EOIE extension" when
55
reading the index using Git versions before 2.20. Defaults to
6-
'false'.
6+
'true' if index.threads has been explicitly enabled, 'false'
7+
otherwise.
78

89
index.recordOffsetTable::
910
Specifies whether the index file should include an "Index Entry
1011
Offset Table" section. This reduces index load time on
1112
multiprocessor machines but produces a message "ignoring IEOT
1213
extension" when reading the index using Git versions before 2.20.
13-
Defaults to 'false'.
14+
Defaults to 'true' if index.threads has been explicitly enabled,
15+
'false' otherwise.
1416

1517
index.threads::
1618
Specifies the number of threads to spawn when loading the index.

config.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,22 +2294,25 @@ int git_config_get_fsmonitor(void)
22942294
return 0;
22952295
}
22962296

2297-
int git_config_get_index_threads(void)
2297+
int git_config_get_index_threads(int *dest)
22982298
{
2299-
int is_bool, val = 0;
2299+
int is_bool, val;
23002300

23012301
val = git_env_ulong("GIT_TEST_INDEX_THREADS", 0);
2302-
if (val)
2303-
return val;
2302+
if (val) {
2303+
*dest = val;
2304+
return 0;
2305+
}
23042306

23052307
if (!git_config_get_bool_or_int("index.threads", &is_bool, &val)) {
23062308
if (is_bool)
2307-
return val ? 0 : 1;
2309+
*dest = val ? 0 : 1;
23082310
else
2309-
return val;
2311+
*dest = val;
2312+
return 0;
23102313
}
23112314

2312-
return 0; /* auto */
2315+
return 1;
23132316
}
23142317

23152318
NORETURN

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ extern int git_config_get_bool(const char *key, int *dest);
246246
extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
247247
extern int git_config_get_maybe_bool(const char *key, int *dest);
248248
extern int git_config_get_pathname(const char *key, const char **dest);
249+
extern int git_config_get_index_threads(int *dest);
249250
extern int git_config_get_untracked_cache(void);
250251
extern int git_config_get_split_index(void);
251252
extern int git_config_get_max_percent_split_change(void);
252253
extern int git_config_get_fsmonitor(void);
253-
extern int git_config_get_index_threads(void);
254254

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

read-cache.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
21762176

21772177
src_offset = sizeof(*hdr);
21782178

2179-
nr_threads = git_config_get_index_threads();
2179+
if (git_config_get_index_threads(&nr_threads))
2180+
nr_threads = 1;
21802181

21812182
/* TODO: does creating more threads than cores help? */
21822183
if (!nr_threads) {
@@ -2695,7 +2696,13 @@ static int record_eoie(void)
26952696

26962697
if (!git_config_get_bool("index.recordendofindexentries", &val))
26972698
return val;
2698-
return 0;
2699+
2700+
/*
2701+
* As a convenience, the end of index entries extension
2702+
* used for threading is written by default if the user
2703+
* explicitly requested threaded index reads.
2704+
*/
2705+
return !git_config_get_index_threads(&val) && val != 1;
26992706
}
27002707

27012708
static int record_ieot(void)
@@ -2704,7 +2711,13 @@ static int record_ieot(void)
27042711

27052712
if (!git_config_get_bool("index.recordoffsettable", &val))
27062713
return val;
2707-
return 0;
2714+
2715+
/*
2716+
* As a convenience, the offset table used for threading is
2717+
* written by default if the user explicitly requested
2718+
* threaded index reads.
2719+
*/
2720+
return !git_config_get_index_threads(&val) && val != 1;
27082721
}
27092722

27102723
/*
@@ -2765,9 +2778,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
27652778
if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
27662779
return -1;
27672780

2768-
if (HAVE_THREADS)
2769-
nr_threads = git_config_get_index_threads();
2770-
else
2781+
if (!HAVE_THREADS || git_config_get_index_threads(&nr_threads))
27712782
nr_threads = 1;
27722783

27732784
if (nr_threads != 1 && record_ieot()) {

0 commit comments

Comments
 (0)