Message ID | e2d82c4337dc002d7296454c59d4006c3bb43c27.1619818517.git.matheus.bernardino@usp.br (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Parallel Checkout (part 3) | expand |
On Fri, Apr 30, 2021 at 11:40 PM Matheus Tavares <matheus.bernardino@usp.br> wrote: > > 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. > > Note: the transient cache entries allocated in checkout_merged() are now s/Note: the/The/ > 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. > -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) For consistency with the previous patch, maybe: s/ce_mem_pool/ce_mp/
On Sat, May 1, 2021 at 2:08 PM Christian Couder <christian.couder@gmail.com> wrote: > > On Fri, Apr 30, 2021 at 11:40 PM Matheus Tavares > <matheus.bernardino@usp.br> wrote: > > > > 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. > > > > Note: the transient cache entries allocated in checkout_merged() are now > > s/Note: the/The/ Thanks > > 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. > > > -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) > > For consistency with the previous patch, maybe: s/ce_mem_pool/ce_mp/ Yeah, I agree that it's a good idea to keep this consistent. In fact, instead of changing `ce_mem_pool` here, I think I should change `mp` in the previous patch to either `mem_pool` or `ce_mem_pool`. Those seem to be the most common names, at read-cache.c, for a memory pool struct holding cache entries.
diff --git a/builtin/checkout.c b/builtin/checkout.c index db667d0267..b71dc08430 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -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,22 @@ 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 +391,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);
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. Note: 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> --- builtin/checkout.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)