parallel-checkout: support progress displaying

Original-patch-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matheus Tavares committed Apr 18, 2021 at 21:14 UTC 1c4d6f46be8dc05c9a49379587ffd454e92b72cf
3 files changed +43 -7
parallel-checkout.c
+31 -3
@@ -3,6 +3,7 @@
3 #include "entry.h"
4 #include "parallel-checkout.h"
5 #include "pkt-line.h"
6 +#include "progress.h"
7 #include "run-command.h"
8 #include "sigchain.h"
9 #include "streaming.h"
@@ -17,6 +18,8 @@ struct parallel_checkout {
18 enum pc_status status;
19 struct parallel_checkout_item *items; /* The parallel checkout queue. */
20 size_t nr, alloc;
21 + struct progress *progress;
22 + unsigned int *progress_cnt;
23 };
24
25 static struct parallel_checkout parallel_checkout;
@@ -146,6 +149,20 @@ int enqueue_checkout(struct cache_entry *ce, struct conv_attrs *ca)
149 return 0;
150 }
151
152 +size_t pc_queue_size(void)
153 +{
154 + return parallel_checkout.nr;
155 +}
156 +
157 +static void advance_progress_meter(void)
158 +{
159 + if (parallel_checkout.progress) {
160 + (*parallel_checkout.progress_cnt)++;
161 + display_progress(parallel_checkout.progress,
162 + *parallel_checkout.progress_cnt);
163 + }
164 +}
165 +
166 static int handle_results(struct checkout *state)
167 {
168 int ret = 0;
@@ -194,6 +211,7 @@ static int handle_results(struct checkout *state)
211 */
212 ret |= checkout_entry_ca(pc_item->ce, &pc_item->ca,
213 state, NULL, NULL);
214 + advance_progress_meter();
215 break;
216 case PC_ITEM_PENDING:
217 have_pending = 1;
@@ -534,6 +552,9 @@ static void parse_and_save_result(const char *buffer, int len,
552 pc_item->status = res->status;
553 if (st)
554 pc_item->st = *st;
555 +
556 + if (res->status != PC_ITEM_COLLIDED)
557 + advance_progress_meter();
558 }
559
560 static void gather_results_from_workers(struct pc_worker *workers,
@@ -596,11 +617,16 @@ static void write_items_sequentially(struct checkout *state)
617 {
618 size_t i;
619
599 - for (i = 0; i < parallel_checkout.nr; i++)
600 - write_pc_item(&parallel_checkout.items[i], state);
620 + for (i = 0; i < parallel_checkout.nr; i++) {
621 + struct parallel_checkout_item *pc_item = &parallel_checkout.items[i];
622 + write_pc_item(pc_item, state);
623 + if (pc_item->status != PC_ITEM_COLLIDED)
624 + advance_progress_meter();
625 + }
626 }
627
603 -int run_parallel_checkout(struct checkout *state, int num_workers, int threshold)
628 +int run_parallel_checkout(struct checkout *state, int num_workers, int threshold,
629 + struct progress *progress, unsigned int *progress_cnt)
630 {
631 int ret;
632
@@ -608,6 +634,8 @@ int run_parallel_checkout(struct checkout *state, int num_workers, int threshold
634 BUG("cannot run parallel checkout: uninitialized or already running");
635
636 parallel_checkout.status = PC_RUNNING;
637 + parallel_checkout.progress = progress;
638 + parallel_checkout.progress_cnt = progress_cnt;
639
640 if (parallel_checkout.nr < num_workers)
641 num_workers = parallel_checkout.nr;
parallel-checkout.h
+4 -1
@@ -5,6 +5,7 @@
5
6 struct cache_entry;
7 struct checkout;
8 +struct progress;
9
10 /****************************************************************
11 * Users of parallel checkout
@@ -31,13 +32,15 @@ void init_parallel_checkout(void);
32 * for later write and return 0.
33 */
34 int enqueue_checkout(struct cache_entry *ce, struct conv_attrs *ca);
35 +size_t pc_queue_size(void);
36
37 /*
38 * Write all the queued entries, returning 0 on success. If the number of
39 * entries is smaller than the specified threshold, the operation is performed
40 * sequentially.
41 */
40 -int run_parallel_checkout(struct checkout *state, int num_workers, int threshold);
42 +int run_parallel_checkout(struct checkout *state, int num_workers, int threshold,
43 + struct progress *progress, unsigned int *progress_cnt);
44
45 /****************************************************************
46 * Interface with checkout--worker
unpack-trees.c
+8 -3
@@ -474,17 +474,22 @@ static int check_updates(struct unpack_trees_options *o,
474 struct cache_entry *ce = index->cache[i];
475
476 if (ce->ce_flags & CE_UPDATE) {
477 + size_t last_pc_queue_size = pc_queue_size();
478 +
479 if (ce->ce_flags & CE_WT_REMOVE)
480 BUG("both update and delete flags are set on %s",
481 ce->name);
480 - display_progress(progress, ++cnt);
482 ce->ce_flags &= ~CE_UPDATE;
483 errs |= checkout_entry(ce, &state, NULL, NULL);
484 +
485 + if (last_pc_queue_size == pc_queue_size())
486 + display_progress(progress, ++cnt);
487 }
488 }
485 - stop_progress(&progress);
489 if (pc_workers > 1)
487 - errs |= run_parallel_checkout(&state, pc_workers, pc_threshold);
490 + errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
491 + progress, &cnt);
492 + stop_progress(&progress);
493 errs |= finish_delayed_checkout(&state, NULL);
494 git_attr_set_direction(GIT_ATTR_CHECKIN);
495