Merge branch 'sl/const'
[gitweb.git] / preload-index.c
index 222792ccbc39b6166a75c702525c396b77c2299e..e73600ee7841a299e060369ca9eecf46d5a7fb0f 100644 (file)
@@ -7,17 +7,8 @@
 #include "fsmonitor.h"
 #include "config.h"
 #include "progress.h"
-
-#ifdef NO_PTHREADS
-void preload_index(struct index_state *index,
-                         const struct pathspec *pathspec,
-                         unsigned int refresh_flags)
-{
-       ; /* nothing */
-}
-#else
-
-#include <pthread.h>
+#include "thread-utils.h"
+#include "repository.h"
 
 /*
  * Mostly randomly chosen maximum thread counts: we
@@ -108,7 +99,7 @@ void preload_index(struct index_state *index,
        struct thread_data data[MAX_PARALLEL];
        struct progress_data pd;
 
-       if (!core_preload_index)
+       if (!HAVE_THREADS || !core_preload_index)
                return;
 
        threads = index->cache_nr / THREAD_COST;
@@ -131,6 +122,8 @@ void preload_index(struct index_state *index,
 
        for (i = 0; i < threads; i++) {
                struct thread_data *p = data+i;
+               int err;
+
                p->index = index;
                if (pathspec)
                        copy_pathspec(&p->pathspec, pathspec);
@@ -139,8 +132,10 @@ void preload_index(struct index_state *index,
                if (pd.progress)
                        p->progress = &pd;
                offset += work;
-               if (pthread_create(&p->pthread, NULL, preload_thread, p))
-                       die("unable to create threaded lstat");
+               err = pthread_create(&p->pthread, NULL, preload_thread, p);
+
+               if (err)
+                       die(_("unable to create threaded lstat: %s"), strerror(err));
        }
        for (i = 0; i < threads; i++) {
                struct thread_data *p = data+i;
@@ -151,14 +146,13 @@ void preload_index(struct index_state *index,
 
        trace_performance_leave("preload index");
 }
-#endif
 
-int read_index_preload(struct index_state *index,
-                      const struct pathspec *pathspec,
-                      unsigned int refresh_flags)
+int repo_read_index_preload(struct repository *repo,
+                           const struct pathspec *pathspec,
+                           unsigned int refresh_flags)
 {
-       int retval = read_index(index);
+       int retval = repo_read_index(repo);
 
-       preload_index(index, pathspec, refresh_flags);
+       preload_index(repo->index, pathspec, refresh_flags);
        return retval;
 }