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 <benpeart@microsoft.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder
2018-11-19 22:14:26 -08:00
committed by Junio C Hamano
parent 429160544d
commit 2a9dedef2e
4 changed files with 32 additions and 16 deletions

View File

@ -2176,7 +2176,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
src_offset = sizeof(*hdr);
nr_threads = git_config_get_index_threads();
if (git_config_get_index_threads(&nr_threads))
nr_threads = 1;
/* TODO: does creating more threads than cores help? */
if (!nr_threads) {
@ -2695,7 +2696,13 @@ static int record_eoie(void)
if (!git_config_get_bool("index.recordendofindexentries", &val))
return val;
return 0;
/*
* As a convenience, the end of index entries extension
* used for threading is written by default if the user
* explicitly requested threaded index reads.
*/
return !git_config_get_index_threads(&val) && val != 1;
}
static int record_ieot(void)
@ -2704,7 +2711,13 @@ static int record_ieot(void)
if (!git_config_get_bool("index.recordoffsettable", &val))
return val;
return 0;
/*
* As a convenience, the offset table used for threading is
* written by default if the user explicitly requested
* threaded index reads.
*/
return !git_config_get_index_threads(&val) && val != 1;
}
/*
@ -2765,9 +2778,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
return -1;
if (HAVE_THREADS)
nr_threads = git_config_get_index_threads();
else
if (!HAVE_THREADS || git_config_get_index_threads(&nr_threads))
nr_threads = 1;
if (nr_threads != 1 && record_ieot()) {