Skip to content

Commit d6861d0

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b520abf commit d6861d0

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

diffcore-rename.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ void diffcore_rename(struct diff_options *options)
534534
if (options->show_rename_progress) {
535535
progress = start_delayed_progress(
536536
_("Performing inexact rename detection"),
537-
rename_dst_nr * rename_src_nr);
537+
(uint64_t)rename_dst_nr * (uint64_t)rename_src_nr);
538538
}
539539

540540
mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_create), sizeof(*mx));
@@ -571,7 +571,7 @@ void diffcore_rename(struct diff_options *options)
571571
diff_free_filespec_blob(two);
572572
}
573573
dst_cnt++;
574-
display_progress(progress, (i+1)*rename_src_nr);
574+
display_progress(progress, (uint64_t)(i+1)*(uint64_t)rename_src_nr);
575575
}
576576
stop_progress(&progress);
577577

progress.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ struct throughput {
3030

3131
struct progress {
3232
const char *title;
33-
int last_value;
34-
unsigned total;
33+
uint64_t last_value;
34+
uint64_t total;
3535
unsigned last_percent;
3636
unsigned delay;
3737
unsigned delayed_percent_threshold;
@@ -79,7 +79,7 @@ static int is_foreground_fd(int fd)
7979
return tpgrp < 0 || tpgrp == getpgid(0);
8080
}
8181

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)
8383
{
8484
const char *eol, *tp;
8585

@@ -106,18 +106,19 @@ static int display(struct progress *progress, unsigned n, const char *done)
106106
if (percent != progress->last_percent || progress_update) {
107107
progress->last_percent = percent;
108108
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);
112113
fflush(stderr);
113114
}
114115
progress_update = 0;
115116
return 1;
116117
}
117118
} else if (progress_update) {
118119
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);
121122
fflush(stderr);
122123
}
123124
progress_update = 0;
@@ -127,7 +128,7 @@ static int display(struct progress *progress, unsigned n, const char *done)
127128
return 0;
128129
}
129130

130-
static void throughput_string(struct strbuf *buf, off_t total,
131+
static void throughput_string(struct strbuf *buf, uint64_t total,
131132
unsigned int rate)
132133
{
133134
strbuf_reset(buf);
@@ -138,7 +139,7 @@ static void throughput_string(struct strbuf *buf, off_t total,
138139
strbuf_addstr(buf, "/s");
139140
}
140141

141-
void display_throughput(struct progress *progress, off_t total)
142+
void display_throughput(struct progress *progress, uint64_t total)
142143
{
143144
struct throughput *tp;
144145
uint64_t now_ns;
@@ -200,12 +201,12 @@ void display_throughput(struct progress *progress, off_t total)
200201
display(progress, progress->last_value, NULL);
201202
}
202203

203-
int display_progress(struct progress *progress, unsigned n)
204+
int display_progress(struct progress *progress, uint64_t n)
204205
{
205206
return progress ? display(progress, n, NULL) : 0;
206207
}
207208

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,
209210
unsigned percent_threshold, unsigned delay)
210211
{
211212
struct progress *progress = malloc(sizeof(*progress));
@@ -227,12 +228,12 @@ static struct progress *start_progress_delay(const char *title, unsigned total,
227228
return progress;
228229
}
229230

230-
struct progress *start_delayed_progress(const char *title, unsigned total)
231+
struct progress *start_delayed_progress(const char *title, uint64_t total)
231232
{
232233
return start_progress_delay(title, total, 0, 2);
233234
}
234235

235-
struct progress *start_progress(const char *title, unsigned total)
236+
struct progress *start_progress(const char *title, uint64_t total)
236237
{
237238
return start_progress_delay(title, total, 0, 0);
238239
}

progress.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
struct progress;
55

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);
1010
void stop_progress(struct progress **progress);
1111
void stop_progress_msg(struct progress **progress, const char *msg);
1212

0 commit comments

Comments
 (0)