MCPcopy Create free account
hub / github.com/git/git / preload_index

Function preload_index

preload-index.c:106–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106void preload_index(struct index_state *index,
107 const struct pathspec *pathspec,
108 unsigned int refresh_flags)
109{
110 int threads, i, work, offset;
111 struct thread_data data[MAX_PARALLEL];
112 struct progress_data pd;
113 int t2_sum_lstat = 0;
114 int core_preload_index = 1;
115
116 repo_config_get_bool(index->repo, "core.preloadindex", &core_preload_index);
117
118 if (!HAVE_THREADS || !core_preload_index)
119 return;
120
121 threads = index->cache_nr / THREAD_COST;
122 if ((index->cache_nr > 1) && (threads < 2) && git_env_bool("GIT_TEST_PRELOAD_INDEX", 0))
123 threads = 2;
124 if (threads < 2)
125 return;
126
127 trace2_region_enter("index", "preload", NULL);
128
129 trace_performance_enter();
130 if (threads > MAX_PARALLEL)
131 threads = MAX_PARALLEL;
132 offset = 0;
133 work = DIV_ROUND_UP(index->cache_nr, threads);
134 memset(&data, 0, sizeof(data));
135
136 memset(&pd, 0, sizeof(pd));
137 if (refresh_flags & REFRESH_PROGRESS && isatty(2)) {
138 pd.progress = start_delayed_progress(index->repo,
139 _("Refreshing index"),
140 index->cache_nr);
141 pthread_mutex_init(&pd.mutex, NULL);
142 }
143
144 for (i = 0; i < threads; i++) {
145 struct thread_data *p = data+i;
146 int err;
147
148 p->index = index;
149 if (pathspec)
150 copy_pathspec(&p->pathspec, pathspec);
151 p->offset = offset;
152 p->nr = work;
153 if (pd.progress)
154 p->progress = &pd;
155 offset += work;
156 err = pthread_create(&p->pthread, NULL, preload_thread, p);
157
158 if (err)
159 die(_("unable to create threaded lstat: %s"), strerror(err));
160 }
161 for (i = 0; i < threads; i++) {
162 struct thread_data *p = data+i;
163 if (pthread_join(p->pthread, NULL))

Callers 2

repo_read_index_preloadFunction · 0.85
refresh_indexFunction · 0.85

Calls 9

repo_config_get_boolFunction · 0.85
git_env_boolFunction · 0.85
trace_performance_enterFunction · 0.85
start_delayed_progressFunction · 0.85
copy_pathspecFunction · 0.85
pthread_createFunction · 0.85
stop_progressFunction · 0.85
clear_pathspecFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected