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>
This commit is contained in:
parent
9616882780
commit
6053950632
@ -27,6 +27,7 @@
|
||||
#include "wt-status.h"
|
||||
#include "xdiff-interface.h"
|
||||
#include "entry.h"
|
||||
#include "parallel-checkout.h"
|
||||
|
||||
static const char * const checkout_usage[] = {
|
||||
N_("git checkout [<options>] <branch>"),
|
||||
@ -230,7 +231,8 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
|
||||
return error(_("path '%s' does not have their version"), ce->name);
|
||||
}
|
||||
|
||||
static int checkout_merged(int pos, const struct checkout *state, int *nr_checkouts)
|
||||
static int checkout_merged(int pos, const struct checkout *state,
|
||||
int *nr_checkouts, struct mem_pool *ce_mem_pool)
|
||||
{
|
||||
struct cache_entry *ce = active_cache[pos];
|
||||
const char *path = ce->name;
|
||||
@ -291,11 +293,10 @@ static int checkout_merged(int pos, const struct checkout *state, int *nr_checko
|
||||
if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
|
||||
die(_("Unable to add merge result for '%s'"), path);
|
||||
free(result_buf.ptr);
|
||||
ce = make_transient_cache_entry(mode, &oid, path, 2, NULL);
|
||||
ce = make_transient_cache_entry(mode, &oid, path, 2, ce_mem_pool);
|
||||
if (!ce)
|
||||
die(_("make_cache_entry failed for path '%s'"), path);
|
||||
status = checkout_entry(ce, state, NULL, nr_checkouts);
|
||||
discard_cache_entry(ce);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -359,16 +360,23 @@ static int checkout_worktree(const struct checkout_opts *opts,
|
||||
int nr_checkouts = 0, nr_unmerged = 0;
|
||||
int errs = 0;
|
||||
int pos;
|
||||
int pc_workers, pc_threshold;
|
||||
struct mem_pool ce_mem_pool;
|
||||
|
||||
state.force = 1;
|
||||
state.refresh_cache = 1;
|
||||
state.istate = &the_index;
|
||||
|
||||
mem_pool_init(&ce_mem_pool, 0);
|
||||
get_parallel_checkout_configs(&pc_workers, &pc_threshold);
|
||||
init_checkout_metadata(&state.meta, info->refname,
|
||||
info->commit ? &info->commit->object.oid : &info->oid,
|
||||
NULL);
|
||||
|
||||
enable_delayed_checkout(&state);
|
||||
if (pc_workers > 1)
|
||||
init_parallel_checkout();
|
||||
|
||||
for (pos = 0; pos < active_nr; pos++) {
|
||||
struct cache_entry *ce = active_cache[pos];
|
||||
if (ce->ce_flags & CE_MATCHED) {
|
||||
@ -384,10 +392,15 @@ static int checkout_worktree(const struct checkout_opts *opts,
|
||||
&nr_checkouts, opts->overlay_mode);
|
||||
else if (opts->merge)
|
||||
errs |= checkout_merged(pos, &state,
|
||||
&nr_unmerged);
|
||||
&nr_unmerged,
|
||||
&ce_mem_pool);
|
||||
pos = skip_same_name(ce, pos) - 1;
|
||||
}
|
||||
}
|
||||
if (pc_workers > 1)
|
||||
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
|
||||
NULL, NULL);
|
||||
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
|
||||
remove_marked_cache_entries(&the_index, 1);
|
||||
remove_scheduled_dirs();
|
||||
errs |= finish_delayed_checkout(&state, &nr_checkouts);
|
||||
|
Loading…
Reference in New Issue
Block a user