diff options
Diffstat (limited to 'progress.c')
-rw-r--r-- | progress.c | 82 |
1 files changed, 44 insertions, 38 deletions
@@ -9,13 +9,15 @@ */ #define GIT_TEST_PROGRESS_ONLY -#include "cache.h" -#include "gettext.h" +#include "git-compat-util.h" +#include "pager.h" #include "progress.h" +#include "repository.h" #include "strbuf.h" #include "trace.h" +#include "trace2.h" #include "utf8.h" -#include "config.h" +#include "parse.h" #define TP_IDX_MAX 8 @@ -59,7 +61,7 @@ void progress_test_force_update(void) } -static void progress_interval(int signum) +static void progress_interval(int signum UNUSED) { progress_update = 1; } @@ -196,7 +198,7 @@ void display_throughput(struct progress *progress, uint64_t total) now_ns = progress_getnanotime(progress); if (!tp) { - progress->throughput = tp = xcalloc(1, sizeof(*tp)); + progress->throughput = CALLOC_ARRAY(tp, 1); tp->prev_total = tp->curr_total = total; tp->prev_ns = now_ns; strbuf_init(&tp->display, 0); @@ -311,54 +313,58 @@ struct progress *start_delayed_sparse_progress(const char *title, static void finish_if_sparse(struct progress *progress) { - if (progress && - progress->sparse && + if (progress->sparse && progress->last_value != progress->total) display_progress(progress, progress->total); } -void stop_progress(struct progress **p_progress) +static void force_last_update(struct progress *progress, const char *msg) { - finish_if_sparse(*p_progress); - - if (p_progress && *p_progress) { - trace2_data_intmax("progress", the_repository, "total_objects", - (*p_progress)->total); + char *buf; + struct throughput *tp = progress->throughput; + + if (tp) { + uint64_t now_ns = progress_getnanotime(progress); + unsigned int misecs, rate; + misecs = ((now_ns - progress->start_ns) * 4398) >> 32; + rate = tp->curr_total / (misecs ? misecs : 1); + throughput_string(&tp->display, tp->curr_total, rate); + } + progress_update = 1; + buf = xstrfmt(", %s.\n", msg); + display(progress, progress->last_value, buf); + free(buf); +} - if ((*p_progress)->throughput) - trace2_data_intmax("progress", the_repository, - "total_bytes", - (*p_progress)->throughput->curr_total); +static void log_trace2(struct progress *progress) +{ + trace2_data_intmax("progress", the_repository, "total_objects", + progress->total); - trace2_region_leave("progress", (*p_progress)->title, the_repository); - } + if (progress->throughput) + trace2_data_intmax("progress", the_repository, "total_bytes", + progress->throughput->curr_total); - stop_progress_msg(p_progress, _("done")); + trace2_region_leave("progress", progress->title, the_repository); } void stop_progress_msg(struct progress **p_progress, const char *msg) { - struct progress *progress = *p_progress; + struct progress *progress; + + if (!p_progress) + BUG("don't provide NULL to stop_progress_msg"); + + progress = *p_progress; if (!progress) return; *p_progress = NULL; - if (progress->last_value != -1) { - /* Force the last update */ - char *buf; - struct throughput *tp = progress->throughput; - - if (tp) { - uint64_t now_ns = progress_getnanotime(progress); - unsigned int misecs, rate; - misecs = ((now_ns - progress->start_ns) * 4398) >> 32; - rate = tp->curr_total / (misecs ? misecs : 1); - throughput_string(&tp->display, tp->curr_total, rate); - } - progress_update = 1; - buf = xstrfmt(", %s.\n", msg); - display(progress, progress->last_value, buf); - free(buf); - } + + finish_if_sparse(progress); + if (progress->last_value != -1) + force_last_update(progress, msg); + log_trace2(progress); + clear_progress_signal(); strbuf_release(&progress->counters_sb); if (progress->throughput) |