progress: fix progress meters when dealing with lots of work

The possibility of setting merge.renameLimit beyond 2^16 raises the possibility that the values passed to progress can exceed 2^32. Use uint64_t, because it "ought to be enough for anybody". :-) Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Nov 13, 2017 at 12:15 UTC d6861d0258df95987696eab6c9bbc138a07190b9
3 files changed +21 -20
diffcore-rename.c
+2 -2
@@ -534,7 +534,7 @@ void diffcore_rename(struct diff_options *options)
534 if (options->show_rename_progress) {
535 progress = start_delayed_progress(
536 _("Performing inexact rename detection"),
537 - rename_dst_nr * rename_src_nr);
537 + (uint64_t)rename_dst_nr * (uint64_t)rename_src_nr);
538 }
539
540 mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_create), sizeof(*mx));
@@ -571,7 +571,7 @@ void diffcore_rename(struct diff_options *options)
571 diff_free_filespec_blob(two);
572 }
573 dst_cnt++;
574 - display_progress(progress, (i+1)*rename_src_nr);
574 + display_progress(progress, (uint64_t)(i+1)*(uint64_t)rename_src_nr);
575 }
576 stop_progress(&progress);
577
progress.c
+15 -14
@@ -30,8 +30,8 @@ struct throughput {
30
31 struct progress {
32 const char *title;
33 - int last_value;
34 - unsigned total;
33 + uint64_t last_value;
34 + uint64_t total;
35 unsigned last_percent;
36 unsigned delay;
37 unsigned delayed_percent_threshold;
@@ -79,7 +79,7 @@ static int is_foreground_fd(int fd)
79 return tpgrp < 0 || tpgrp == getpgid(0);
80 }
81
82 -static int display(struct progress *progress, unsigned n, const char *done)
82 +static int display(struct progress *progress, uint64_t n, const char *done)
83 {
84 const char *eol, *tp;
85
@@ -106,9 +106,10 @@ static int display(struct progress *progress, unsigned n, const char *done)
106 if (percent != progress->last_percent || progress_update) {
107 progress->last_percent = percent;
108 if (is_foreground_fd(fileno(stderr)) || done) {
109 - fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
110 - progress->title, percent, n,
111 - progress->total, tp, eol);
109 + fprintf(stderr, "%s: %3u%% (%"PRIuMAX"/%"PRIuMAX")%s%s",
110 + progress->title, percent,
111 + (uintmax_t)n, (uintmax_t)progress->total,
112 + tp, eol);
113 fflush(stderr);
114 }
115 progress_update = 0;
@@ -116,8 +117,8 @@ static int display(struct progress *progress, unsigned n, const char *done)
117 }
118 } else if (progress_update) {
119 if (is_foreground_fd(fileno(stderr)) || done) {
119 - fprintf(stderr, "%s: %u%s%s",
120 - progress->title, n, tp, eol);
120 + fprintf(stderr, "%s: %"PRIuMAX"%s%s",
121 + progress->title, (uintmax_t)n, tp, eol);
122 fflush(stderr);
123 }
124 progress_update = 0;
@@ -127,7 +128,7 @@ static int display(struct progress *progress, unsigned n, const char *done)
128 return 0;
129 }
130
130 -static void throughput_string(struct strbuf *buf, off_t total,
131 +static void throughput_string(struct strbuf *buf, uint64_t total,
132 unsigned int rate)
133 {
134 strbuf_reset(buf);
@@ -138,7 +139,7 @@ static void throughput_string(struct strbuf *buf, off_t total,
139 strbuf_addstr(buf, "/s");
140 }
141
141 -void display_throughput(struct progress *progress, off_t total)
142 +void display_throughput(struct progress *progress, uint64_t total)
143 {
144 struct throughput *tp;
145 uint64_t now_ns;
@@ -200,12 +201,12 @@ void display_throughput(struct progress *progress, off_t total)
201 display(progress, progress->last_value, NULL);
202 }
203
203 -int display_progress(struct progress *progress, unsigned n)
204 +int display_progress(struct progress *progress, uint64_t n)
205 {
206 return progress ? display(progress, n, NULL) : 0;
207 }
208
208 -static struct progress *start_progress_delay(const char *title, unsigned total,
209 +static struct progress *start_progress_delay(const char *title, uint64_t total,
210 unsigned percent_threshold, unsigned delay)
211 {
212 struct progress *progress = malloc(sizeof(*progress));
@@ -227,12 +228,12 @@ static struct progress *start_progress_delay(const char *title, unsigned total,
228 return progress;
229 }
230
230 -struct progress *start_delayed_progress(const char *title, unsigned total)
231 +struct progress *start_delayed_progress(const char *title, uint64_t total)
232 {
233 return start_progress_delay(title, total, 0, 2);
234 }
235
235 -struct progress *start_progress(const char *title, unsigned total)
236 +struct progress *start_progress(const char *title, uint64_t total)
237 {
238 return start_progress_delay(title, total, 0, 0);
239 }
progress.h
+4 -4
@@ -3,10 +3,10 @@
3
4 struct progress;
5
6 -void display_throughput(struct progress *progress, off_t total);
7 -int display_progress(struct progress *progress, unsigned n);
8 -struct progress *start_progress(const char *title, unsigned total);
9 -struct progress *start_delayed_progress(const char *title, unsigned total);
6 +void display_throughput(struct progress *progress, uint64_t total);
7 +int display_progress(struct progress *progress, uint64_t n);
8 +struct progress *start_progress(const char *title, uint64_t total);
9 +struct progress *start_delayed_progress(const char *title, uint64_t total);
10 void stop_progress(struct progress **progress);
11 void stop_progress_msg(struct progress **progress, const char *msg);
12