test-lib-functions: make 'test_cmp_rev' more informative on failure
[gitweb.git] / read-cache.c
index 00cd416816e7dd291fb8ce7252c919a7228bb7a6..4ca81286c00c57484a3567a56fa4d441725708da 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;
@@ -1746,7 +1752,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
        size_t len;
        const char *name;
        unsigned int flags;
-       size_t copy_len;
+       size_t copy_len = 0;
        /*
         * Adjacent cache entries tend to share the leading paths, so it makes
         * sense to only store the differences in later entries.  In the v4
@@ -1786,8 +1792,6 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
                                die(_("malformed name field in the index, near path '%s'"),
                                        previous_ce->name);
                        copy_len = previous_len - strip_len;
-               } else {
-                       copy_len = 0;
                }
                name = (const char *)cp;
        }
@@ -2284,8 +2288,8 @@ int read_index_from(struct index_state *istate, const char *path,
        freshen_shared_index(base_path, 0);
        merge_base_index(istate);
        post_read_index_from(istate);
-       free(base_path);
        trace_performance_leave("read cache %s", base_path);
+       free(base_path);
        return ret;
 }