Merge branch 'bp/refresh-index-using-preload'
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:25 +0000 (22:37 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Nov 2018 13:37:26 +0000 (22:37 +0900)
The helper function to refresh the cached stat information in the
in-core index has learned to perform the lstat() part of the
operation in parallel on multi-core platforms.

* bp/refresh-index-using-preload:
refresh_index: remove unnecessary calls to preload_index()
speed up refresh_index() by utilizing preload_index()

builtin/commit.c
builtin/describe.c
builtin/update-index.c
cache.h
preload-index.c
read-cache.c
sequencer.c
index 074bd9a55160a8efcaa1c108afcf6bd6bc360626..96d336ec3d8044918fb260d6cf8c03296cf32ed1 100644 (file)
@@ -1363,7 +1363,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        if (status_format != STATUS_FORMAT_PORCELAIN &&
            status_format != STATUS_FORMAT_PORCELAIN_V2)
                progress_flag = REFRESH_PROGRESS;
-       read_index_preload(&the_index, &s.pathspec, progress_flag);
+       read_index(&the_index);
        refresh_index(&the_index,
                      REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,
                      &s.pathspec, NULL, NULL);
index c48c34e8667c36a42101fffe51bd96f1a4d36842..cc118448ee00d2c4336422afbad1799babfb5783 100644 (file)
@@ -629,7 +629,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                        struct argv_array args = ARGV_ARRAY_INIT;
                        int fd, result;
 
-                       read_cache_preload(NULL);
+                       read_cache();
                        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
                                      NULL, NULL, NULL);
                        fd = hold_locked_index(&index_lock, 0);
index 07c10bcb7d82c19becf424f9ab63954c9e58f93f..0e1dcf0438f7b2ec37b404d3f2acb7bd70650b67 100644 (file)
@@ -782,7 +782,7 @@ struct refresh_params {
 static int refresh(struct refresh_params *o, unsigned int flag)
 {
        setup_work_tree();
-       read_cache_preload(NULL);
+       read_cache();
        *o->has_errors |= refresh_cache(o->flags | flag);
        return 0;
 }
diff --git a/cache.h b/cache.h
index 8ac4adb3644f789ef644c630a2ab1bb86941fd61..ca36b44ee0b5851f837616c322a201ac420a90d2 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -661,6 +661,9 @@ extern int daemonize(void);
 /* Initialize and use the cache information */
 struct lock_file;
 extern int read_index(struct index_state *);
+extern void preload_index(struct index_state *index,
+                         const struct pathspec *pathspec,
+                         unsigned int refresh_flags);
 extern int read_index_preload(struct index_state *,
                              const struct pathspec *pathspec,
                              unsigned int refresh_flags);
index 9e7152ab14d9359d0a48da8b25cd58253a13fc0c..222792ccbc39b6166a75c702525c396b77c2299e 100644 (file)
@@ -9,7 +9,7 @@
 #include "progress.h"
 
 #ifdef NO_PTHREADS
-static void preload_index(struct index_state *index,
+void preload_index(struct index_state *index,
                          const struct pathspec *pathspec,
                          unsigned int refresh_flags)
 {
@@ -100,9 +100,9 @@ static void *preload_thread(void *_data)
        return NULL;
 }
 
-static void preload_index(struct index_state *index,
-                         const struct pathspec *pathspec,
-                         unsigned int refresh_flags)
+void preload_index(struct index_state *index,
+                  const struct pathspec *pathspec,
+                  unsigned int refresh_flags)
 {
        int threads, i, work, offset;
        struct thread_data data[MAX_PARALLEL];
index f3a848d61c154ec99b4c45d3404380810c18eec1..8c924506dd96037c1d7c0fa93e4223f9274a851f 100644 (file)
@@ -1496,6 +1496,12 @@ int refresh_index(struct index_state *istate, unsigned int flags,
        typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
        added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n");
        unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
+       /*
+        * Use the multi-threaded preload_index() to refresh most of the
+        * cache entries quickly then in the single threaded loop below,
+        * we only have to do the special cases that are left.
+        */
+       preload_index(istate, pathspec, 0);
        for (i = 0; i < istate->cache_nr; i++) {
                struct cache_entry *ce, *new_entry;
                int cache_errno = 0;
index 63a2094cac277359f23c8bdfa102cb5785e70d69..0d87b0739be5c5fdaf686063729aca02559638b8 100644 (file)
@@ -1969,7 +1969,7 @@ static int read_and_refresh_cache(struct replay_opts *opts)
 {
        struct lock_file index_lock = LOCK_INIT;
        int index_fd = hold_locked_index(&index_lock, 0);
-       if (read_index_preload(&the_index, NULL, 0) < 0) {
+       if (read_index(&the_index) < 0) {
                rollback_lock_file(&index_lock);
                return error(_("git %s: failed to read the index"),
                        _(action_name(opts)));