diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-02-25 15:47:35 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-02-25 15:47:35 -0800 |
| commit | a47fcfe8712e3258d1c565cd654c9bd5312a5168 (patch) | |
| tree | 4c724f397e890c6b233d253be279321505e2a3a4 /progress.c | |
| parent | Merge branch 'ds/sparse-checkout-requires-per-worktree-config' (diff) | |
| parent | pack-bitmap-write.c: don't return without stop_progress() (diff) | |
| download | git-a47fcfe8712e3258d1c565cd654c9bd5312a5168.tar.gz git-a47fcfe8712e3258d1c565cd654c9bd5312a5168.zip | |
Merge branch 'ab/only-single-progress-at-once'
Further tweaks on progress API.
* ab/only-single-progress-at-once:
pack-bitmap-write.c: don't return without stop_progress()
progress API: unify stop_progress{,_msg}(), fix trace2 bug
progress.c: refactor stop_progress{,_msg}() to use helpers
progress.c: use dereferenced "progress" variable, not "(*p_progress)"
progress.h: format and be consistent with progress.c naming
progress.c tests: test some invalid usage
progress.c tests: make start/stop commands on stdin
progress.c test helper: add missing braces
leak tests: fix a memory leak in "test-progress" helper
Diffstat (limited to 'progress.c')
| -rw-r--r-- | progress.c | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/progress.c b/progress.c index 680c6a8bf9..0cdd875d37 100644 --- a/progress.c +++ b/progress.c @@ -311,32 +311,39 @@ 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) { - if (!p_progress) - BUG("don't provide NULL to stop_progress"); - - finish_if_sparse(*p_progress); - - if (*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) @@ -350,23 +357,12 @@ void stop_progress_msg(struct progress **p_progress, const char *msg) 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) |
