]> git.ipfire.org Git - thirdparty/git.git/commitdiff
index: make index.threads=true enable ieot and eoie
authorJonathan Nieder <jrnieder@gmail.com>
Tue, 20 Nov 2018 06:14:26 +0000 (22:14 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Nov 2018 07:46:54 +0000 (16:46 +0900)
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>
Documentation/config/index.txt
config.c
config.h
read-cache.c

index de4418323583f0b6f662cb02b0c100766b20613b..f18150304106891ad388a7620594937b43e7615e 100644 (file)
@@ -3,14 +3,16 @@ index.recordEndOfIndexEntries::
        Entry" section. This reduces index load time on multiprocessor
        machines but produces a message "ignoring EOIE extension" when
        reading the index using Git versions before 2.20. Defaults to
-       'false'.
+       'true' if index.threads has been explicitly enabled, 'false'
+       otherwise.
 
 index.recordOffsetTable::
        Specifies whether the index file should include an "Index Entry
        Offset Table" section. This reduces index load time on
        multiprocessor machines but produces a message "ignoring IEOT
        extension" when reading the index using Git versions before 2.20.
-       Defaults to 'false'.
+       Defaults to 'true' if index.threads has been explicitly enabled,
+       'false' otherwise.
 
 index.threads::
        Specifies the number of threads to spawn when loading the index.
index 04286f7717645c6812c7236a282c34f5ad353eb7..ff521eb27ad243b27c7bd95f3ad7a1b777a4ae00 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2294,22 +2294,25 @@ int git_config_get_fsmonitor(void)
        return 0;
 }
 
-int git_config_get_index_threads(void)
+int git_config_get_index_threads(int *dest)
 {
-       int is_bool, val = 0;
+       int is_bool, val;
 
        val = git_env_ulong("GIT_TEST_INDEX_THREADS", 0);
-       if (val)
-               return val;
+       if (val) {
+               *dest = val;
+               return 0;
+       }
 
        if (!git_config_get_bool_or_int("index.threads", &is_bool, &val)) {
                if (is_bool)
-                       return val ? 0 : 1;
+                       *dest = val ? 0 : 1;
                else
-                       return val;
+                       *dest = val;
+               return 0;
        }
 
-       return 0; /* auto */
+       return 1;
 }
 
 NORETURN
index a06027e69b9d453c6e4277968622aa9bd6ae92b1..ee5d3fa7b4264f24e8b36c2e1154546ae626c191 100644 (file)
--- a/config.h
+++ b/config.h
@@ -246,11 +246,11 @@ extern int git_config_get_bool(const char *key, int *dest);
 extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
 extern int git_config_get_maybe_bool(const char *key, int *dest);
 extern int git_config_get_pathname(const char *key, const char **dest);
+extern int git_config_get_index_threads(int *dest);
 extern int git_config_get_untracked_cache(void);
 extern int git_config_get_split_index(void);
 extern int git_config_get_max_percent_split_change(void);
 extern int git_config_get_fsmonitor(void);
-extern int git_config_get_index_threads(void);
 
 /* This dies if the configured or default date is in the future */
 extern int git_config_get_expiry(const char *key, const char **output);
index f3d5638d9ed40fd5f35d5a525d159ddf3eb155b6..42de59a163c1f88580b88281dfc1572ca0dcd5f0 100644 (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()) {