From ee85e41af3f87afedd9fba63617e74713449240c Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 4 Dec 2017 17:05:23 -0500 Subject: [PATCH 1/2] progress: set default delay threshold to 100%, not 0% Commit 8aade107dd (progress: simplify "delayed" progress API, 2017-08-19) dropped the parameter by which callers could say "show my progress only if I haven't passed M% progress after N seconds". The intent was to just show nothing for 2 seconds, and then always progress after that. But we flipped the logic in the wrapper: it sets M=0, meaning that we'd almost _never_ show progress after 2 seconds, since we'd generally have made some progress. This should have been 100%, not 0%. We were fooled by existing calls like: start_progress_delay("foo", 0, 0, 2); which behaved this way. The trick is that the first "0" there is "how many items total", and there zero means "we don't know". And without knowing that, we cannot compute a completed percent at all, and we ignored the threshold parameter entirely! Modeling our wrapper after that broke callers which pass a non-zero value for "total". We can switch to the intended behavior by using "100" in the wrapper call. Reported-by: Lars Schneider Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progress.c b/progress.c index 289678d43d..b774cb1cd1 100644 --- a/progress.c +++ b/progress.c @@ -229,7 +229,7 @@ static struct progress *start_progress_delay(const char *title, unsigned total, struct progress *start_delayed_progress(const char *title, unsigned total) { - return start_progress_delay(title, total, 0, 2); + return start_progress_delay(title, total, 100, 2); } struct progress *start_progress(const char *title, unsigned total) From 9c5951cacf5cf2a4828480176921ca0307d22746 Mon Sep 17 00:00:00 2001 From: Lars Schneider Date: Mon, 4 Dec 2017 17:07:00 -0500 Subject: [PATCH 2/2] progress: drop delay-threshold code Since 180a9f2268 (provide a facility for "delayed" progress reporting, 2007-04-20), the progress code has allowed callers to skip showing progress if they have reached a percentage-threshold of the total work before the delay period passes. But since 8aade107dd (progress: simplify "delayed" progress API, 2017-08-19), that parameter is not available to outside callers (we always passed zero after that commit, though that was corrected in the previous commit to "100%"). Let's drop the threshold code, which never triggers in any meaningful way. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- progress.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/progress.c b/progress.c index b774cb1cd1..5f87f4568f 100644 --- a/progress.c +++ b/progress.c @@ -34,7 +34,6 @@ struct progress { unsigned total; unsigned last_percent; unsigned delay; - unsigned delayed_percent_threshold; struct throughput *throughput; uint64_t start_ns; }; @@ -83,20 +82,8 @@ static int display(struct progress *progress, unsigned n, const char *done) { const char *eol, *tp; - if (progress->delay) { - if (!progress_update || --progress->delay) - return 0; - if (progress->total) { - unsigned percent = n * 100 / progress->total; - if (percent > progress->delayed_percent_threshold) { - /* inhibit this progress report entirely */ - clear_progress_signal(); - progress->delay = -1; - progress->total = 0; - return 0; - } - } - } + if (progress->delay && (!progress_update || --progress->delay)) + return 0; progress->last_value = n; tp = (progress->throughput) ? progress->throughput->display.buf : ""; @@ -206,7 +193,7 @@ int display_progress(struct progress *progress, unsigned n) } static struct progress *start_progress_delay(const char *title, unsigned total, - unsigned percent_threshold, unsigned delay) + unsigned delay) { struct progress *progress = malloc(sizeof(*progress)); if (!progress) { @@ -219,7 +206,6 @@ static struct progress *start_progress_delay(const char *title, unsigned total, progress->total = total; progress->last_value = -1; progress->last_percent = -1; - progress->delayed_percent_threshold = percent_threshold; progress->delay = delay; progress->throughput = NULL; progress->start_ns = getnanotime(); @@ -229,12 +215,12 @@ static struct progress *start_progress_delay(const char *title, unsigned total, struct progress *start_delayed_progress(const char *title, unsigned total) { - return start_progress_delay(title, total, 100, 2); + return start_progress_delay(title, total, 2); } struct progress *start_progress(const char *title, unsigned total) { - return start_progress_delay(title, total, 0, 0); + return start_progress_delay(title, total, 0); } void stop_progress(struct progress **p_progress)