Parallel checkout
Subsystems (2)
PATCH v4 11/19 parallel-checkout: make it truly parallel
In reply to Matheus TavaresUse multiple worker processes to distribute the queued entries and call write_checkout_item() in parallel for them. The items are distributed uniformly in contiguous chunks. This minimizes the chances of two workers writing to the same directory simultaneously, which could affect performance due to lock contention in the kernel. Work stealing (or any other format of re-distribution) is not implemented yet.
The parallel version was benchmarked during three operations in the linux repo, with cold cache: cloning v5.8, checking out v5.8 from v2.6.15 (checkout I) and checking out v5.8 from v5.7 (checkout II). The four tables below show the mean run times and standard deviations for 5 runs in: a local file system with SSD, a local file system with HDD, a Linux NFS server, and Amazon EFS. The numbers of workers were chosen based on what produces the best result for each case.
Local SSD:
Clone Checkout I Checkout II
Sequential 8.171 s ± 0.206 s 8.735 s ± 0.230 s 4.166 s ± 0.246 s 10 workers 3.277 s ± 0.138 s 3.774 s ± 0.188 s 2.561 s ± 0.120 s Speedup 2.49 ± 0.12 2.31 ± 0.13 1.63 ± 0.12
Local HDD:
Clone Checkout I Checkout II
Sequential 35.157 s ± 0.205 s 48.835 s ± 0.407 s 47.302 s ± 1.435 s 8 workers 35.538 s ± 0.325 s 49.353 s ± 0.826 s 48.919 s ± 0.416 s Speedup 0.99 ± 0.01 0.99 ± 0.02 0.97 ± 0.03
Linux NFS server (v4.1, on EBS, single availability zone):
Clone Checkout I Checkout II
Sequential 216.070 s ± 3.611 s 211.169 s ± 3.147 s 57.446 s ± 1.301 s 32 workers 67.997 s ± 0.740 s 66.563 s ± 0.457 s 23.708 s ± 0.622 s Speedup 3.18 ± 0.06 3.17 ± 0.05 2.42 ± 0.08
EFS (v4.1, replicated over multiple availability zones):
Clone Checkout I Checkout II
Sequential 1249.329 s ± 13.857 s 1438.979 s ± 78.792 s 543.919 s ± 18.745 s 64 workers 225.864 s ± 12.433 s 316.345 s ± 1.887 s 183.648 s ± 10.095 s Speedup 5.53 ± 0.31 4.55 ± 0.25 2.96 ± 0.19
The above benchmarks show that parallel checkout is most effective on repositories located on an SSD or over a distributed file system. For local file systems on spinning disks, and/or older machines, the parallelism does not always bring a good performance. In fact, it can even increase the run time. For this reason, the sequential code is still the default. Two settings are added to optionally enable and configure the new parallel version as desired.
Local SSD tests were executed in an i7-7700HQ (4 cores with hyper-threading) running Manjaro Linux. Local HDD tests were executed in an i7-2600 (also 4 cores with hyper-threading), HDD Seagate Barracuda 7200 rpm SATA 3.0, running Debian 9.13. NFS and EFS tests were executed in an Amazon EC2 c5n.large instance, with 2 vCPUs. The Linux NFS server was running on a m6g.large instance with 1 TB, EBS GP2 volume. Before each timing, the linux repository was removed (or checked out back), and sync && sysctl vm.drop_caches=3 was executed.
--- .gitignore | 1 + Documentation/config/checkout.txt | 21 +++ Makefile | 1 + builtin.h | 1 + builtin/checkout--helper.c | 142 +++++++++++++++ git.c | 2 + parallel-checkout.c | 280 +++++++++++++++++++++++++++--- parallel-checkout.h | 84 ++++++++- unpack-trees.c | 10 +- 9 files changed, 508 insertions(+), 34 deletions(-) create mode 100644 builtin/checkout--helper.c
.gitignore +1 -0
@@ -33,6 +33,7 @@ /git-check-mailmap /git-check-ref-format /git-checkout +/git-checkout--helper /git-checkout-index /git-cherry /git-cherry-pick
Documentation/config/checkout.txt +21 -0
@@ -16,3 +16,24 @@ will checkout the '<something>' branch on another remote, and by linkgit:git-worktree[1] when 'git worktree add' refers to a remote branch. This setting might be used for other checkout-like commands or functionality in the future. + +checkout.workers:: + The number of parallel workers to use when updating the working tree. + The default is one, i.e. sequential execution. If set to a value less + than one, Git will use as many workers as the number of logical cores + available. This setting and `checkout.thresholdForParallelism` affect + all commands that perform checkout. E.g. checkout, clone, reset, + sparse-checkout, etc. ++ +Note: parallel checkout usually delivers better performance for repositories +located on SSDs or over NFS. For repositories on spinning disks and/or machines +with a small number of cores, the default sequential checkout often performs +better. The size and compression level of a repository might also influence how +well the parallel version performs. + +checkout.thresholdForParallelism:: + When running parallel checkout with a small number of files, the cost + of subprocess spawning and inter-process communication might outweigh + the parallelization gains. This setting allows to define the minimum + number of files for which parallel checkout should be attempted. The + default is 100.
Makefile +1 -0
@@ -1063,6 +1063,7 @@ BUILTIN_OBJS += builtin/check-attr.o BUILTIN_OBJS += builtin/check-ignore.o BUILTIN_OBJS += builtin/check-mailmap.o BUILTIN_OBJS += builtin/check-ref-format.o +BUILTIN_OBJS += builtin/checkout--helper.o BUILTIN_OBJS += builtin/checkout-index.o BUILTIN_OBJS += builtin/checkout.o BUILTIN_OBJS += builtin/clean.o
builtin.h +1 -0
@@ -123,6 +123,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix);int cmd_bundle (int argc,const char **argv,const char *prefix);int cmd_cat_file (int argc,const char **argv,const char *prefix);int cmd_checkout (int argc,const char **argv,const char *prefix); +int cmd_checkout__helper (int argc,const char **argv,const char *prefix);int cmd_checkout_index (int argc,const char **argv,const char *prefix);int cmd_check_attr (int argc,const char **argv,const char *prefix);int cmd_check_ignore (int argc,const char **argv,const char *prefix);
builtin/checkout--helper.c new file +142 -0
142 lines not on this page · raw message
git.c +2 -0
@@ -487,6 +487,8 @@ static struct cmd_struct commands[] = { { "check-mailmap", cmd_check_mailmap, RUN_SETUP }, { "check-ref-format", cmd_check_ref_format, NO_PARSEOPT }, { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, + { "checkout--helper", cmd_checkout__helper, + RUN_SETUP | NEED_WORK_TREE | SUPPORT_SUPER_PREFIX }, { "checkout-index", cmd_checkout_index, RUN_SETUP | NEED_WORK_TREE}, { "cherry", cmd_cherry, RUN_SETUP },
parallel-checkout.c +254 -26
333 lines not on this page · raw message
parallel-checkout.h +79 -5
101 lines not on this page · raw message
unpack-trees.c +7 -3
@@ -399,7 +399,7 @@ static int check_updates(struct unpack_trees_options *o,int errs =0 ;struct progress *progress;struct checkout state =CHECKOUT_INIT ; -int i; +int i, pc_workers, pc_threshold;trace_performance_enter (); state.force =1 ;
@@ -462,8 +462,11 @@ static int check_updates(struct unpack_trees_options *o,oid_array_clear (&to_fetch); } +get_parallel_checkout_configs (&pc_workers, &pc_threshold); +enable_delayed_checkout (&state); -init_parallel_checkout (); +if (pc_workers >1 ) +init_parallel_checkout ();for (i =0 ; i < index->cache_nr; i++) {struct cache_entry *ce = index->cache[i];
@@ -477,7 +480,8 @@ static int check_updates(struct unpack_trees_options *o, } }stop_progress (&progress); - errs |=run_parallel_checkout (&state); +if (pc_workers >1 ) + errs |=run_parallel_checkout (&state, pc_workers, pc_threshold); errs |=finish_delayed_checkout (&state,NULL );git_attr_set_direction (GIT_ATTR_CHECKIN );
Signature · 1 line
2.28.0
Re: [PATCH v4 11/19] parallel-checkout: make it truly parallel
Quoted 61 lines · Matheus Tavares
Use multiple worker processes to distribute the queued entries and call
write_checkout_item()in parallel for them. The items are distributed uniformly in contiguous chunks. This minimizes the chances of two workers writing to the same directory simultaneously, which could affect performance due to lock contention in the kernel. Work stealing (or any other format of re-distribution) is not implemented yet.The parallel version was benchmarked during three operations in the linux repo, with cold cache: cloning v5.8, checking out v5.8 from v2.6.15 (checkout I) and checking out v5.8 from v5.7 (checkout II). The four tables below show the mean run times and standard deviations for 5 runs in: a local file system with SSD, a local file system with HDD, a Linux NFS server, and Amazon EFS. The numbers of workers were chosen based on what produces the best result for each case.
Local SSD:
Clone Checkout I Checkout II
Sequential 8.171 s ± 0.206 s 8.735 s ± 0.230 s 4.166 s ± 0.246 s 10 workers 3.277 s ± 0.138 s 3.774 s ± 0.188 s 2.561 s ± 0.120 s Speedup 2.49 ± 0.12 2.31 ± 0.13 1.63 ± 0.12Local HDD:
Clone Checkout I Checkout II
Sequential 35.157 s ± 0.205 s 48.835 s ± 0.407 s 47.302 s ± 1.435 s 8 workers 35.538 s ± 0.325 s 49.353 s ± 0.826 s 48.919 s ± 0.416 s Speedup 0.99 ± 0.01 0.99 ± 0.02 0.97 ± 0.03Linux NFS server (v4.1, on EBS, single availability zone):
Clone Checkout I Checkout II
Sequential 216.070 s ± 3.611 s 211.169 s ± 3.147 s 57.446 s ± 1.301 s 32 workers 67.997 s ± 0.740 s 66.563 s ± 0.457 s 23.708 s ± 0.622 s Speedup 3.18 ± 0.06 3.17 ± 0.05 2.42 ± 0.08EFS (v4.1, replicated over multiple availability zones):
Clone Checkout I Checkout II
Sequential 1249.329 s ± 13.857 s 1438.979 s ± 78.792 s 543.919 s ± 18.745 s 64 workers 225.864 s ± 12.433 s 316.345 s ± 1.887 s 183.648 s ± 10.095 s Speedup 5.53 ± 0.31 4.55 ± 0.25 2.96 ± 0.19The above benchmarks show that parallel checkout is most effective on repositories located on an SSD or over a distributed file system. For local file systems on spinning disks, and/or older machines, the parallelism does not always bring a good performance. In fact, it can even increase the run time. For this reason, the sequential code is still the default. Two settings are added to optionally enable and configure the new parallel version as desired.
Local SSD tests were executed in an i7-7700HQ (4 cores with hyper-threading) running Manjaro Linux. Local HDD tests were executed in an i7-2600 (also 4 cores with hyper-threading), HDD Seagate Barracuda 7200 rpm SATA 3.0, running Debian 9.13. NFS and EFS tests were executed in an Amazon EC2 c5n.large instance, with 2 vCPUs. The Linux NFS server was running on a m6g.large instance with 1 TB, EBS GP2 volume. Before each timing, the linux repository was removed (or checked out back), and
sync && sysctl vm.drop_caches=3was executed.
Quoted 3 lines
Co-authored-by Nguyễn Thái Ngọc Duy <[email protected]>Co-authored-by Jeff Hostetler <[email protected]>Signed-off-by Matheus Tavares <[email protected]>
Only having done a quick skim, is there a reason that you are doing the workqueue handling from scratch rather than using run-command.h:run_processes_parallel()? The implementation you use and the implementation in run-command.c seem really similar to me.
- Emily
Re: [PATCH v4 11/19] parallel-checkout: make it truly parallel
Hi, Emily
Quoted 11 lines · Emily Shaffer
Quoted 8 lines · Matheus Tavares
Use multiple worker processes to distribute the queued entries and call
write_checkout_item()in parallel for them. The items are distributed uniformly in contiguous chunks. This minimizes the chances of two workers writing to the same directory simultaneously, which could affect performance due to lock contention in the kernel. Work stealing (or any other format of re-distribution) is not implemented yet.
Quoted 4 lines
Only having done a quick skim, is there a reason that you are doing the workqueue handling from scratch rather than using run-command.h:run_processes_parallel()? The implementation you use and the implementation in
run-command.cseem really similar to me.
TBH, I wasn't aware of run_process_parallel(). Thanks for bringing it to my attention! :)
Hmm, I still have to look further into it, but I think parallel checkout wouldn't be compatible with the run_process_parallel() framework, in its current form.
The first obstacle would be that, IIUC, the framework only allows callers to pass information to the child processes through argv, right? I saw that you already have a patch lifting this limitation [1], but the feed_pipe callback requires a strbuf and parallel checkout communicates through pkt-line. This is important because, otherwise, the workers wouldn't know where each parallel_checkout_item finishes. (The size of each item is variable and, since we send binary data, it might contain anything, even bytes normally used as delimiter such as '\0' or '\n'.)
Another difficulty is that the framework combines the child processes' stdout and stderr, dumping it to the foreground process' stderr. Parallel checkout expects workers to print errors to stderr, but it needs the stdout of each worker to get the results back. This is used both to get stat() data from the workers and to advance the checkout progress bar. I see that you've also sent a patch adding more flexibility in this area [2], but I'm not sure if parallel checkout could use it without pkt-lines and separating stdout from stderr (although, of course, the latter could be implemented in the framework as an optional feature).
Also, we might want to later improve the main-process<=>worker protocol by adding work stealing. This might help in the workload balancing while still minimizing the chances of having multiple workers writing to the same part of the working tree (as would happen with round-robin, for example). I already have a rough patch for this [3], but it needs to be timed and tested further. With work stealing, the protocol becomes a little more complex, so it might not be suitable for the callback-style interface of run_process_parallel().
I'm not really sure... I guess parallel checkout could use run_process_parallel(), but it seems to me that it would require a good amount of work on the framework and parallel checkout itself. I don't know if it would be worth it.
[1]: https://lore.kernel.org/git/[email protected]/
[2]: https://lore.kernel.org/git/[email protected]/
[3]: https://github.com/matheustavares/git/commit/a483df570a3cdd1165354388ea3c9fcc0ec66aaf
PATCH v4 12/19 parallel-checkout: support progress displaying
In reply to Matheus Tavares--- parallel-checkout.c | 34 +++++++++++++++++++++++++++++++--- parallel-checkout.h | 4 +++- unpack-trees.c | 11 ++++++++--- 3 files changed, 42 insertions(+), 7 deletions(-)
parallel-checkout.c +31 -3
@@ -2,6 +2,7 @@#include "entry.h" #include "parallel-checkout.h" #include "pkt-line.h" +#include "progress.h" #include "run-command.h" #include "streaming.h" #include "thread-utils.h"
@@ -16,6 +17,8 @@ struct parallel_checkout {enum pc_status status;struct parallel_checkout_item *items;size_t nr, alloc; +struct progress *progress; +unsigned int *progress_cnt; };static struct parallel_checkout parallel_checkout;
@@ -125,6 +128,20 @@ int enqueue_checkout(struct cache_entry *ce, struct conv_attrs *ca)return 0 ; } +size_t pc_queue_size (void ) +{ +return parallel_checkout.nr; +} + +static void advance_progress_meter (void ) +{ +if (parallel_checkout.progress) { + (*parallel_checkout.progress_cnt)++; +display_progress (parallel_checkout.progress, + *parallel_checkout.progress_cnt); + } +} +static int handle_results (struct checkout *state) {int ret =0 ;
@@ -173,6 +190,7 @@ static int handle_results(struct checkout *state)*/ ret |=checkout_entry_ca (pc_item->ce, &pc_item->ca, state,NULL ,NULL ); +advance_progress_meter ();break ;case PC_ITEM_PENDING : have_pending =1 ;
@@ -500,6 +518,9 @@ static void parse_and_save_result(const char *line, int len, pc_item->status = res->status;if (st) pc_item->st = *st; + +if (res->status !=PC_ITEM_COLLIDED ) +advance_progress_meter (); }
@@ -559,11 +580,16 @@ static void write_items_sequentially(struct checkout *state) {size_t i; -for (i =0 ; i < parallel_checkout.nr; i++) -write_pc_item (¶llel_checkout.items[i], state); +for (i =0 ; i < parallel_checkout.nr; i++) { +struct parallel_checkout_item *pc_item = ¶llel_checkout.items[i]; +write_pc_item (pc_item, state); +if (pc_item->status !=PC_ITEM_COLLIDED ) +advance_progress_meter (); + } } -int run_parallel_checkout (struct checkout *state,int num_workers,int threshold) +int run_parallel_checkout (struct checkout *state,int num_workers,int threshold, +struct progress *progress,unsigned int *progress_cnt) {int ret;
@@ -571,6 +597,8 @@ int run_parallel_checkout(struct checkout *state, int num_workers, int thresholdBUG ("cannot run parallel checkout: uninitialized or already running" ); parallel_checkout.status =PC_RUNNING ; + parallel_checkout.progress = progress; + parallel_checkout.progress_cnt = progress_cnt;if (parallel_checkout.nr < num_workers) num_workers = parallel_checkout.nr;
parallel-checkout.h +3 -1
@@ -24,13 +24,15 @@ void init_parallel_checkout(void);* write and return 0. */ int enqueue_checkout (struct cache_entry *ce,struct conv_attrs *ca); +size_t pc_queue_size (void );/* * Write all the queued entries, returning 0 on success. If the number of * entries is smaller than the specified threshold, the operation is performed * sequentially. */ -int run_parallel_checkout (struct checkout *state,int num_workers,int threshold); +int run_parallel_checkout (struct checkout *state,int num_workers,int threshold, +struct progress *progress,unsigned int *progress_cnt);/**************************************************************** * Interface with checkout--helper
unpack-trees.c +8 -3
@@ -471,17 +471,22 @@ static int check_updates(struct unpack_trees_options *o,struct cache_entry *ce = index->cache[i];if (ce->ce_flags &CE_UPDATE ) { +size_t last_pc_queue_size =pc_queue_size (); +if (ce->ce_flags &CE_WT_REMOVE )BUG ("both update and delete flags are set on %s" , ce->name); -display_progress (progress, ++cnt); ce->ce_flags &= ~CE_UPDATE ; errs |=checkout_entry (ce, &state,NULL ,NULL ); + +if (last_pc_queue_size ==pc_queue_size ()) +display_progress (progress, ++cnt); } } -stop_progress (&progress);if (pc_workers >1 ) - errs |=run_parallel_checkout (&state, pc_workers, pc_threshold); + errs |=run_parallel_checkout (&state, pc_workers, pc_threshold, + progress, &cnt); +stop_progress (&progress); errs |=finish_delayed_checkout (&state,NULL );git_attr_set_direction (GIT_ATTR_CHECKIN );
Signature · 1 line
2.28.0
PATCH v4 13/19 make_transient_cache_entry(): optionally alloc from mem_pool
In reply to Matheus TavaresAllow make_transient_cache_entry() to optionally receive a mem_pool struct in which it should allocate the entry. This will be used in the following patch, to store some transient entries which should persist until parallel checkout finishes.
--- builtin/checkout--helper.c | 2 +- builtin/checkout.c | 2 +- builtin/difftool.c | 2 +- cache.h | 10 +++++----- read-cache.c | 12 ++++++++---- unpack-trees.c | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-)
builtin/checkout--helper.c +1 -1
@@ -38,7 +38,7 @@ static void packet_to_pc_item(char *line, int len, }memset (pc_item,0 ,sizeof (*pc_item)); - pc_item->ce =make_empty_transient_cache_entry (fixed_portion->name_len); + pc_item->ce =make_empty_transient_cache_entry (fixed_portion->name_len,NULL ); pc_item->ce->ce_namelen = fixed_portion->name_len; pc_item->ce->ce_mode = fixed_portion->ce_mode;memcpy (pc_item->ce->name, variant, pc_item->ce->ce_namelen);
builtin/checkout.c +1 -1
@@ -291,7 +291,7 @@ static int checkout_merged(int pos, const struct checkout *state, int *nr_checkoif (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 ); + ce =make_transient_cache_entry (mode, &oid, path,2 ,NULL );if (!ce)die (_ ("make_cache_entry failed for path '%s'" ), path); status =checkout_entry (ce, state,NULL , nr_checkouts);
builtin/difftool.c +1 -1
@@ -323,7 +323,7 @@ static int checkout_path(unsigned mode, struct object_id *oid,struct cache_entry *ce;int ret; - ce =make_transient_cache_entry (mode, oid, path,0 ); + ce =make_transient_cache_entry (mode, oid, path,0 ,NULL ); ret =checkout_entry (ce, state,NULL ,NULL );discard_cache_entry (ce);
cache.h +5 -5
@@ -355,16 +355,16 @@ struct cache_entry *make_empty_cache_entry(struct index_state *istate, size_t name_len);/* -* Create a cache_entry that is not intended to be added to an index. -* Caller is responsible for discarding the cache_entry -* with `discard_cache_entry`. +* Create a cache_entry that is not intended to be added to an index. If mp is +* not NULL, the entry is allocated within the given memory pool. Caller is +* responsible for discarding the cache_entry with `discard_cache_entry`. */ struct cache_entry *make_transient_cache_entry (unsigned int mode,const struct object_id *oid,const char *path, -int stage); +int stage,struct mem_pool *mp); -struct cache_entry *make_empty_transient_cache_entry (size_t name_len); +struct cache_entry *make_empty_transient_cache_entry (size_t len,struct mem_pool *mp);/* * Discard cache entry.
read-cache.c +8 -4
@@ -813,8 +813,10 @@ struct cache_entry *make_empty_cache_entry(struct index_state *istate, size_t lereturn mem_pool__ce_calloc (find_mem_pool (istate), len); } -struct cache_entry *make_empty_transient_cache_entry (size_t len) +struct cache_entry *make_empty_transient_cache_entry (size_t len,struct mem_pool *mp) { +if (mp) +return mem_pool__ce_calloc (mp, len);return xcalloc (1 ,cache_entry_size (len)); }
@@ -848,8 +850,10 @@ struct cache_entry *make_cache_entry(struct index_state *istate,return ret; } -struct cache_entry *make_transient_cache_entry (unsigned int mode,const struct object_id *oid, -const char *path,int stage) +struct cache_entry *make_transient_cache_entry (unsigned int mode, +const struct object_id *oid, +const char *path,int stage, +struct mem_pool *mp) {struct cache_entry *ce;int len;
@@ -860,7 +864,7 @@ struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct o } len =strlen (path); - ce =make_empty_transient_cache_entry (len); + ce =make_empty_transient_cache_entry (len, mp);oidcpy (&ce->oid, oid);memcpy (ce->name, path, len);
unpack-trees.c +1 -1
@@ -1031,7 +1031,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info,size_t len =traverse_path_len (info,tree_entry_len (n));struct cache_entry *ce = is_transient ? -make_empty_transient_cache_entry (len) : +make_empty_transient_cache_entry (len,NULL ) :make_empty_cache_entry (istate, len); ce->ce_mode =create_ce_mode (n->mode);
Signature · 1 line
2.28.0
PATCH v4 14/19 builtin/checkout.c: complete parallel checkout support
In reply to Matheus TavaresThere is one code path in builtin/checkout.c which still doesn't benefit from parallel checkout because it calls checkout_entry() directly, instead of unpack_trees(). Let's add parallel support for this missing spot as well. 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.
--- builtin/checkout.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
builtin/checkout.c +16 -4
@@ -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_checkoif (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);
Signature · 1 line
2.28.0
PATCH v4 15/19 checkout-index: add parallel checkout support
In reply to Matheus Tavares--- builtin/checkout-index.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
builtin/checkout-index.c +18 -3
@@ -12,6 +12,7 @@#include "cache-tree.h" #include "parse-options.h" #include "entry.h" +#include "parallel-checkout.h" #define CHECKOUT_ALL 4static int nul_term_line;
@@ -169,6 +170,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)int force =0 , quiet =0 , not_new =0 ;int index_opt =0 ;int err =0 ; +int pc_workers, pc_threshold;struct option builtin_checkout_index_options[] = {OPT_BOOL ('a' ,"all" , &all,N_ ("check out all files in the index" )),
@@ -223,6 +225,14 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)hold_locked_index (&lock_file,LOCK_DIE_ON_ERROR ); } +if (!to_tempfile) +get_parallel_checkout_configs (&pc_workers, &pc_threshold); +else + pc_workers =1 ; + +if (pc_workers >1 ) +init_parallel_checkout (); +/* Check out named files first */ for (i =0 ; i < argc; i++) {const char *arg = argv[i];
@@ -262,12 +272,17 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)strbuf_release (&buf); } -if (err) -return 1 ; -if (all)checkout_all (prefix, prefix_length); +if (pc_workers >1 ) { + err |=run_parallel_checkout (&state, pc_workers, pc_threshold, +NULL ,NULL ); + } + +if (err) +return 1 ; +if (is_lock_file_locked (&lock_file) &&write_locked_index (&the_index, &lock_file,COMMIT_LOCK ))die ("Unable to write new index file" );
Signature · 1 line
2.28.0
PATCH v4 16/19 parallel-checkout: add tests for basic operations
In reply to Matheus TavaresAdd tests to populate the working tree during clone and checkout using the sequential and parallel modes, to confirm that they produce identical results. Also test basic checkout mechanics, such as checking for symlinks in the leading directories and the abidance to --force.
Note: some helper functions are added to a common lib file which is only included by t2080 for now. But it will also be used by other parallel-checkout tests in the following patches.
--- t/lib-parallel-checkout.sh | 40 +++++++ t/t2080-parallel-checkout-basics.sh | 170 ++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 t/lib-parallel-checkout.sh create mode 100755 t/t2080-parallel-checkout-basics.sh
t/lib-parallel-checkout.sh new file +40 -0
@@ -0,0 +1,40 @@ +# Helpers for t208* tests + +# Runs `git -c checkout.workers=$1 -c checkout.thesholdForParallelism=$2 ${@:4}` +# and checks that the number of workers spawned is equal to $3. +# +git_pc() +{ + if test $# -lt 4 + then + BUG "too few arguments to git_pc()" + fi && + + workers=$1 threshold=$2 expected_workers=$3 && + shift 3 && + + rm -f trace && + GIT_TRACE2="$(pwd)/trace" git \ + -c checkout.workers=$workers \ + -c checkout.thresholdForParallelism=$threshold \ + -c advice.detachedHead=0 \ + "$@" && + + # Check that the expected number of workers has been used. Note that it + # can be different from the requested number in two cases: when the + # threshold is not reached; and when there are not enough + # parallel-eligible entries for all workers. + # + local workers_in_trace=$(grep "child_start\[..*\] git checkout--helper" trace | wc -l) && + test $workers_in_trace -eq $expected_workers && + rm -f trace +} + +# Verify that both the working tree and the index were created correctly +verify_checkout() +{ + git -C "$1" diff-index --quiet HEAD -- && + git -C "$1" diff-index --quiet --cached HEAD -- && + git -C "$1" status --porcelain >"$1".status && + test_must_be_empty "$1".status +}
t/t2080-parallel-checkout-basics.sh new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v4 17/19 parallel-checkout: add tests related to clone collisions
In reply to Matheus TavaresAdd tests to confirm that path collisions are properly reported during a clone operation using parallel-checkout.
--- t/lib-parallel-checkout.sh | 4 +- t/t2081-parallel-checkout-collisions.sh | 98 +++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100755 t/t2081-parallel-checkout-collisions.sh
t/lib-parallel-checkout.sh +2 -2
@@ -18,7 +18,7 @@ git_pc() -c checkout.workers=$workers \ -c checkout.thresholdForParallelism=$threshold \ -c advice.detachedHead=0 \ - "$@" && + "$@" 2>&8 && # Check that the expected number of workers has been used. Note that it # can be different from the requested number in two cases: when the
@@ -28,7 +28,7 @@ git_pc() local workers_in_trace=$(grep "child_start\[..*\] git checkout--helper" trace | wc -l) && test $workers_in_trace -eq $expected_workers && rm -f trace -} +} 8>&2 2>&4 # Verify that both the working tree and the index were created correctly verify_checkout()
t/t2081-parallel-checkout-collisions.sh new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v4 18/19 parallel-checkout: add tests related to .gitattributes
In reply to Matheus TavaresAdd tests to confirm that struct conv_attrs data is correctly passed from the main process to the workers, and that they properly smudge files before writing to the working tree. Also check that non-parallel-eligible entries, such as regular files that require external filters, are correctly smudge and written when parallel-checkout is enabled.
Note: to avoid repeating code, some helper functions are extracted from t0028 into a common lib file.
--- t/lib-encoding.sh | 25 ++++ t/t0028-working-tree-encoding.sh | 25 +--- t/t2082-parallel-checkout-attributes.sh | 174 ++++++++++++++++++++++++ 3 files changed, 200 insertions(+), 24 deletions(-) create mode 100644 t/lib-encoding.sh create mode 100755 t/t2082-parallel-checkout-attributes.sh
t/lib-encoding.sh new file +25 -0
@@ -0,0 +1,25 @@ +# Encoding helpers used by t0028 and t2082 + +test_lazy_prereq NO_UTF16_BOM ' + test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6 +' + +test_lazy_prereq NO_UTF32_BOM ' + test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12 +' + +write_utf16 () { + if test_have_prereq NO_UTF16_BOM + then + printf '\376\377' + fi && + iconv -f UTF-8 -t UTF-16 +} + +write_utf32 () { + if test_have_prereq NO_UTF32_BOM + then + printf '\0\0\376\377' + fi && + iconv -f UTF-8 -t UTF-32 +}
t/t0028-working-tree-encoding.sh +1 -24
@@ -3,33 +3,10 @@ test_description='working-tree-encoding conversion via gitattributes' . ./test-lib.sh +. "$TEST_DIRECTORY/lib-encoding.sh" GIT_TRACE_WORKING_TREE_ENCODING=1 && export GIT_TRACE_WORKING_TREE_ENCODING -test_lazy_prereq NO_UTF16_BOM ' - test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6 -' - -test_lazy_prereq NO_UTF32_BOM ' - test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12 -' - -write_utf16 () { - if test_have_prereq NO_UTF16_BOM - then - printf '\376\377' - fi && - iconv -f UTF-8 -t UTF-16 -} - -write_utf32 () { - if test_have_prereq NO_UTF32_BOM - then - printf '\0\0\376\377' - fi && - iconv -f UTF-8 -t UTF-32 -} - test_expect_success 'setup test files' ' git config core.eol lf &&
t/t2082-parallel-checkout-attributes.sh new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v4 19/19 ci: run test round with parallel-checkout enabled
In reply to Matheus TavaresWe already have tests for the basic parallel-checkout operations. But this code can also run in other commands, such as git-read-tree and git-sparse-checkout, which are currently not tested with multiple workers. To promote a wider test coverage without duplicating tests:
1. Add the GIT_TEST_CHECKOUT_WORKERS environment variable, to optionally force parallel-checkout execution during the whole test suite.
2. Include this variable in the second test round of the linux-gcc job of our ci scripts. This round runs make test again with some optional GIT_TEST_* variables enabled, so there is no additional overhead in exercising the parallel-checkout code here.
Note: the specific parallel-checkout tests t208* cannot be used in combination with GIT_TEST_CHECKOUT_WORKERS as they need to set and check the number of workers by themselves. So skip those tests when this flag is set.
--- ci/run-build-and-tests.sh | 1 + parallel-checkout.c | 14 ++++++++++++++ t/README | 4 ++++ t/lib-parallel-checkout.sh | 6 ++++++ 4 files changed, 25 insertions(+)
ci/run-build-and-tests.sh +1 -0
@@ -22,6 +22,7 @@ linux-gcc) export GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=1 export GIT_TEST_MULTI_PACK_INDEX=1 export GIT_TEST_ADD_I_USE_BUILTIN=1 + export GIT_TEST_CHECKOUT_WORKERS=2 make test ;; linux-clang)
parallel-checkout.c +14 -0
@@ -32,6 +32,20 @@ enum pc_status parallel_checkout_status(void)void get_parallel_checkout_configs (int *num_workers,int *threshold) { +char *env_workers =getenv ("GIT_TEST_CHECKOUT_WORKERS" ); + +if (env_workers && *env_workers) { +if (strtol_i (env_workers,10 , num_workers)) { +die ("invalid value for GIT_TEST_CHECKOUT_WORKERS: '%s'" , + env_workers); + } +if (*num_workers <1 ) + *num_workers =online_cpus (); + + *threshold =0 ; +return ; + } +if (git_config_get_int ("checkout.workers" , num_workers)) *num_workers =1 ;else if (*num_workers <1 )
t/README +4 -0
@@ -425,6 +425,10 @@ GIT_TEST_DEFAULT_HASH=<hash-algo> specifies which hash algorithm to use in the test scripts. Recognized values for <hash-algo> are "sha1" and "sha256". +GIT_TEST_CHECKOUT_WORKERS=<n> overrides the 'checkout.workers' setting +to <n> and 'checkout.thresholdForParallelism' to 0, forcing the +execution of the parallel-checkout code. + Naming Tests ------------
t/lib-parallel-checkout.sh +6 -0
@@ -1,5 +1,11 @@ # Helpers for t208* tests +if ! test -z "$GIT_TEST_CHECKOUT_WORKERS" +then + skip_all="skipping test, GIT_TEST_CHECKOUT_WORKERS is set" + test_done +fi + # Runs `git -c checkout.workers=$1 -c checkout.thesholdForParallelism=$2 ${@:4}` # and checks that the number of workers spawned is equal to $3. #
Signature · 1 line
2.28.0
v5 cover Parallel Checkout (part I)
In reply to Matheus TavaresThe previous rounds got many great suggestions about patches 1 to 10, but not as many comments on the latter patches. Christian commented that patches 10 and 11 are too long/complex, making the overall series harder to review. So he suggested that I eject patches 10 to 19, and send them later in a separated part. This will hopefully make the series easier to review and move forward. (I also hope to include a desing doc in part 2 to make those two bigger patches more digestible.)
So this part is now composed only of the 9 preparatory patches, which mainly focus on: (1) adding the 'struct conv_attrs' parameter to some convert.c and entry.c functions (to avoid re-loading the attributes during parallel checkout); and (2) making some functions public (for parallel-checkout.c's later use).
Changes since v4:
General:
- Removed "[matheus.bernardino: ...]" lines from patches 1 to 4.
- Ejected patches 10 to 19, which will now be sent in part 2.
Patch 2:
- Fixed typo on commit message (s/on a index/on an index/).
- Added "_ca" to convert_to_working_tree_internal()'s name.
Patch 4:
- Reworded patch title for better clarity, as suggested by Christian.
Patch 5:
- Mentioned about moving a checkout_entry() comment from entry.c to entry.h in the patch's message.
Patch 7:
- Make patch's title more explicit and reworded message for clarity.
Patch 8:
- Fixed the last call to write_entry() in checkout_entry(): it should pass 'ca', not NULL.
Patch 9:
- Defined checkout_entry() -- which is now a wrapper to checkout_entry_ca() -- as a static inline function instead of a macro.
- Shortened patch's title.
Note: to see the big picture where these patches should fit in, please check the previous round with the complete series:
https://lore.kernel.org/git/[email protected]/
Jeff Hostetler (4):
convert: make convert_attrs() and convert structs public
convert: add [async_]convert_to_working_tree_ca() variants
convert: add get_stream_filter_ca() variant
convert: add classification for conv_attrs struct
Matheus Tavares (5):
entry: extract a header file for entry.c functions
entry: make fstat_output() and read_blob_entry() public
entry: extract update_ce_after_write() from write_entry()
entry: move conv_attrs lookup up to checkout_entry()
entry: add checkout_entry_ca() taking preloaded conv_attrs
apply.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/difftool.c | 1 + cache.h | 24 ------- convert.c | 143 ++++++++++++++++++++------------------- convert.h | 96 +++++++++++++++++++++++--- entry.c | 85 +++++++++++++---------- entry.h | 59 ++++++++++++++++ unpack-trees.c | 1 + 10 files changed, 275 insertions(+), 137 deletions(-) create mode 100644 entry.h
Range-diff against v4:
1: 2726f6dc05 ! 1: fa04185237 convert: make convert_attrs() and convert structs public
@@ Commit message
convert_crlf_action, which is more appropriate for the global namespace.
- [matheus.bernardino: squash and reword msg]
## convert.c ##
2: fc03417592 ! 2: 2d3c1dc0a1 convert: add [async_]convert_to_working_tree_ca() variants
@@ Commit message
Separate the attribute gathering from the actual conversion by adding _ca() variants of the conversion functions. These variants receive a
- precomputed 'struct conv_attrs', not relying, thus, on a index state.
+ precomputed 'struct conv_attrs', not relying, thus, on an index state.
They will be used in a future patch adding parallel checkout support, for two reasons:
@@ Commit message
it for the main process, anyway.
- [matheus.bernardino: squash, remove one function definition and reword]
## convert.c ##
@@ convert.c: void convert_to_git_filter_fd(const struct index_state *istate,
}
-static int convert_to_working_tree_internal(const struct index_state *istate,
-+static int convert_to_working_tree_internal(const struct conv_attrs *ca,
- const char *path, const char *src,
- size_t len, struct strbuf *dst,
- int normalizing,
-@@ convert.c: static int convert_to_working_tree_internal(const struct index_state *istate,
- struct delayed_checkout *dco)
+- const char *path, const char *src,
+- size_t len, struct strbuf *dst,
+- int normalizing,
+- const struct checkout_metadata *meta,
+- struct delayed_checkout *dco)
++static int convert_to_working_tree_ca_internal(const struct conv_attrs *ca,
++ const char *path, const char *src,
++ size_t len, struct strbuf *dst,
++ int normalizing,
++ const struct checkout_metadata *meta,
++ struct delayed_checkout *dco)
{
int ret = 0, ret_filter = 0;
- struct conv_attrs ca;
@@ convert.c: static int convert_to_working_tree_internal(const struct index_state
+ void *dco)
{
- return convert_to_working_tree_internal(istate, path, src, len, dst, 0, meta, dco);
-+ return convert_to_working_tree_internal(ca, path, src, len, dst, 0, meta, dco);
++ return convert_to_working_tree_ca_internal(ca, path, src, len, dst, 0,
++ meta, dco);
}
-int convert_to_working_tree(const struct index_state *istate,
@@ convert.c: static int convert_to_working_tree_internal(const struct index_state
+ const struct checkout_metadata *meta)
{
- return convert_to_working_tree_internal(istate, path, src, len, dst, 0, meta, NULL);
-+ return convert_to_working_tree_internal(ca, path, src, len, dst, 0, meta, NULL);
++ return convert_to_working_tree_ca_internal(ca, path, src, len, dst, 0,
++ meta, NULL);
}
int renormalize_buffer(const struct index_state *istate, const char *path,
@@ convert.c: static int convert_to_working_tree_internal(const struct index_state
+ int ret;
+
+ convert_attrs(istate, &ca, path);
-+ ret = convert_to_working_tree_internal(&ca, path, src, len, dst, 1, NULL, NULL);
++ ret = convert_to_working_tree_ca_internal(&ca, path, src, len, dst, 1,
++ NULL, NULL);
if (ret) {
src = dst->buf;
len = dst->len;
3: 8ce20f1031 ! 3: 8af17f6a9b convert: add get_stream_filter_ca() variant
@@ Commit message
attributes struct as a parameter.
- [matheus.bernardino: move header comment to ca() variant and reword msg]
## convert.c ##
4: aa1eb461f4 ! 4: f829e2e08f convert: add conv_attrs classification
@@ Metadata
Author: Jeff Hostetler <[email protected]>
## Commit message ##
- convert: add conv_attrs classification
+ convert: add classification for conv_attrs struct
Create enum conv_attrs_classification to express the different ways that attributes are handled for a blob during checkout.
@@ Commit message
classifying logic is the same).
- [matheus.bernardino: use classification in get_stream_filter_ca()]
## convert.c ##
5: cb3dea224b ! 5: 934ead9519 entry: extract a header file for entry.c functions
@@ Commit message
reside in cache.h. Although not many, they contribute to the size of cache.h and, when changed, cause the unnecessary recompilation of modules that don't really use these functions. So let's move them to a
- new entry.h header.
+ new entry.h header. While at it let's also move a comment related to
+ checkout_entry() from entry.c to entry.h as it's more useful to describe
+ the function there.
6: 46ed6274d7 = 6: da6d1d7624 entry: make fstat_output() and read_blob_entry() public 7: a0479d02ff ! 7: def654606d entry: extract cache_entry update from write_entry()
@@ Metadata
Author: Matheus Tavares <[email protected]>
## Commit message ##
- entry: extract cache_entry update from write_entry()
+ entry: extract update_ce_after_write() from write_entry()
- This code will be used by the parallel checkout functions, outside
- entry.c, so extract it to a public function.
+ The code that updates the in-memory index information after an entry is
+ written currently resides in write_entry(). Extract it to a public
+ function so that it can be called by the parallel checkout functions,
+ outside entry.c, in a later patch.
8: 5c993cc27f ! 8: fbde901518 entry: move conv_attrs lookup up to checkout_entry()
@@ entry.c: int checkout_entry(struct cache_entry *ce, const struct checkout *state
+ ca = &ca_buf;
+ }
+
-+ return write_entry(ce, path.buf, NULL, state, 0);
++ return write_entry(ce, path.buf, ca, state, 0);
}
void unlink_entry(const struct cache_entry *ce)
9: aa635bda21 ! 9: 0556d32e8c entry: add checkout_entry_ca() which takes preloaded conv_attrs
@@ Metadata
Author: Matheus Tavares <[email protected]>
## Commit message ##
- entry: add checkout_entry_ca() which takes preloaded conv_attrs
+ entry: add checkout_entry_ca() taking preloaded conv_attrs
The parallel checkout machinery will call checkout_entry() for entries
that could not be written in parallel due to path collisions. At this
@@ entry.c: int checkout_entry(struct cache_entry *ce, const struct checkout *state
convert_attrs(state->istate, &ca_buf, ce->name);
ca = &ca_buf;
}
-
-- return write_entry(ce, path.buf, NULL, state, 0);
-+ return write_entry(ce, path.buf, ca, state, 0);
- }
-
- void unlink_entry(const struct cache_entry *ce)
## entry.h ##
@@ entry.h: struct checkout {
@@ entry.h: struct checkout {
*/
-int checkout_entry(struct cache_entry *ce, const struct checkout *state,
- char *topath, int *nr_checkouts);
-+#define checkout_entry(ce, state, topath, nr_checkouts) \
-+ checkout_entry_ca(ce, NULL, state, topath, nr_checkouts)
+int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
+ const struct checkout *state, char *topath,
+ int *nr_checkouts);
++static inline int checkout_entry(struct cache_entry *ce,
++ const struct checkout *state, char *topath,
++ int *nr_checkouts)
++{
++ return checkout_entry_ca(ce, NULL, state, topath, nr_checkouts);
++}
void enable_delayed_checkout(struct checkout *state);
int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
10: bc8447cd9c < -: ---------- unpack-trees: add basic support for parallel checkout
11: 815137685a < -: ---------- parallel-checkout: make it truly parallel
12: 2b42621582 < -: ---------- parallel-checkout: support progress displaying
13: 960116579a < -: ---------- make_transient_cache_entry(): optionally alloc from mem_pool
14: fb9f2f580c < -: ---------- builtin/checkout.c: complete parallel checkout support
15: a844451e58 < -: ---------- checkout-index: add parallel checkout support
16: 3733857ffa < -: ---------- parallel-checkout: add tests for basic operations
17: c8a2974f81 < -: ---------- parallel-checkout: add tests related to clone collisions
18: 86fccd57d5 < -: ---------- parallel-checkout: add tests related to .gitattributes
19: 7f3e23cc38 < -: ---------- ci: run test round with parallel-checkout enabledSignature · 1 line
2.29.2
PATCH v5 1/9 convert: make convert_attrs() and convert structs public
From: Jeff Hostetler <[email protected]>
Move convert_attrs() declaration from convert.c to convert.h, together with the conv_attrs struct and the crlf_action enum. This function and the data structures will be used outside convert.c in the upcoming parallel checkout implementation. Note that crlf_action is renamed to convert_crlf_action, which is more appropriate for the global namespace.
--- convert.c | 35 ++++++++--------------------------- convert.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 27 deletions(-)
convert.c +8 -27
@@ -24,17 +24,6 @@#define CONVERT_STAT_BITS_TXT_CRLF 0x2#define CONVERT_STAT_BITS_BIN 0x4 -enum crlf_action { -CRLF_UNDEFINED , -CRLF_BINARY , -CRLF_TEXT , -CRLF_TEXT_INPUT , -CRLF_TEXT_CRLF , -CRLF_AUTO , -CRLF_AUTO_INPUT , -CRLF_AUTO_CRLF -}; -struct text_stat {/* NUL, CR, LF and CRLF counts */ unsigned nul, lonecr, lonelf, crlf;
@@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)return 0 ; } -static enum eol output_eol (enum crlf_action crlf_action) +static enum eol output_eol (enum convert_crlf_action crlf_action) {switch (crlf_action) {case CRLF_BINARY :
@@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path) }static int will_convert_lf_to_crlf (struct text_stat *stats, -enum crlf_action crlf_action) +enum convert_crlf_action crlf_action) {if (output_eol (crlf_action) !=EOL_CRLF )return 0 ;
@@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,static int crlf_to_git (const struct index_state *istate,const char *path,const char *src,size_t len,struct strbuf *buf, -enum crlf_action crlf_action,int conv_flags) +enum convert_crlf_action crlf_action,int conv_flags) {struct text_stat stats;char *dst;
@@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,return 1 ; } -static int crlf_to_worktree (const char *src,size_t len, -struct strbuf *buf,enum crlf_action crlf_action) +static int crlf_to_worktree (const char *src,size_t len,struct strbuf *buf, +enum convert_crlf_action crlf_action) {char *to_free =NULL ;struct text_stat stats;
@@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)return value; } -static enum crlf_action git_path_check_crlf (struct attr_check_item *check) +static enum convert_crlf_action git_path_check_crlf (struct attr_check_item *check) {const char *value = check->value;
@@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)return !!ATTR_TRUE (value); } -struct conv_attrs { -struct convert_driver *drv; -enum crlf_action attr_action;/* What attr says */ -enum crlf_action crlf_action;/* When no attr is set, use core.autocrlf */ -int ident; -const char *working_tree_encoding;/* Supported encoding or default encoding if NULL */ -}; -static struct attr_check *check; -static void convert_attrs (const struct index_state *istate, -struct conv_attrs *ca,const char *path) +void convert_attrs (const struct index_state *istate, +struct conv_attrs *ca,const char *path) {struct attr_check_item *ccheck =NULL ;
convert.h +24 -0
@@ -63,6 +63,30 @@ struct checkout_metadata {struct object_id blob; }; +enum convert_crlf_action { +CRLF_UNDEFINED , +CRLF_BINARY , +CRLF_TEXT , +CRLF_TEXT_INPUT , +CRLF_TEXT_CRLF , +CRLF_AUTO , +CRLF_AUTO_INPUT , +CRLF_AUTO_CRLF +}; + +struct convert_driver ; + +struct conv_attrs { +struct convert_driver *drv; +enum convert_crlf_action attr_action;/* What attr says */ +enum convert_crlf_action crlf_action;/* When no attr is set, use core.autocrlf */ +int ident; +const char *working_tree_encoding;/* Supported encoding or default encoding if NULL */ +}; + +void convert_attrs (const struct index_state *istate, +struct conv_attrs *ca,const char *path); +extern enum eol core_eol;extern char *check_roundtrip_encoding; const char *get_cached_convert_stats_ascii(const struct index_state *istate,
Signature · 1 line
2.29.2
PATCH v5 2/9 convert: add [async_]convert_to_working_tree_ca() variants
In reply to Matheus TavaresFrom: Jeff Hostetler <[email protected]>
Separate the attribute gathering from the actual conversion by adding _ca() variants of the conversion functions. These variants receive a precomputed 'struct conv_attrs', not relying, thus, on an index state. They will be used in a future patch adding parallel checkout support, for two reasons:
- We will already load the conversion attributes in checkout_entry(), before conversion, to decide whether a path is eligible for parallel checkout. Therefore, it would be wasteful to load them again later, for the actual conversion.
- The parallel workers will be responsible for reading, converting and writing blobs to the working tree. They won't have access to the main process' index state, so they cannot load the attributes. Instead, they will receive the preloaded ones and call the _ca() variant of the conversion functions. Furthermore, the attributes machinery is optimized to handle paths in sequential order, so it's better to leave it for the main process, anyway.
--- convert.c | 60 +++++++++++++++++++++++++++++-------------------------- convert.h | 37 +++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 37 deletions(-)
convert.c +32 -28
@@ -1447,19 +1447,16 @@ void convert_to_git_filter_fd(const struct index_state *istate,ident_to_git (dst->buf, dst->len, dst, ca.ident); } -static int convert_to_working_tree_internal (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -int normalizing, -const struct checkout_metadata *meta, -struct delayed_checkout *dco) +static int convert_to_working_tree_ca_internal (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +int normalizing, +const struct checkout_metadata *meta, +struct delayed_checkout *dco) {int ret =0 , ret_filter =0 ; -struct conv_attrs ca; - -convert_attrs (istate, &ca, path); - ret |=ident_to_worktree (src, len, dst, ca.ident); + ret |=ident_to_worktree (src, len, dst, ca->ident);if (ret) { src = dst->buf; len = dst->len;
@@ -1469,49 +1466,56 @@ static int convert_to_working_tree_internal(const struct index_state *istate,* is a smudge or process filter (even if the process filter doesn't * support smudge). The filters might expect CRLFs. */ -if ((ca.drv && (ca.drv->smudge || ca.drv->process)) || !normalizing) { - ret |=crlf_to_worktree (src, len, dst, ca.crlf_action); +if ((ca->drv && (ca->drv->smudge || ca->drv->process)) || !normalizing) { + ret |=crlf_to_worktree (src, len, dst, ca->crlf_action);if (ret) { src = dst->buf; len = dst->len; } } - ret |=encode_to_worktree (path, src, len, dst, ca.working_tree_encoding); + ret |=encode_to_worktree (path, src, len, dst, ca->working_tree_encoding);if (ret) { src = dst->buf; len = dst->len; } ret_filter =apply_filter ( - path, src, len,-1 , dst, ca.drv,CAP_SMUDGE , meta, dco); -if (!ret_filter && ca.drv && ca.drv->required) -die (_ ("%s: smudge filter %s failed" ), path, ca.drv->name); + path, src, len,-1 , dst, ca->drv,CAP_SMUDGE , meta, dco); +if (!ret_filter && ca->drv && ca->drv->required) +die (_ ("%s: smudge filter %s failed" ), path, ca->drv->name);return ret | ret_filter; } -int async_convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta, -void *dco) +int async_convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta, +void *dco) { -return convert_to_working_tree_internal (istate, path, src, len, dst,0 , meta, dco); +return convert_to_working_tree_ca_internal (ca, path, src, len, dst,0 , + meta, dco); } -int convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta) +int convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta) { -return convert_to_working_tree_internal (istate, path, src, len, dst,0 , meta,NULL ); +return convert_to_working_tree_ca_internal (ca, path, src, len, dst,0 , + meta,NULL ); }int renormalize_buffer (const struct index_state *istate,const char *path,const char *src,size_t len,struct strbuf *dst) { -int ret =convert_to_working_tree_internal (istate, path, src, len, dst,1 ,NULL ,NULL ); +struct conv_attrs ca; +int ret; + +convert_attrs (istate, &ca, path); + ret =convert_to_working_tree_ca_internal (&ca, path, src, len, dst,1 , +NULL ,NULL );if (ret) { src = dst->buf; len = dst->len;
convert.h +28 -9
@@ -99,15 +99,34 @@ const char *get_convert_attr_ascii(const struct index_state *istate,int convert_to_git (const struct index_state *istate,const char *path,const char *src,size_t len,struct strbuf *dst,int conv_flags); -int convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta); -int async_convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta, -void *dco); +int convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta); +int async_convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta, +void *dco); +static inline int convert_to_working_tree (const struct index_state *istate, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta) +{ +struct conv_attrs ca; +convert_attrs (istate, &ca, path); +return convert_to_working_tree_ca (&ca, path, src, len, dst, meta); +} +static inline int async_convert_to_working_tree (const struct index_state *istate, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta, +void *dco) +{ +struct conv_attrs ca; +convert_attrs (istate, &ca, path); +return async_convert_to_working_tree_ca (&ca, path, src, len, dst, meta, dco); +}int async_query_available_blobs (const char *cmd,struct string_list *available_paths); int renormalize_buffer(const struct index_state *istate,
Signature · 1 line
2.29.2
PATCH v5 3/9 convert: add get_stream_filter_ca() variant
In reply to Matheus TavaresFrom: Jeff Hostetler <[email protected]>
Like the previous patch, we will also need to call get_stream_filter() with a precomputed struct conv_attrs, when we add support for parallel checkout workers. So add the _ca() variant which takes the conversion attributes struct as a parameter.
--- convert.c | 28 +++++++++++++++++----------- convert.h | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-)
convert.c +17 -11
@@ -1942,34 +1942,31 @@ static struct stream_filter *ident_filter(const struct object_id *oid) }/* -* Return an appropriately constructed filter for the path, or NULL if +* Return an appropriately constructed filter for the given ca, or NULL if * the contents cannot be filtered without reading the whole thing * in-core. * * Note that you would be crazy to set CRLF, smudge/clean or ident to a * large binary blob you would want us not to slurp into the memory! */ -struct stream_filter *get_stream_filter (const struct index_state *istate, -const char *path, -const struct object_id *oid) +struct stream_filter *get_stream_filter_ca (const struct conv_attrs *ca, +const struct object_id *oid) { -struct conv_attrs ca;struct stream_filter *filter =NULL ; -convert_attrs (istate, &ca, path); -if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean)) +if (ca->drv && (ca->drv->process || ca->drv->smudge || ca->drv->clean))return NULL ; -if (ca.working_tree_encoding) +if (ca->working_tree_encoding)return NULL ; -if (ca.crlf_action ==CRLF_AUTO || ca.crlf_action ==CRLF_AUTO_CRLF ) +if (ca->crlf_action ==CRLF_AUTO || ca->crlf_action ==CRLF_AUTO_CRLF )return NULL ; -if (ca.ident) +if (ca->ident) filter =ident_filter (oid); -if (output_eol (ca.crlf_action) ==EOL_CRLF ) +if (output_eol (ca->crlf_action) ==EOL_CRLF ) filter =cascade_filter (filter,lf_to_crlf_filter ());else filter =cascade_filter (filter, &null_filter_singleton);
@@ -1977,6 +1974,15 @@ struct stream_filter *get_stream_filter(const struct index_state *istate,return filter; } +struct stream_filter *get_stream_filter (const struct index_state *istate, +const char *path, +const struct object_id *oid) +{ +struct conv_attrs ca; +convert_attrs (istate, &ca, path); +return get_stream_filter_ca (&ca, oid); +} +void free_stream_filter (struct stream_filter *filter) { filter->vtbl->free (filter);
convert.h +2 -0
@@ -179,6 +179,8 @@ struct stream_filter; /* opaque */struct stream_filter *get_stream_filter (const struct index_state *istate,const char *path,const struct object_id *); +struct stream_filter *get_stream_filter_ca (const struct conv_attrs *ca, +const struct object_id *oid);void free_stream_filter (struct stream_filter *);int is_null_stream_filter (struct stream_filter *);
Signature · 1 line
2.29.2
PATCH v5 4/9 convert: add classification for conv_attrs struct
In reply to Matheus TavaresFrom: Jeff Hostetler <[email protected]>
Create enum conv_attrs_classification to express the different ways that attributes are handled for a blob during checkout.
This will be used in a later commit when deciding whether to add a file to the parallel or delayed queue during checkout. For now, we can also use it in get_stream_filter_ca() to simplify the function (as the classifying logic is the same).
--- convert.c | 26 +++++++++++++++++++------- convert.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-)
convert.c +19 -7
@@ -1954,13 +1954,7 @@ struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca, {struct stream_filter *filter =NULL ; -if (ca->drv && (ca->drv->process || ca->drv->smudge || ca->drv->clean)) -return NULL ; - -if (ca->working_tree_encoding) -return NULL ; - -if (ca->crlf_action ==CRLF_AUTO || ca->crlf_action ==CRLF_AUTO_CRLF ) +if (classify_conv_attrs (ca) !=CA_CLASS_STREAMABLE )return NULL ;if (ca->ident)
@@ -2016,3 +2010,21 @@ void clone_checkout_metadata(struct checkout_metadata *dst,if (blob)oidcpy (&dst->blob, blob); } + +enum conv_attrs_classification classify_conv_attrs (const struct conv_attrs *ca) +{ +if (ca->drv) { +if (ca->drv->process) +return CA_CLASS_INCORE_PROCESS ; +if (ca->drv->smudge || ca->drv->clean) +return CA_CLASS_INCORE_FILTER ; + } + +if (ca->working_tree_encoding) +return CA_CLASS_INCORE ; + +if (ca->crlf_action ==CRLF_AUTO || ca->crlf_action ==CRLF_AUTO_CRLF ) +return CA_CLASS_INCORE ; + +return CA_CLASS_STREAMABLE ; +}
convert.h +33 -0
@@ -200,4 +200,37 @@ int stream_filter(struct stream_filter *, const char *input, size_t *isize_p, char *output, size_t *osize_p); +enum conv_attrs_classification { +/* +* The blob must be loaded into a buffer before it can be +* smudged. All smudging is done in-proc. +*/ +CA_CLASS_INCORE , + +/* +* The blob must be loaded into a buffer, but uses a +* single-file driver filter, such as rot13. +*/ +CA_CLASS_INCORE_FILTER , + +/* +* The blob must be loaded into a buffer, but uses a +* long-running driver process, such as LFS. This might or +* might not use delayed operations. (The important thing is +* that there is a single subordinate long-running process +* handling all associated blobs and in case of delayed +* operations, may hold per-blob state.) +*/ +CA_CLASS_INCORE_PROCESS , + +/* +* The blob can be streamed and smudged without needing to +* completely read it into a buffer. +*/ +CA_CLASS_STREAMABLE , +}; + +enum conv_attrs_classification classify_conv_attrs ( +const struct conv_attrs *ca); +#endif /* CONVERT_H */
Signature · 1 line
2.29.2
PATCH v5 5/9 entry: extract a header file for entry.c functions
In reply to Matheus TavaresThe declarations of entry.c's public functions and structures currently reside in cache.h. Although not many, they contribute to the size of cache.h and, when changed, cause the unnecessary recompilation of modules that don't really use these functions. So let's move them to a new entry.h header. While at it let's also move a comment related to checkout_entry() from entry.c to entry.h as it's more useful to describe the function there.
--- apply.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/difftool.c | 1 + cache.h | 24 ----------------------- entry.c | 9 +-------- entry.h | 42 ++++++++++++++++++++++++++++++++++++++++ unpack-trees.c | 1 + 8 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 entry.h
apply.c +1 -0
@@ -21,6 +21,7 @@#include "quote.h" #include "rerere.h" #include "apply.h" +#include "entry.h" struct gitdiff_data {struct strbuf *root;
builtin/checkout-index.c +1 -0
@@ -11,6 +11,7 @@#include "quote.h" #include "cache-tree.h" #include "parse-options.h" +#include "entry.h" #define CHECKOUT_ALL 4static int nul_term_line;
builtin/checkout.c +1 -0
@@ -26,6 +26,7 @@#include "unpack-trees.h" #include "wt-status.h" #include "xdiff-interface.h" +#include "entry.h" static const char *const checkout_usage[] = {N_ ("git checkout [<options>] <branch>" ),
builtin/difftool.c +1 -0
@@ -23,6 +23,7 @@#include "lockfile.h" #include "object-store.h" #include "dir.h" +#include "entry.h" static int trust_exit_code;
cache.h +0 -24
@@ -1711,30 +1711,6 @@ const char *show_ident_date(const struct ident_split *id,*/ int ident_cmp (const struct ident_split *,const struct ident_split *); -struct checkout { -struct index_state *istate; -const char *base_dir; -int base_dir_len; -struct delayed_checkout *delayed_checkout; -struct checkout_metadata meta; -unsigned force:1 , - quiet:1 , - not_new:1 , - clone:1 , - refresh_cache:1 ; -}; -#define CHECKOUT_INIT { NULL, "" } - -#define TEMPORARY_FILENAME_LENGTH 25 -int checkout_entry (struct cache_entry *ce,const struct checkout *state,char *topath,int *nr_checkouts); -void enable_delayed_checkout (struct checkout *state); -int finish_delayed_checkout (struct checkout *state,int *nr_checkouts); -/* -* Unlink the last component and schedule the leading directories for -* removal, such that empty directories get removed. -*/ -void unlink_entry (const struct cache_entry *ce); -struct cache_def {struct strbuf path;int flags;
entry.c +1 -8
@@ -6,6 +6,7 @@#include "submodule.h" #include "progress.h" #include "fsmonitor.h" +#include "entry.h" static void create_directories (const char *path,int path_len,const struct checkout *state)
@@ -429,14 +430,6 @@ static void mark_colliding_entries(const struct checkout *state, } } -/* -* Write the contents from ce out to the working tree. -* -* When topath[] is not NULL, instead of writing to the working tree -* file named by ce, a temporary file is created by this function and -* its name is returned in topath[], which must be able to hold at -* least TEMPORARY_FILENAME_LENGTH bytes long. -*/ int checkout_entry (struct cache_entry *ce,const struct checkout *state,char *topath,int *nr_checkouts) {
entry.h new file +42 -0
42 lines not on this page · raw message
unpack-trees.c +1 -0
@@ -16,6 +16,7 @@#include "fsmonitor.h" #include "object-store.h" #include "promisor-remote.h" +#include "entry.h" /* * Error messages expected by scripts out of plumbing commands such as
Signature · 1 line
2.29.2
PATCH v5 6/9 entry: make fstat_output() and read_blob_entry() public
In reply to Matheus TavaresThese two functions will be used by the parallel checkout code, so let's make them public. Note: fstat_output() is renamed to fstat_checkout_output(), now that it has become public, seeking to avoid future name collisions.
--- entry.c | 8 ++++---- entry.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-)
entry.c +4 -4
@@ -84,7 +84,7 @@ static int create_file(const char *path, unsigned int mode)return open (path,O_WRONLY |O_CREAT |O_EXCL , mode); } -static void *read_blob_entry (const struct cache_entry *ce,unsigned long *size) +void *read_blob_entry (const struct cache_entry *ce,unsigned long *size) {enum object_type type;void *blob_data =read_object_file (&ce->oid, &type, size);
@@ -109,7 +109,7 @@ static int open_output_fd(char *path, const struct cache_entry *ce, int to_tempf } } -static int fstat_output (int fd,const struct checkout *state,struct stat *st) +int fstat_checkout_output (int fd,const struct checkout *state,struct stat *st) {/* use fstat() only when path == ce->name */ if (fstat_is_reliable() &&
@@ -132,7 +132,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path,return -1 ; result |=stream_blob_to_fd (fd, &ce->oid, filter,1 ); - *fstat_done =fstat_output (fd, state, statbuf); + *fstat_done =fstat_checkout_output (fd, state, statbuf); result |=close (fd);if (result)
@@ -346,7 +346,7 @@ static int write_entry(struct cache_entry *ce, wrote =write_in_full (fd, new_blob, size);if (!to_tempfile) - fstat_done =fstat_output (fd, state, &st); + fstat_done =fstat_checkout_output (fd, state, &st);close (fd);free (new_blob);if (wrote <0 )
entry.h +3 -0
@@ -39,4 +39,7 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);*/ void unlink_entry (const struct cache_entry *ce); +void *read_blob_entry (const struct cache_entry *ce,unsigned long *size); +int fstat_checkout_output (int fd,const struct checkout *state,struct stat *st); +#endif /* ENTRY_H */
Signature · 1 line
2.29.2
PATCH v5 7/9 entry: extract update_ce_after_write() from write_entry()
In reply to Matheus TavaresThe code that updates the in-memory index information after an entry is written currently resides in write_entry(). Extract it to a public function so that it can be called by the parallel checkout functions, outside entry.c, in a later patch.
--- entry.c | 25 ++++++++++++++++--------- entry.h | 2 ++ 2 files changed, 18 insertions(+), 9 deletions(-)
entry.c +16 -9
@@ -251,6 +251,18 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)return errs; } +void update_ce_after_write (const struct checkout *state,struct cache_entry *ce, +struct stat *st) +{ +if (state->refresh_cache) { +assert (state->istate); +fill_stat_cache_info (state->istate, ce, st); + ce->ce_flags |=CE_UPDATE_IN_BASE ; +mark_fsmonitor_invalid (state->istate, ce); + state->istate->cache_changed |=CE_ENTRY_CHANGED ; + } +} +static int write_entry (struct cache_entry *ce,char *path,const struct checkout *state,int to_tempfile) {
@@ -371,15 +383,10 @@ static int write_entry(struct cache_entry *ce, finish:if (state->refresh_cache) { -assert (state->istate); -if (!fstat_done) -if (lstat (ce->name, &st) <0 ) -return error_errno ("unable to stat just-written file %s" , - ce->name); -fill_stat_cache_info (state->istate, ce, &st); - ce->ce_flags |=CE_UPDATE_IN_BASE ; -mark_fsmonitor_invalid (state->istate, ce); - state->istate->cache_changed |=CE_ENTRY_CHANGED ; +if (!fstat_done &&lstat (ce->name, &st) <0 ) +return error_errno ("unable to stat just-written file %s" , + ce->name); +update_ce_after_write (state, ce , &st); } delayed:return 0 ;
entry.h +2 -0
@@ -41,5 +41,7 @@ void unlink_entry(const struct cache_entry *ce);void *read_blob_entry (const struct cache_entry *ce,unsigned long *size);int fstat_checkout_output (int fd,const struct checkout *state,struct stat *st); +void update_ce_after_write (const struct checkout *state,struct cache_entry *ce, +struct stat *st);#endif /* ENTRY_H */
Signature · 1 line
2.29.2
PATCH v5 8/9 entry: move conv_attrs lookup up to checkout_entry()
In reply to Matheus TavaresIn a following patch, checkout_entry() will use conv_attrs to decide whether an entry should be enqueued for parallel checkout or not. But the attributes lookup only happens lower in this call stack. To avoid the unnecessary work of loading the attributes twice, let's move it up to checkout_entry(), and pass the loaded struct down to write_entry().
--- entry.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
entry.c +27 -11
@@ -263,8 +263,9 @@ void update_ce_after_write(const struct checkout *state, struct cache_entry *ce, } } -static int write_entry (struct cache_entry *ce, -char *path,const struct checkout *state,int to_tempfile) +/* Note: ca is used (and required) iff the entry refers to a regular file. */ +static int write_entry (struct cache_entry *ce,char *path,struct conv_attrs *ca, +const struct checkout *state,int to_tempfile) {unsigned int ce_mode_s_ifmt = ce->ce_mode &S_IFMT ;struct delayed_checkout *dco = state->delayed_checkout;
@@ -281,8 +282,7 @@ static int write_entry(struct cache_entry *ce,clone_checkout_metadata (&meta, &state->meta, &ce->oid); if (ce_mode_s_ifmt == S_IFREG) { - struct stream_filter *filter = get_stream_filter(state->istate, ce->name, - &ce->oid); + struct stream_filter *filter = get_stream_filter_ca(ca, &ce->oid); if (filter && !streaming_write_entry(ce, path, filter, state, to_tempfile,
@@ -329,14 +329,17 @@ static int write_entry(struct cache_entry *ce,* Convert from git internal format to working tree format */ if (dco && dco->state !=CE_NO_DELAY ) { - ret =async_convert_to_working_tree (state->istate, ce->name, new_blob, - size, &buf, &meta, dco); + ret =async_convert_to_working_tree_ca (ca, ce->name, + new_blob, size, + &buf, &meta, dco);if (ret &&string_list_has_string (&dco->paths, ce->name)) {free (new_blob); goto delayed; } - }else - ret =convert_to_working_tree (state->istate, ce->name, new_blob, size, &buf, &meta); + }else { + ret =convert_to_working_tree_ca (ca, ce->name, new_blob, + size, &buf, &meta); + }if (ret) {free (new_blob);
@@ -442,6 +445,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, {static struct strbuf path =STRBUF_INIT ;struct stat st; +struct conv_attrs ca_buf, *ca =NULL ;if (ce->ce_flags &CE_WT_REMOVE ) {if (topath)
@@ -454,8 +458,13 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,return 0 ; } -if (topath) -return write_entry (ce, topath, state,1 ); +if (topath) { +if (S_ISREG (ce->ce_mode)) { +convert_attrs (state->istate, &ca_buf, ce->name); + ca = &ca_buf; + } +return write_entry (ce, topath, ca, state,1 ); + }strbuf_reset (&path);strbuf_add (&path, state->base_dir, state->base_dir_len);
@@ -517,9 +526,16 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,return 0 ;create_directories (path.buf, path.len, state); +if (nr_checkouts) (*nr_checkouts)++; -return write_entry (ce, path.buf, state,0 ); + +if (S_ISREG (ce->ce_mode)) { +convert_attrs (state->istate, &ca_buf, ce->name); + ca = &ca_buf; + } + +return write_entry (ce, path.buf, ca, state,0 ); }void unlink_entry (const struct cache_entry *ce)
Signature · 1 line
2.29.2
PATCH v5 9/9 entry: add checkout_entry_ca() taking preloaded conv_attrs
In reply to Matheus TavaresThe parallel checkout machinery will call checkout_entry() for entries that could not be written in parallel due to path collisions. At this point, we will already be holding the conversion attributes for each entry, and it would be wasteful to let checkout_entry() load these again. Instead, let's add the checkout_entry_ca() variant, which optionally takes a preloaded conv_attrs struct.
--- entry.c | 11 ++++++----- entry.h | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-)
entry.c +6 -5
@@ -440,12 +440,13 @@ static void mark_colliding_entries(const struct checkout *state, } } -int checkout_entry (struct cache_entry *ce,const struct checkout *state, -char *topath,int *nr_checkouts) +int checkout_entry_ca (struct cache_entry *ce,struct conv_attrs *ca, +const struct checkout *state,char *topath, +int *nr_checkouts) {static struct strbuf path =STRBUF_INIT ;struct stat st; -struct conv_attrs ca_buf, *ca =NULL ; +struct conv_attrs ca_buf;if (ce->ce_flags &CE_WT_REMOVE ) {if (topath)
@@ -459,7 +460,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, }if (topath) { -if (S_ISREG (ce->ce_mode)) { +if (S_ISREG (ce->ce_mode) && !ca) {convert_attrs (state->istate, &ca_buf, ce->name); ca = &ca_buf; }
@@ -530,7 +531,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,if (nr_checkouts) (*nr_checkouts)++; -if (S_ISREG (ce->ce_mode)) { +if (S_ISREG (ce->ce_mode) && !ca) {convert_attrs (state->istate, &ca_buf, ce->name); ca = &ca_buf; }
entry.h +14 -2
@@ -26,9 +26,21 @@ struct checkout {* file named by ce, a temporary file is created by this function and * its name is returned in topath[], which must be able to hold at * least TEMPORARY_FILENAME_LENGTH bytes long. +* +* With checkout_entry_ca(), callers can optionally pass a preloaded +* conv_attrs struct (to avoid reloading it), when ce refers to a +* regular file. If ca is NULL, the attributes will be loaded +* internally when (and if) needed. */ -int checkout_entry (struct cache_entry *ce,const struct checkout *state, -char *topath,int *nr_checkouts); +int checkout_entry_ca (struct cache_entry *ce,struct conv_attrs *ca, +const struct checkout *state,char *topath, +int *nr_checkouts); +static inline int checkout_entry (struct cache_entry *ce, +const struct checkout *state,char *topath, +int *nr_checkouts) +{ +return checkout_entry_ca (ce,NULL , state, topath, nr_checkouts); +}void enable_delayed_checkout (struct checkout *state);int finish_delayed_checkout (struct checkout *state,int *nr_checkouts);
Signature · 1 line
2.29.2
Re: [PATCH v5 0/9] Parallel Checkout (part I)
In reply to Matheus TavaresQuoted 8 lines · Matheus Tavares
The previous rounds got many great suggestions about patches 1 to 10, but not as many comments on the latter patches. Christian commented that patches 10 and 11 are too long/complex, making the overall series harder to review. So he suggested that I eject patches 10 to 19, and send them later in a separated part. This will hopefully make the series easier to review and move forward. (I also hope to include a desing doc in part 2 to make those two bigger patches more digestible.)
Thanks, and yeah, sorry I suggested that privately, but should have done it on the mailing list.
I actually think that patches 10 and 11 (which each one contains 400+ new lines) in the previous series should be mostly alone in a part 2, with perhaps a part 3 that would have most of the rest, so improvements and tests.
It might also be possible to split at least a bit a few things in patches 10 and 11. For example I think it's ok to add new configuration in a separate patch even if it's not used yet. It can just reserve the name. That could be in part 2 then.
Quoted 1 line
Changes since v4:
From a quick look at the range-diff, it looks good to me!
Thanks,
Christian.
Re: [PATCH v5 0/9] Parallel Checkout (part I)
In reply to Matheus TavaresQuoted 8 lines · Matheus Tavares
The previous rounds got many great suggestions about patches 1 to 10, but not as many comments on the latter patches. Christian commented that patches 10 and 11 are too long/complex, making the overall series harder to review. So he suggested that I eject patches 10 to 19, and send them later in a separated part. This will hopefully make the series easier to review and move forward. (I also hope to include a desing doc in part 2 to make those two bigger patches more digestible.)
Quoted 5 lines
So this part is now composed only of the 9 preparatory patches, which mainly focus on: (1) adding the 'struct
conv_attrs' parameter to someconvert.candentry.cfunctions (to avoid re-loading the attributes during parallel checkout); and (2) making some functions public (for parallel-checkout.c's later use).
All of these patches look sensible to me.
Will replace. Thanks.
v6 cover Parallel Checkout (part 1)
In reply to Matheus TavaresPreparatory API changes for parallel checkout. This version was rebased on top of 'master'. The only change required in this change of base was the entry.h inclusion on builtin/stash.c, at the commit that creates this header file.
Jeff Hostetler (4):
convert: make convert_attrs() and convert structs public
convert: add [async_]convert_to_working_tree_ca() variants
convert: add get_stream_filter_ca() variant
convert: add classification for conv_attrs struct
Matheus Tavares (5):
entry: extract a header file for entry.c functions
entry: make fstat_output() and read_blob_entry() public
entry: extract update_ce_after_write() from write_entry()
entry: move conv_attrs lookup up to checkout_entry()
entry: add checkout_entry_ca() taking preloaded conv_attrs
apply.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/difftool.c | 1 + builtin/stash.c | 1 + cache.h | 24 ------- convert.c | 143 ++++++++++++++++++++------------------- convert.h | 96 +++++++++++++++++++++++--- entry.c | 85 +++++++++++++---------- entry.h | 59 ++++++++++++++++ unpack-trees.c | 1 + 11 files changed, 276 insertions(+), 137 deletions(-) create mode 100644 entry.h
Range-diff against v5:
1: 9909ccee14 = 1: 5e8a1b6a1c convert: make convert_attrs() and convert structs public
2: ec4e645aea = 2: 91d1a3063b convert: add [async_]convert_to_working_tree_ca() variants
3: 1834a54dfd = 3: ab1bf85b75 convert: add get_stream_filter_ca() variant
4: b26022af45 = 4: 01ac6176cc convert: add classification for conv_attrs struct
5: 837fccde5b ! 5: 4d85af1579 entry: extract a header file for entry.c functions
@@ builtin/difftool.c
static int trust_exit_code;
+ ## builtin/stash.c ##
+@@
+ #include "log-tree.h"
+ #include "diffcore.h"
+ #include "exec-cmd.h"
++#include "entry.h"
+
+ #define INCLUDE_ALL_FILES 2
+
+
## cache.h ##
@@ cache.h: const char *show_ident_date(const struct ident_split *id,
*/
6: 231e81fb82 = 6: af8b1691cc entry: make fstat_output() and read_blob_entry() public
7: 2fd8d35242 = 7: b28e518c0d entry: extract update_ce_after_write() from write_entry()
8: 7531ad195b = 8: 87b9d4590a entry: move conv_attrs lookup up to checkout_entry()
9: bf6b7259cb = 9: aa36bfee87 entry: add checkout_entry_ca() taking preloaded conv_attrsSignature · 1 line
2.30.1
PATCH v6 1/9 convert: make convert_attrs() and convert structs public
From: Jeff Hostetler <[email protected]>
Move convert_attrs() declaration from convert.c to convert.h, together with the conv_attrs struct and the crlf_action enum. This function and the data structures will be used outside convert.c in the upcoming parallel checkout implementation. Note that crlf_action is renamed to convert_crlf_action, which is more appropriate for the global namespace.
--- convert.c | 35 ++++++++--------------------------- convert.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 27 deletions(-)
convert.c +8 -27
@@ -24,17 +24,6 @@#define CONVERT_STAT_BITS_TXT_CRLF 0x2#define CONVERT_STAT_BITS_BIN 0x4 -enum crlf_action { -CRLF_UNDEFINED , -CRLF_BINARY , -CRLF_TEXT , -CRLF_TEXT_INPUT , -CRLF_TEXT_CRLF , -CRLF_AUTO , -CRLF_AUTO_INPUT , -CRLF_AUTO_CRLF -}; -struct text_stat {/* NUL, CR, LF and CRLF counts */ unsigned nul, lonecr, lonelf, crlf;
@@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)return 0 ; } -static enum eol output_eol (enum crlf_action crlf_action) +static enum eol output_eol (enum convert_crlf_action crlf_action) {switch (crlf_action) {case CRLF_BINARY :
@@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path) }static int will_convert_lf_to_crlf (struct text_stat *stats, -enum crlf_action crlf_action) +enum convert_crlf_action crlf_action) {if (output_eol (crlf_action) !=EOL_CRLF )return 0 ;
@@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,static int crlf_to_git (const struct index_state *istate,const char *path,const char *src,size_t len,struct strbuf *buf, -enum crlf_action crlf_action,int conv_flags) +enum convert_crlf_action crlf_action,int conv_flags) {struct text_stat stats;char *dst;
@@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,return 1 ; } -static int crlf_to_worktree (const char *src,size_t len, -struct strbuf *buf,enum crlf_action crlf_action) +static int crlf_to_worktree (const char *src,size_t len,struct strbuf *buf, +enum convert_crlf_action crlf_action) {char *to_free =NULL ;struct text_stat stats;
@@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)return value; } -static enum crlf_action git_path_check_crlf (struct attr_check_item *check) +static enum convert_crlf_action git_path_check_crlf (struct attr_check_item *check) {const char *value = check->value;
@@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)return !!ATTR_TRUE (value); } -struct conv_attrs { -struct convert_driver *drv; -enum crlf_action attr_action;/* What attr says */ -enum crlf_action crlf_action;/* When no attr is set, use core.autocrlf */ -int ident; -const char *working_tree_encoding;/* Supported encoding or default encoding if NULL */ -}; -static struct attr_check *check; -static void convert_attrs (const struct index_state *istate, -struct conv_attrs *ca,const char *path) +void convert_attrs (const struct index_state *istate, +struct conv_attrs *ca,const char *path) {struct attr_check_item *ccheck =NULL ;
convert.h +24 -0
@@ -63,6 +63,30 @@ struct checkout_metadata {struct object_id blob; }; +enum convert_crlf_action { +CRLF_UNDEFINED , +CRLF_BINARY , +CRLF_TEXT , +CRLF_TEXT_INPUT , +CRLF_TEXT_CRLF , +CRLF_AUTO , +CRLF_AUTO_INPUT , +CRLF_AUTO_CRLF +}; + +struct convert_driver ; + +struct conv_attrs { +struct convert_driver *drv; +enum convert_crlf_action attr_action;/* What attr says */ +enum convert_crlf_action crlf_action;/* When no attr is set, use core.autocrlf */ +int ident; +const char *working_tree_encoding;/* Supported encoding or default encoding if NULL */ +}; + +void convert_attrs (const struct index_state *istate, +struct conv_attrs *ca,const char *path); +extern enum eol core_eol;extern char *check_roundtrip_encoding; const char *get_cached_convert_stats_ascii(const struct index_state *istate,
Signature · 1 line
2.30.1
PATCH v6 2/9 convert: add [async_]convert_to_working_tree_ca() variants
In reply to Matheus TavaresFrom: Jeff Hostetler <[email protected]>
Separate the attribute gathering from the actual conversion by adding _ca() variants of the conversion functions. These variants receive a precomputed 'struct conv_attrs', not relying, thus, on an index state. They will be used in a future patch adding parallel checkout support, for two reasons:
- We will already load the conversion attributes in checkout_entry(), before conversion, to decide whether a path is eligible for parallel checkout. Therefore, it would be wasteful to load them again later, for the actual conversion.
- The parallel workers will be responsible for reading, converting and writing blobs to the working tree. They won't have access to the main process' index state, so they cannot load the attributes. Instead, they will receive the preloaded ones and call the _ca() variant of the conversion functions. Furthermore, the attributes machinery is optimized to handle paths in sequential order, so it's better to leave it for the main process, anyway.
--- convert.c | 60 +++++++++++++++++++++++++++++-------------------------- convert.h | 37 +++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 37 deletions(-)
convert.c +32 -28
@@ -1446,19 +1446,16 @@ void convert_to_git_filter_fd(const struct index_state *istate,ident_to_git (dst->buf, dst->len, dst, ca.ident); } -static int convert_to_working_tree_internal (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -int normalizing, -const struct checkout_metadata *meta, -struct delayed_checkout *dco) +static int convert_to_working_tree_ca_internal (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +int normalizing, +const struct checkout_metadata *meta, +struct delayed_checkout *dco) {int ret =0 , ret_filter =0 ; -struct conv_attrs ca; - -convert_attrs (istate, &ca, path); - ret |=ident_to_worktree (src, len, dst, ca.ident); + ret |=ident_to_worktree (src, len, dst, ca->ident);if (ret) { src = dst->buf; len = dst->len;
@@ -1468,49 +1465,56 @@ static int convert_to_working_tree_internal(const struct index_state *istate,* is a smudge or process filter (even if the process filter doesn't * support smudge). The filters might expect CRLFs. */ -if ((ca.drv && (ca.drv->smudge || ca.drv->process)) || !normalizing) { - ret |=crlf_to_worktree (src, len, dst, ca.crlf_action); +if ((ca->drv && (ca->drv->smudge || ca->drv->process)) || !normalizing) { + ret |=crlf_to_worktree (src, len, dst, ca->crlf_action);if (ret) { src = dst->buf; len = dst->len; } } - ret |=encode_to_worktree (path, src, len, dst, ca.working_tree_encoding); + ret |=encode_to_worktree (path, src, len, dst, ca->working_tree_encoding);if (ret) { src = dst->buf; len = dst->len; } ret_filter =apply_filter ( - path, src, len,-1 , dst, ca.drv,CAP_SMUDGE , meta, dco); -if (!ret_filter && ca.drv && ca.drv->required) -die (_ ("%s: smudge filter %s failed" ), path, ca.drv->name); + path, src, len,-1 , dst, ca->drv,CAP_SMUDGE , meta, dco); +if (!ret_filter && ca->drv && ca->drv->required) +die (_ ("%s: smudge filter %s failed" ), path, ca->drv->name);return ret | ret_filter; } -int async_convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta, -void *dco) +int async_convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta, +void *dco) { -return convert_to_working_tree_internal (istate, path, src, len, dst,0 , meta, dco); +return convert_to_working_tree_ca_internal (ca, path, src, len, dst,0 , + meta, dco); } -int convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta) +int convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta) { -return convert_to_working_tree_internal (istate, path, src, len, dst,0 , meta,NULL ); +return convert_to_working_tree_ca_internal (ca, path, src, len, dst,0 , + meta,NULL ); }int renormalize_buffer (const struct index_state *istate,const char *path,const char *src,size_t len,struct strbuf *dst) { -int ret =convert_to_working_tree_internal (istate, path, src, len, dst,1 ,NULL ,NULL ); +struct conv_attrs ca; +int ret; + +convert_attrs (istate, &ca, path); + ret =convert_to_working_tree_ca_internal (&ca, path, src, len, dst,1 , +NULL ,NULL );if (ret) { src = dst->buf; len = dst->len;
convert.h +28 -9
@@ -99,15 +99,34 @@ const char *get_convert_attr_ascii(const struct index_state *istate,int convert_to_git (const struct index_state *istate,const char *path,const char *src,size_t len,struct strbuf *dst,int conv_flags); -int convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta); -int async_convert_to_working_tree (const struct index_state *istate, -const char *path,const char *src, -size_t len,struct strbuf *dst, -const struct checkout_metadata *meta, -void *dco); +int convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta); +int async_convert_to_working_tree_ca (const struct conv_attrs *ca, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta, +void *dco); +static inline int convert_to_working_tree (const struct index_state *istate, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta) +{ +struct conv_attrs ca; +convert_attrs (istate, &ca, path); +return convert_to_working_tree_ca (&ca, path, src, len, dst, meta); +} +static inline int async_convert_to_working_tree (const struct index_state *istate, +const char *path,const char *src, +size_t len,struct strbuf *dst, +const struct checkout_metadata *meta, +void *dco) +{ +struct conv_attrs ca; +convert_attrs (istate, &ca, path); +return async_convert_to_working_tree_ca (&ca, path, src, len, dst, meta, dco); +}int async_query_available_blobs (const char *cmd,struct string_list *available_paths); int renormalize_buffer(const struct index_state *istate,
Signature · 1 line
2.30.1
PATCH v6 3/9 convert: add get_stream_filter_ca() variant
In reply to Matheus TavaresFrom: Jeff Hostetler <[email protected]>
Like the previous patch, we will also need to call get_stream_filter() with a precomputed struct conv_attrs, when we add support for parallel checkout workers. So add the _ca() variant which takes the conversion attributes struct as a parameter.
--- convert.c | 28 +++++++++++++++++----------- convert.h | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-)
convert.c +17 -11
@@ -1941,34 +1941,31 @@ static struct stream_filter *ident_filter(const struct object_id *oid) }/* -* Return an appropriately constructed filter for the path, or NULL if +* Return an appropriately constructed filter for the given ca, or NULL if * the contents cannot be filtered without reading the whole thing * in-core. * * Note that you would be crazy to set CRLF, smudge/clean or ident to a * large binary blob you would want us not to slurp into the memory! */ -struct stream_filter *get_stream_filter (const struct index_state *istate, -const char *path, -const struct object_id *oid) +struct stream_filter *get_stream_filter_ca (const struct conv_attrs *ca, +const struct object_id *oid) { -struct conv_attrs ca;struct stream_filter *filter =NULL ; -convert_attrs (istate, &ca, path); -if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean)) +if (ca->drv && (ca->drv->process || ca->drv->smudge || ca->drv->clean))return NULL ; -if (ca.working_tree_encoding) +if (ca->working_tree_encoding)return NULL ; -if (ca.crlf_action ==CRLF_AUTO || ca.crlf_action ==CRLF_AUTO_CRLF ) +if (ca->crlf_action ==CRLF_AUTO || ca->crlf_action ==CRLF_AUTO_CRLF )return NULL ; -if (ca.ident) +if (ca->ident) filter =ident_filter (oid); -if (output_eol (ca.crlf_action) ==EOL_CRLF ) +if (output_eol (ca->crlf_action) ==EOL_CRLF ) filter =cascade_filter (filter,lf_to_crlf_filter ());else filter =cascade_filter (filter, &null_filter_singleton);
@@ -1976,6 +1973,15 @@ struct stream_filter *get_stream_filter(const struct index_state *istate,return filter; } +struct stream_filter *get_stream_filter (const struct index_state *istate, +const char *path, +const struct object_id *oid) +{ +struct conv_attrs ca; +convert_attrs (istate, &ca, path); +return get_stream_filter_ca (&ca, oid); +} +void free_stream_filter (struct stream_filter *filter) { filter->vtbl->free (filter);
convert.h +2 -0
@@ -179,6 +179,8 @@ struct stream_filter; /* opaque */struct stream_filter *get_stream_filter (const struct index_state *istate,const char *path,const struct object_id *); +struct stream_filter *get_stream_filter_ca (const struct conv_attrs *ca, +const struct object_id *oid);void free_stream_filter (struct stream_filter *);int is_null_stream_filter (struct stream_filter *);
Signature · 1 line
2.30.1
PATCH v6 4/9 convert: add classification for conv_attrs struct
In reply to Matheus TavaresFrom: Jeff Hostetler <[email protected]>
Create enum conv_attrs_classification to express the different ways that attributes are handled for a blob during checkout.
This will be used in a later commit when deciding whether to add a file to the parallel or delayed queue during checkout. For now, we can also use it in get_stream_filter_ca() to simplify the function (as the classifying logic is the same).
--- convert.c | 26 +++++++++++++++++++------- convert.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-)
convert.c +19 -7
@@ -1953,13 +1953,7 @@ struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca, {struct stream_filter *filter =NULL ; -if (ca->drv && (ca->drv->process || ca->drv->smudge || ca->drv->clean)) -return NULL ; - -if (ca->working_tree_encoding) -return NULL ; - -if (ca->crlf_action ==CRLF_AUTO || ca->crlf_action ==CRLF_AUTO_CRLF ) +if (classify_conv_attrs (ca) !=CA_CLASS_STREAMABLE )return NULL ;if (ca->ident)
@@ -2015,3 +2009,21 @@ void clone_checkout_metadata(struct checkout_metadata *dst,if (blob)oidcpy (&dst->blob, blob); } + +enum conv_attrs_classification classify_conv_attrs (const struct conv_attrs *ca) +{ +if (ca->drv) { +if (ca->drv->process) +return CA_CLASS_INCORE_PROCESS ; +if (ca->drv->smudge || ca->drv->clean) +return CA_CLASS_INCORE_FILTER ; + } + +if (ca->working_tree_encoding) +return CA_CLASS_INCORE ; + +if (ca->crlf_action ==CRLF_AUTO || ca->crlf_action ==CRLF_AUTO_CRLF ) +return CA_CLASS_INCORE ; + +return CA_CLASS_STREAMABLE ; +}
convert.h +33 -0
@@ -200,4 +200,37 @@ int stream_filter(struct stream_filter *, const char *input, size_t *isize_p, char *output, size_t *osize_p); +enum conv_attrs_classification { +/* +* The blob must be loaded into a buffer before it can be +* smudged. All smudging is done in-proc. +*/ +CA_CLASS_INCORE , + +/* +* The blob must be loaded into a buffer, but uses a +* single-file driver filter, such as rot13. +*/ +CA_CLASS_INCORE_FILTER , + +/* +* The blob must be loaded into a buffer, but uses a +* long-running driver process, such as LFS. This might or +* might not use delayed operations. (The important thing is +* that there is a single subordinate long-running process +* handling all associated blobs and in case of delayed +* operations, may hold per-blob state.) +*/ +CA_CLASS_INCORE_PROCESS , + +/* +* The blob can be streamed and smudged without needing to +* completely read it into a buffer. +*/ +CA_CLASS_STREAMABLE , +}; + +enum conv_attrs_classification classify_conv_attrs ( +const struct conv_attrs *ca); +#endif /* CONVERT_H */
Signature · 1 line
2.30.1
PATCH v6 5/9 entry: extract a header file for entry.c functions
In reply to Matheus TavaresThe declarations of entry.c's public functions and structures currently reside in cache.h. Although not many, they contribute to the size of cache.h and, when changed, cause the unnecessary recompilation of modules that don't really use these functions. So let's move them to a new entry.h header. While at it let's also move a comment related to checkout_entry() from entry.c to entry.h as it's more useful to describe the function there.
--- apply.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/difftool.c | 1 + builtin/stash.c | 1 + cache.h | 24 ----------------------- entry.c | 9 +-------- entry.h | 42 ++++++++++++++++++++++++++++++++++++++++ unpack-trees.c | 1 + 9 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 entry.h
apply.c +1 -0
@@ -21,6 +21,7 @@#include "quote.h" #include "rerere.h" #include "apply.h" +#include "entry.h" struct gitdiff_data {struct strbuf *root;
builtin/checkout-index.c +1 -0
@@ -11,6 +11,7 @@#include "quote.h" #include "cache-tree.h" #include "parse-options.h" +#include "entry.h" #define CHECKOUT_ALL 4static int nul_term_line;
builtin/checkout.c +1 -0
@@ -26,6 +26,7 @@#include "unpack-trees.h" #include "wt-status.h" #include "xdiff-interface.h" +#include "entry.h" static const char *const checkout_usage[] = {N_ ("git checkout [<options>] <branch>" ),
builtin/difftool.c +1 -0
@@ -23,6 +23,7 @@#include "lockfile.h" #include "object-store.h" #include "dir.h" +#include "entry.h" static int trust_exit_code;
builtin/stash.c +1 -0
@@ -15,6 +15,7 @@#include "log-tree.h" #include "diffcore.h" #include "exec-cmd.h" +#include "entry.h" #define INCLUDE_ALL_FILES 2
cache.h +0 -24
@@ -1621,30 +1621,6 @@ const char *show_ident_date(const struct ident_split *id,*/ int ident_cmp (const struct ident_split *,const struct ident_split *); -struct checkout { -struct index_state *istate; -const char *base_dir; -int base_dir_len; -struct delayed_checkout *delayed_checkout; -struct checkout_metadata meta; -unsigned force:1 , - quiet:1 , - not_new:1 , - clone:1 , - refresh_cache:1 ; -}; -#define CHECKOUT_INIT { NULL, "" } - -#define TEMPORARY_FILENAME_LENGTH 25 -int checkout_entry (struct cache_entry *ce,const struct checkout *state,char *topath,int *nr_checkouts); -void enable_delayed_checkout (struct checkout *state); -int finish_delayed_checkout (struct checkout *state,int *nr_checkouts); -/* -* Unlink the last component and schedule the leading directories for -* removal, such that empty directories get removed. -*/ -void unlink_entry (const struct cache_entry *ce); -struct cache_def {struct strbuf path;int flags;
entry.c +1 -8
@@ -6,6 +6,7 @@#include "submodule.h" #include "progress.h" #include "fsmonitor.h" +#include "entry.h" static void create_directories (const char *path,int path_len,const struct checkout *state)
@@ -429,14 +430,6 @@ static void mark_colliding_entries(const struct checkout *state, } } -/* -* Write the contents from ce out to the working tree. -* -* When topath[] is not NULL, instead of writing to the working tree -* file named by ce, a temporary file is created by this function and -* its name is returned in topath[], which must be able to hold at -* least TEMPORARY_FILENAME_LENGTH bytes long. -*/ int checkout_entry (struct cache_entry *ce,const struct checkout *state,char *topath,int *nr_checkouts) {
entry.h new file +42 -0
42 lines not on this page · raw message
unpack-trees.c +1 -0
@@ -16,6 +16,7 @@#include "fsmonitor.h" #include "object-store.h" #include "promisor-remote.h" +#include "entry.h" /* * Error messages expected by scripts out of plumbing commands such as
Signature · 1 line
2.30.1
PATCH v6 6/9 entry: make fstat_output() and read_blob_entry() public
In reply to Matheus TavaresThese two functions will be used by the parallel checkout code, so let's make them public. Note: fstat_output() is renamed to fstat_checkout_output(), now that it has become public, seeking to avoid future name collisions.
--- entry.c | 8 ++++---- entry.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-)
entry.c +4 -4
@@ -84,7 +84,7 @@ static int create_file(const char *path, unsigned int mode)return open (path,O_WRONLY |O_CREAT |O_EXCL , mode); } -static void *read_blob_entry (const struct cache_entry *ce,unsigned long *size) +void *read_blob_entry (const struct cache_entry *ce,unsigned long *size) {enum object_type type;void *blob_data =read_object_file (&ce->oid, &type, size);
@@ -109,7 +109,7 @@ static int open_output_fd(char *path, const struct cache_entry *ce, int to_tempf } } -static int fstat_output (int fd,const struct checkout *state,struct stat *st) +int fstat_checkout_output (int fd,const struct checkout *state,struct stat *st) {/* use fstat() only when path == ce->name */ if (fstat_is_reliable() &&
@@ -132,7 +132,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path,return -1 ; result |=stream_blob_to_fd (fd, &ce->oid, filter,1 ); - *fstat_done =fstat_output (fd, state, statbuf); + *fstat_done =fstat_checkout_output (fd, state, statbuf); result |=close (fd);if (result)
@@ -346,7 +346,7 @@ static int write_entry(struct cache_entry *ce, wrote =write_in_full (fd, new_blob, size);if (!to_tempfile) - fstat_done =fstat_output (fd, state, &st); + fstat_done =fstat_checkout_output (fd, state, &st);close (fd);free (new_blob);if (wrote <0 )
entry.h +3 -0
@@ -39,4 +39,7 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);*/ void unlink_entry (const struct cache_entry *ce); +void *read_blob_entry (const struct cache_entry *ce,unsigned long *size); +int fstat_checkout_output (int fd,const struct checkout *state,struct stat *st); +#endif /* ENTRY_H */
Signature · 1 line
2.30.1
PATCH v6 7/9 entry: extract update_ce_after_write() from write_entry()
In reply to Matheus TavaresThe code that updates the in-memory index information after an entry is written currently resides in write_entry(). Extract it to a public function so that it can be called by the parallel checkout functions, outside entry.c, in a later patch.
--- entry.c | 25 ++++++++++++++++--------- entry.h | 2 ++ 2 files changed, 18 insertions(+), 9 deletions(-)
entry.c +16 -9
@@ -251,6 +251,18 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)return errs; } +void update_ce_after_write (const struct checkout *state,struct cache_entry *ce, +struct stat *st) +{ +if (state->refresh_cache) { +assert (state->istate); +fill_stat_cache_info (state->istate, ce, st); + ce->ce_flags |=CE_UPDATE_IN_BASE ; +mark_fsmonitor_invalid (state->istate, ce); + state->istate->cache_changed |=CE_ENTRY_CHANGED ; + } +} +static int write_entry (struct cache_entry *ce,char *path,const struct checkout *state,int to_tempfile) {
@@ -371,15 +383,10 @@ static int write_entry(struct cache_entry *ce, finish:if (state->refresh_cache) { -assert (state->istate); -if (!fstat_done) -if (lstat (ce->name, &st) <0 ) -return error_errno ("unable to stat just-written file %s" , - ce->name); -fill_stat_cache_info (state->istate, ce, &st); - ce->ce_flags |=CE_UPDATE_IN_BASE ; -mark_fsmonitor_invalid (state->istate, ce); - state->istate->cache_changed |=CE_ENTRY_CHANGED ; +if (!fstat_done &&lstat (ce->name, &st) <0 ) +return error_errno ("unable to stat just-written file %s" , + ce->name); +update_ce_after_write (state, ce , &st); } delayed:return 0 ;
entry.h +2 -0
@@ -41,5 +41,7 @@ void unlink_entry(const struct cache_entry *ce);void *read_blob_entry (const struct cache_entry *ce,unsigned long *size);int fstat_checkout_output (int fd,const struct checkout *state,struct stat *st); +void update_ce_after_write (const struct checkout *state,struct cache_entry *ce, +struct stat *st);#endif /* ENTRY_H */
Signature · 1 line
2.30.1
PATCH v6 8/9 entry: move conv_attrs lookup up to checkout_entry()
In reply to Matheus TavaresIn a following patch, checkout_entry() will use conv_attrs to decide whether an entry should be enqueued for parallel checkout or not. But the attributes lookup only happens lower in this call stack. To avoid the unnecessary work of loading the attributes twice, let's move it up to checkout_entry(), and pass the loaded struct down to write_entry().
--- entry.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
entry.c +27 -11
@@ -263,8 +263,9 @@ void update_ce_after_write(const struct checkout *state, struct cache_entry *ce, } } -static int write_entry (struct cache_entry *ce, -char *path,const struct checkout *state,int to_tempfile) +/* Note: ca is used (and required) iff the entry refers to a regular file. */ +static int write_entry (struct cache_entry *ce,char *path,struct conv_attrs *ca, +const struct checkout *state,int to_tempfile) {unsigned int ce_mode_s_ifmt = ce->ce_mode &S_IFMT ;struct delayed_checkout *dco = state->delayed_checkout;
@@ -281,8 +282,7 @@ static int write_entry(struct cache_entry *ce,clone_checkout_metadata (&meta, &state->meta, &ce->oid); if (ce_mode_s_ifmt == S_IFREG) { - struct stream_filter *filter = get_stream_filter(state->istate, ce->name, - &ce->oid); + struct stream_filter *filter = get_stream_filter_ca(ca, &ce->oid); if (filter && !streaming_write_entry(ce, path, filter, state, to_tempfile,
@@ -329,14 +329,17 @@ static int write_entry(struct cache_entry *ce,* Convert from git internal format to working tree format */ if (dco && dco->state !=CE_NO_DELAY ) { - ret =async_convert_to_working_tree (state->istate, ce->name, new_blob, - size, &buf, &meta, dco); + ret =async_convert_to_working_tree_ca (ca, ce->name, + new_blob, size, + &buf, &meta, dco);if (ret &&string_list_has_string (&dco->paths, ce->name)) {free (new_blob); goto delayed; } - }else - ret =convert_to_working_tree (state->istate, ce->name, new_blob, size, &buf, &meta); + }else { + ret =convert_to_working_tree_ca (ca, ce->name, new_blob, + size, &buf, &meta); + }if (ret) {free (new_blob);
@@ -442,6 +445,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, {static struct strbuf path =STRBUF_INIT ;struct stat st; +struct conv_attrs ca_buf, *ca =NULL ;if (ce->ce_flags &CE_WT_REMOVE ) {if (topath)
@@ -454,8 +458,13 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,return 0 ; } -if (topath) -return write_entry (ce, topath, state,1 ); +if (topath) { +if (S_ISREG (ce->ce_mode)) { +convert_attrs (state->istate, &ca_buf, ce->name); + ca = &ca_buf; + } +return write_entry (ce, topath, ca, state,1 ); + }strbuf_reset (&path);strbuf_add (&path, state->base_dir, state->base_dir_len);
@@ -517,9 +526,16 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,return 0 ;create_directories (path.buf, path.len, state); +if (nr_checkouts) (*nr_checkouts)++; -return write_entry (ce, path.buf, state,0 ); + +if (S_ISREG (ce->ce_mode)) { +convert_attrs (state->istate, &ca_buf, ce->name); + ca = &ca_buf; + } + +return write_entry (ce, path.buf, ca, state,0 ); }void unlink_entry (const struct cache_entry *ce)
Signature · 1 line
2.30.1
PATCH v6 9/9 entry: add checkout_entry_ca() taking preloaded conv_attrs
In reply to Matheus TavaresThe parallel checkout machinery will call checkout_entry() for entries that could not be written in parallel due to path collisions. At this point, we will already be holding the conversion attributes for each entry, and it would be wasteful to let checkout_entry() load these again. Instead, let's add the checkout_entry_ca() variant, which optionally takes a preloaded conv_attrs struct.
--- entry.c | 11 ++++++----- entry.h | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-)
entry.c +6 -5
@@ -440,12 +440,13 @@ static void mark_colliding_entries(const struct checkout *state, } } -int checkout_entry (struct cache_entry *ce,const struct checkout *state, -char *topath,int *nr_checkouts) +int checkout_entry_ca (struct cache_entry *ce,struct conv_attrs *ca, +const struct checkout *state,char *topath, +int *nr_checkouts) {static struct strbuf path =STRBUF_INIT ;struct stat st; -struct conv_attrs ca_buf, *ca =NULL ; +struct conv_attrs ca_buf;if (ce->ce_flags &CE_WT_REMOVE ) {if (topath)
@@ -459,7 +460,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, }if (topath) { -if (S_ISREG (ce->ce_mode)) { +if (S_ISREG (ce->ce_mode) && !ca) {convert_attrs (state->istate, &ca_buf, ce->name); ca = &ca_buf; }
@@ -530,7 +531,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state,if (nr_checkouts) (*nr_checkouts)++; -if (S_ISREG (ce->ce_mode)) { +if (S_ISREG (ce->ce_mode) && !ca) {convert_attrs (state->istate, &ca_buf, ce->name); ca = &ca_buf; }
entry.h +14 -2
@@ -26,9 +26,21 @@ struct checkout {* file named by ce, a temporary file is created by this function and * its name is returned in topath[], which must be able to hold at * least TEMPORARY_FILENAME_LENGTH bytes long. +* +* With checkout_entry_ca(), callers can optionally pass a preloaded +* conv_attrs struct (to avoid reloading it), when ce refers to a +* regular file. If ca is NULL, the attributes will be loaded +* internally when (and if) needed. */ -int checkout_entry (struct cache_entry *ce,const struct checkout *state, -char *topath,int *nr_checkouts); +int checkout_entry_ca (struct cache_entry *ce,struct conv_attrs *ca, +const struct checkout *state,char *topath, +int *nr_checkouts); +static inline int checkout_entry (struct cache_entry *ce, +const struct checkout *state,char *topath, +int *nr_checkouts) +{ +return checkout_entry_ca (ce,NULL , state, topath, nr_checkouts); +}void enable_delayed_checkout (struct checkout *state);int finish_delayed_checkout (struct checkout *state,int *nr_checkouts);
Signature · 1 line
2.30.1
Re: [PATCH v6 0/9] Parallel Checkout (part 1)
In reply to Matheus TavaresQuoted 4 lines · Matheus Tavares
Preparatory API changes for parallel checkout. This version was rebased on top of 'master'. The only change required in this change of base was the
entry.hinclusion onbuiltin/stash.c, at the commit that creates this header file.
Thanks. I think you had part-2 that depended on this one, so if I have a(n old) copy I'll rebase them on this round myself.
Quoted 5 lines · Matheus Tavares
This series adds parallel workers to the checkout machinery. The cache entries are distributed among helper processes which are responsible for reading, filtering and writing the blobs to the working tree. This should benefit all commands that call
unpack_trees()orcheck_updates(), such as: checkout, clone, sparse-checkout, checkout-index, etc.
This series looks very good!
Thanks for your attention to detail.
Jeff