Skip to content

Commit 6053950

Browse files
matheustavaresgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9616882 commit 6053950

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

builtin/checkout.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "wt-status.h"
2828
#include "xdiff-interface.h"
2929
#include "entry.h"
30+
#include "parallel-checkout.h"
3031

3132
static const char * const checkout_usage[] = {
3233
N_("git checkout [<options>] <branch>"),
@@ -230,7 +231,8 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
230231
return error(_("path '%s' does not have their version"), ce->name);
231232
}
232233

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)
234236
{
235237
struct cache_entry *ce = active_cache[pos];
236238
const char *path = ce->name;
@@ -291,11 +293,10 @@ static int checkout_merged(int pos, const struct checkout *state, int *nr_checko
291293
if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
292294
die(_("Unable to add merge result for '%s'"), path);
293295
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);
295297
if (!ce)
296298
die(_("make_cache_entry failed for path '%s'"), path);
297299
status = checkout_entry(ce, state, NULL, nr_checkouts);
298-
discard_cache_entry(ce);
299300
return status;
300301
}
301302

@@ -359,16 +360,23 @@ static int checkout_worktree(const struct checkout_opts *opts,
359360
int nr_checkouts = 0, nr_unmerged = 0;
360361
int errs = 0;
361362
int pos;
363+
int pc_workers, pc_threshold;
364+
struct mem_pool ce_mem_pool;
362365

363366
state.force = 1;
364367
state.refresh_cache = 1;
365368
state.istate = &the_index;
366369

370+
mem_pool_init(&ce_mem_pool, 0);
371+
get_parallel_checkout_configs(&pc_workers, &pc_threshold);
367372
init_checkout_metadata(&state.meta, info->refname,
368373
info->commit ? &info->commit->object.oid : &info->oid,
369374
NULL);
370375

371376
enable_delayed_checkout(&state);
377+
if (pc_workers > 1)
378+
init_parallel_checkout();
379+
372380
for (pos = 0; pos < active_nr; pos++) {
373381
struct cache_entry *ce = active_cache[pos];
374382
if (ce->ce_flags & CE_MATCHED) {
@@ -384,10 +392,15 @@ static int checkout_worktree(const struct checkout_opts *opts,
384392
&nr_checkouts, opts->overlay_mode);
385393
else if (opts->merge)
386394
errs |= checkout_merged(pos, &state,
387-
&nr_unmerged);
395+
&nr_unmerged,
396+
&ce_mem_pool);
388397
pos = skip_same_name(ce, pos) - 1;
389398
}
390399
}
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());
391404
remove_marked_cache_entries(&the_index, 1);
392405
remove_scheduled_dirs();
393406
errs |= finish_delayed_checkout(&state, &nr_checkouts);

0 commit comments

Comments
 (0)