Skip to content

Commit 1c4d6f4

Browse files
matheustavaresgitster
authored andcommitted
parallel-checkout: support progress displaying
Original-patch-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7531e4b commit 1c4d6f4

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

parallel-checkout.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "entry.h"
44
#include "parallel-checkout.h"
55
#include "pkt-line.h"
6+
#include "progress.h"
67
#include "run-command.h"
78
#include "sigchain.h"
89
#include "streaming.h"
@@ -17,6 +18,8 @@ struct parallel_checkout {
1718
enum pc_status status;
1819
struct parallel_checkout_item *items; /* The parallel checkout queue. */
1920
size_t nr, alloc;
21+
struct progress *progress;
22+
unsigned int *progress_cnt;
2023
};
2124

2225
static struct parallel_checkout parallel_checkout;
@@ -146,6 +149,20 @@ int enqueue_checkout(struct cache_entry *ce, struct conv_attrs *ca)
146149
return 0;
147150
}
148151

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+
149166
static int handle_results(struct checkout *state)
150167
{
151168
int ret = 0;
@@ -194,6 +211,7 @@ static int handle_results(struct checkout *state)
194211
*/
195212
ret |= checkout_entry_ca(pc_item->ce, &pc_item->ca,
196213
state, NULL, NULL);
214+
advance_progress_meter();
197215
break;
198216
case PC_ITEM_PENDING:
199217
have_pending = 1;
@@ -534,6 +552,9 @@ static void parse_and_save_result(const char *buffer, int len,
534552
pc_item->status = res->status;
535553
if (st)
536554
pc_item->st = *st;
555+
556+
if (res->status != PC_ITEM_COLLIDED)
557+
advance_progress_meter();
537558
}
538559

539560
static void gather_results_from_workers(struct pc_worker *workers,
@@ -596,18 +617,25 @@ static void write_items_sequentially(struct checkout *state)
596617
{
597618
size_t i;
598619

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+
}
601626
}
602627

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)
604630
{
605631
int ret;
606632

607633
if (parallel_checkout.status != PC_ACCEPTING_ENTRIES)
608634
BUG("cannot run parallel checkout: uninitialized or already running");
609635

610636
parallel_checkout.status = PC_RUNNING;
637+
parallel_checkout.progress = progress;
638+
parallel_checkout.progress_cnt = progress_cnt;
611639

612640
if (parallel_checkout.nr < num_workers)
613641
num_workers = parallel_checkout.nr;

parallel-checkout.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
struct cache_entry;
77
struct checkout;
8+
struct progress;
89

910
/****************************************************************
1011
* Users of parallel checkout
@@ -31,13 +32,15 @@ void init_parallel_checkout(void);
3132
* for later write and return 0.
3233
*/
3334
int enqueue_checkout(struct cache_entry *ce, struct conv_attrs *ca);
35+
size_t pc_queue_size(void);
3436

3537
/*
3638
* Write all the queued entries, returning 0 on success. If the number of
3739
* entries is smaller than the specified threshold, the operation is performed
3840
* sequentially.
3941
*/
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);
4144

4245
/****************************************************************
4346
* Interface with checkout--worker

unpack-trees.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,17 +474,22 @@ static int check_updates(struct unpack_trees_options *o,
474474
struct cache_entry *ce = index->cache[i];
475475

476476
if (ce->ce_flags & CE_UPDATE) {
477+
size_t last_pc_queue_size = pc_queue_size();
478+
477479
if (ce->ce_flags & CE_WT_REMOVE)
478480
BUG("both update and delete flags are set on %s",
479481
ce->name);
480-
display_progress(progress, ++cnt);
481482
ce->ce_flags &= ~CE_UPDATE;
482483
errs |= checkout_entry(ce, &state, NULL, NULL);
484+
485+
if (last_pc_queue_size == pc_queue_size())
486+
display_progress(progress, ++cnt);
483487
}
484488
}
485-
stop_progress(&progress);
486489
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);
488493
errs |= finish_delayed_checkout(&state, NULL);
489494
git_attr_set_direction(GIT_ATTR_CHECKIN);
490495

0 commit comments

Comments
 (0)