diff --git a/progress.c b/progress.c
index 3971f49..92fc3c5 100644
--- a/progress.c
+++ b/progress.c
@@ -103,7 +103,10 @@ static int display(struct progress *progress, unsigned n, const char *done)
return 1;
}
} else if (progress_update) {
- fprintf(stderr, "%s: %u%s%s", progress->title, n, tp, eol);
+ fprintf(stderr, "%s: ", progress->title);
+ if (n)
+ fprintf(stderr, "%u", n);
+ fprintf(stderr, "%s%s", tp, eol);
fflush(stderr);
progress_update = 0;
return 1;@@ -113,23 +116,24 @@ static int display(struct progress *progress, unsigned n, const char *done)
}
static void throughput_string(struct throughput *tp, off_t total,
- unsigned int rate)
+ unsigned int rate, struct progress *p)
{
+ const char *delim = p->total || p->last_value > 0 ? ", " : "";
int l = sizeof(tp->display);
if (total > 1 << 30) {
- l -= snprintf(tp->display, l, ", %u.%2.2u GiB",
+ l -= snprintf(tp->display, l, "%s%u.%2.2u GiB", delim,
(int)(total >> 30),
(int)(total & ((1 << 30) - 1)) / 10737419);
} else if (total > 1 << 20) {
int x = total + 5243; /* for rounding */
- l -= snprintf(tp->display, l, ", %u.%2.2u MiB",
+ l -= snprintf(tp->display, l, "%s%u.%2.2u MiB", delim,
x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
} else if (total > 1 << 10) {
int x = total + 5; /* for rounding */
- l -= snprintf(tp->display, l, ", %u.%2.2u KiB",
+ l -= snprintf(tp->display, l, "%s%u.%2.2u KiB", delim,
x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
} else {
- l -= snprintf(tp->display, l, ", %u bytes", (int)total);
+ l -= snprintf(tp->display, l, "%s%u bytes", delim, (int)total);
}
if (rate > 1 << 10) {@@ -197,7 +201,7 @@ void display_throughput(struct progress *progress, off_t total)
tp->last_misecs[tp->idx] = misecs;
tp->idx = (tp->idx + 1) % TP_IDX_MAX;
- throughput_string(tp, total, rate);
+ throughput_string(tp, total, rate, progress);
if (progress->last_value != -1 && progress_update)
display(progress, progress->last_value, NULL);
}
@@ -255,7 +259,7 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
if (tp) {
unsigned int rate = !tp->avg_misecs ? 0 :
tp->avg_bytes / tp->avg_misecs;
- throughput_string(tp, tp->curr_total, rate);
+ throughput_string(tp, tp->curr_total, rate, progress);
}
progress_update = 1;
sprintf(bufp, ", %s.\n", msg);--
1.7.7.2.7.g9f96f