25
unsigned int last_bytes[TP_IDX_MAX];
26
unsigned int last_misecs[TP_IDX_MAX];
27
unsigned int idx;
28
- char display[32];
28
+ struct strbuf display;
29
};
30
31
struct progress {
98
}
99
100
progress->last_value = n;
101
- tp = (progress->throughput) ? progress->throughput->display : "";
101
+ tp = (progress->throughput) ? progress->throughput->display.buf : "";
102
eol = done ? done : " \r";
103
if (progress->total) {
104
unsigned percent = n * 100 / progress->total;
129
static void throughput_string(struct strbuf *buf, off_t total,
130
unsigned int rate)
131
{
132
+ strbuf_reset(buf);
133
strbuf_addstr(buf, ", ");
134
strbuf_humanise_bytes(buf, total);
135
strbuf_addstr(buf, " | ");
142
struct throughput *tp;
143
uint64_t now_ns;
144
unsigned int misecs, count, rate;
144
- struct strbuf buf = STRBUF_INIT;
145
146
if (!progress)
147
return;
154
if (tp) {
155
tp->prev_total = tp->curr_total = total;
156
tp->prev_ns = now_ns;
157
+ strbuf_init(&tp->display, 0);
158
}
159
return;
160
}
194
tp->last_misecs[tp->idx] = misecs;
195
tp->idx = (tp->idx + 1) % TP_IDX_MAX;
196
196
- throughput_string(&buf, total, rate);
197
- strncpy(tp->display, buf.buf, sizeof(tp->display));
198
- strbuf_release(&buf);
197
+ throughput_string(&tp->display, total, rate);
198
if (progress->last_value != -1 && progress_update)
199
display(progress, progress->last_value, NULL);
200
}
249
250
bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
251
if (tp) {
253
- struct strbuf strbuf = STRBUF_INIT;
252
unsigned int rate = !tp->avg_misecs ? 0 :
253
tp->avg_bytes / tp->avg_misecs;
256
- throughput_string(&strbuf, tp->curr_total, rate);
257
- strncpy(tp->display, strbuf.buf, sizeof(tp->display));
258
- strbuf_release(&strbuf);
254
+ throughput_string(&tp->display, tp->curr_total, rate);
255
}
256
progress_update = 1;
257
sprintf(bufp, ", %s.\n", msg);
260
free(bufp);
261
}
262
clear_progress_signal();
263
+ if (progress->throughput)
264
+ strbuf_release(&progress->throughput->display);
265
free(progress->throughput);
266
free(progress);
267
}