Git fork

builtin/checkout.c: complete parallel checkout support

Pathspec-limited checkouts (like `git checkout *.txt`) are performed by
a code path that doesn't yet support parallel checkout because it calls
checkout_entry() directly, instead of unpack_trees(). Let's add parallel
checkout support for this code path too.

The transient cache entries allocated in checkout_merged() are now
allocated in a mem_pool which is only discarded after parallel checkout
finishes. This is done because the entries need to be valid when
run_parallel_checkout() is called.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Matheus Tavares and committed by
Junio C Hamano
60539506 96168827

+17 -4
+17 -4
builtin/checkout.c
··· 27 27 #include "wt-status.h" 28 28 #include "xdiff-interface.h" 29 29 #include "entry.h" 30 + #include "parallel-checkout.h" 30 31 31 32 static const char * const checkout_usage[] = { 32 33 N_("git checkout [<options>] <branch>"), ··· 230 231 return error(_("path '%s' does not have their version"), ce->name); 231 232 } 232 233 233 - static int checkout_merged(int pos, const struct checkout *state, int *nr_checkouts) 234 + static int checkout_merged(int pos, const struct checkout *state, 235 + int *nr_checkouts, struct mem_pool *ce_mem_pool) 234 236 { 235 237 struct cache_entry *ce = active_cache[pos]; 236 238 const char *path = ce->name; ··· 291 293 if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid)) 292 294 die(_("Unable to add merge result for '%s'"), path); 293 295 free(result_buf.ptr); 294 - ce = make_transient_cache_entry(mode, &oid, path, 2, NULL); 296 + ce = make_transient_cache_entry(mode, &oid, path, 2, ce_mem_pool); 295 297 if (!ce) 296 298 die(_("make_cache_entry failed for path '%s'"), path); 297 299 status = checkout_entry(ce, state, NULL, nr_checkouts); 298 - discard_cache_entry(ce); 299 300 return status; 300 301 } 301 302 ··· 359 360 int nr_checkouts = 0, nr_unmerged = 0; 360 361 int errs = 0; 361 362 int pos; 363 + int pc_workers, pc_threshold; 364 + struct mem_pool ce_mem_pool; 362 365 363 366 state.force = 1; 364 367 state.refresh_cache = 1; 365 368 state.istate = &the_index; 366 369 370 + mem_pool_init(&ce_mem_pool, 0); 371 + get_parallel_checkout_configs(&pc_workers, &pc_threshold); 367 372 init_checkout_metadata(&state.meta, info->refname, 368 373 info->commit ? &info->commit->object.oid : &info->oid, 369 374 NULL); 370 375 371 376 enable_delayed_checkout(&state); 377 + if (pc_workers > 1) 378 + init_parallel_checkout(); 379 + 372 380 for (pos = 0; pos < active_nr; pos++) { 373 381 struct cache_entry *ce = active_cache[pos]; 374 382 if (ce->ce_flags & CE_MATCHED) { ··· 384 392 &nr_checkouts, opts->overlay_mode); 385 393 else if (opts->merge) 386 394 errs |= checkout_merged(pos, &state, 387 - &nr_unmerged); 395 + &nr_unmerged, 396 + &ce_mem_pool); 388 397 pos = skip_same_name(ce, pos) - 1; 389 398 } 390 399 } 400 + if (pc_workers > 1) 401 + errs |= run_parallel_checkout(&state, pc_workers, pc_threshold, 402 + NULL, NULL); 403 + mem_pool_discard(&ce_mem_pool, should_validate_cache_entries()); 391 404 remove_marked_cache_entries(&the_index, 1); 392 405 remove_scheduled_dirs(); 393 406 errs |= finish_delayed_checkout(&state, &nr_checkouts);