git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 1/4] progress: make display_progress() return void

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Apr 12, 2019, 19:45 UTC
Message-ID
<20190412194515.6244-2-szeder.dev@gmail.com>
In-Reply-To
<20190412194515.6244-1-szeder.dev@gmail.com>

Ever since the progress infrastructure was introduced in 96a02f8f6d (common progress display support, 2007-04-18), display_progress() has returned an int, telling callers whether it updated the progress bar or not. However, this is:

  - useless, because over the last dozen years there has never been a
    single caller that cared about that return value.
  - not quite true, because it doesn't print a progress bar when
    running in the background, yet it returns 1; see 85cb8906f0
    (progress: no progress in background, 2015-04-13).

The related display_throughput() function returned void already upon its introduction in cf84d51c43 (add throughput to progress display, 2007-10-30).

Let's make display_progress() return void, too. While doing so several return statements in display() become unnecessary, remove them.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 progress.c | 13 +++++--------
 progress.h |  2 +-
 2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/progress.c b/progress.c
index 5a99c9fbf0..9010032446 100644
--- a/progress.c
+++ b/progress.c
@@ -78,12 +78,12 @@ static int is_foreground_fd(int fd)
 	return tpgrp < 0 || tpgrp == getpgid(0);
 }
 
-static int display(struct progress *progress, uint64_t n, const char *done)
+static void display(struct progress *progress, uint64_t n, const char *done)
 {
 	const char *eol, *tp;
 
 	if (progress->delay && (!progress_update || --progress->delay))
-		return 0;
+		return;
 
 	progress->last_value = n;
 	tp = (progress->throughput) ? progress->throughput->display.buf : "";
@@ -100,7 +100,6 @@ static int display(struct progress *progress, uint64_t n, const char *done)
 				fflush(stderr);
 			}
 			progress_update = 0;
-			return 1;
 		}
 	} else if (progress_update) {
 		if (is_foreground_fd(fileno(stderr)) || done) {
@@ -109,10 +108,7 @@ static int display(struct progress *progress, uint64_t n, const char *done)
 			fflush(stderr);
 		}
 		progress_update = 0;
-		return 1;
 	}
-
-	return 0;
 }
 
 static void throughput_string(struct strbuf *buf, uint64_t total,
@@ -188,9 +184,10 @@ void display_throughput(struct progress *progress, uint64_t total)
 		display(progress, progress->last_value, NULL);
 }
 
-int display_progress(struct progress *progress, uint64_t n)
+void display_progress(struct progress *progress, uint64_t n)
 {
-	return progress ? display(progress, n, NULL) : 0;
+	if (progress)
+		display(progress, n, NULL);
 }
 
 static struct progress *start_progress_delay(const char *title, uint64_t total,
diff --git a/progress.h b/progress.h
index 70a4d4a0d6..59e40cc4fd 100644
--- a/progress.h
+++ b/progress.h
@@ -4,7 +4,7 @@
 struct progress;
 
 void display_throughput(struct progress *progress, uint64_t total);
-int display_progress(struct progress *progress, uint64_t n);
+void display_progress(struct progress *progress, uint64_t n);
 struct progress *start_progress(const char *title, uint64_t total);
 struct progress *start_delayed_progress(const char *title, uint64_t total);
 void stop_progress(struct progress **progress);
-- 
2.21.0.746.gd74f1657d3
Previous: SZEDER GáborNext: SZEDER Gábor
Message 35 of 38 in “Progress display fixes”
  1. 0/5 Progress display fixesSZEDER Gábor, Mar 25, 2019
  2. 1/5 progress: make display_progress() return voidSZEDER Gábor, Mar 25, 2019
  3. 3/5 progress: assemble percentage and counters in a strbuf before printingSZEDER Gábor, Mar 25, 2019
  4. Jeff KingMar 26, 2019
  5. SZEDER GáborMar 27, 2019
  6. Jeff KingMar 28, 2019
  7. 4/5 progress: clear previous progress update dynamicallySZEDER Gábor, Mar 25, 2019
  8. 2/5 progress: return early when in the backgroundSZEDER Gábor, Mar 25, 2019
  9. Ævar Arnfjörð BjarmasonMar 25, 2019
  10. SZEDER GáborMar 25, 2019
  11. Luke MewburnMar 26, 2019
  12. Jeff KingMar 26, 2019
  13. 5/5 progress: break too long progress bar linesSZEDER Gábor, Mar 25, 2019
  14. Duy NguyenMar 25, 2019
  15. SZEDER GáborMar 25, 2019
  16. Jeff KingMar 26, 2019
  17. 0/4 Progress display fixesSZEDER Gábor, Apr 1, 2019
  18. 1/4 progress: make display_progress() return voidSZEDER Gábor, Apr 1, 2019
  19. Eric SunshineApr 2, 2019
  20. 2/4 progress: assemble percentage and counters in a strbuf before printingSZEDER Gábor, Apr 1, 2019
  21. Eric SunshineApr 2, 2019
  22. Eric SunshineApr 2, 2019
  23. 4/4 progress: break too long progress bar linesSZEDER Gábor, Apr 1, 2019
  24. 3/4 progress: clear previous progress update dynamicallySZEDER Gábor, Apr 1, 2019
  25. Jeff KingApr 1, 2019
  26. SZEDER GáborApr 1, 2019
  27. Jeff KingApr 2, 2019
  28. 0/4 Progress display fixesSZEDER Gábor, Apr 5, 2019
  29. 1/4 progress: make display_progress() return voidSZEDER Gábor, Apr 5, 2019
  30. 2/4 progress: assemble percentage and counters in a strbuf before printingSZEDER Gábor, Apr 5, 2019
  31. 3/4 progress: clear previous progress update dynamicallySZEDER Gábor, Apr 5, 2019
  32. 4/4 progress: break too long progress bar linesSZEDER Gábor, Apr 5, 2019
  33. Jeff KingApr 5, 2019
  34. 0/4 Progress display fixesSZEDER Gábor, Apr 12, 2019
  35. 1/4 progress: make display_progress() return voidSZEDER Gábor, Apr 12, 2019
  36. 2/4 progress: assemble percentage and counters in a strbuf before printingSZEDER Gábor, Apr 12, 2019
  37. 3/4 progress: clear previous progress update dynamicallySZEDER Gábor, Apr 12, 2019
  38. 4/4 progress: break too long progress bar linesSZEDER Gábor, Apr 12, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.