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>
This commit is contained in:
committed by
Junio C Hamano
parent
7531e4b66e
commit
1c4d6f46be
@@ -3,6 +3,7 @@
|
||||
#include "entry.h"
|
||||
#include "parallel-checkout.h"
|
||||
#include "pkt-line.h"
|
||||
#include "progress.h"
|
||||
#include "run-command.h"
|
||||
#include "sigchain.h"
|
||||
#include "streaming.h"
|
||||
@@ -17,6 +18,8 @@ struct parallel_checkout {
|
||||
enum pc_status status;
|
||||
struct parallel_checkout_item *items; /* The parallel checkout queue. */
|
||||
size_t nr, alloc;
|
||||
struct progress *progress;
|
||||
unsigned int *progress_cnt;
|
||||
};
|
||||
|
||||
static struct parallel_checkout parallel_checkout;
|
||||
@@ -146,6 +149,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;
|
||||
@@ -194,6 +211,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;
|
||||
@@ -534,6 +552,9 @@ static void parse_and_save_result(const char *buffer, int len,
|
||||
pc_item->status = res->status;
|
||||
if (st)
|
||||
pc_item->st = *st;
|
||||
|
||||
if (res->status != PC_ITEM_COLLIDED)
|
||||
advance_progress_meter();
|
||||
}
|
||||
|
||||
static void gather_results_from_workers(struct pc_worker *workers,
|
||||
@@ -596,11 +617,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;
|
||||
|
||||
@@ -608,6 +634,8 @@ int run_parallel_checkout(struct checkout *state, int num_workers, int threshold
|
||||
BUG("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;
|
||||
|
||||
Reference in New Issue
Block a user