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

[PATCH 2/4] progress: use pager's original_stderr if available

From
Jeff King <peff@peff.net>
Date
Mar 24, 2011, 17:47 UTC
Message-ID
<20110324174732.GB30685@sigill.intra.peff.net>
In-Reply-To
<20110324174556.GA30661@sigill.intra.peff.net>

If we are outputting to a pager, stderr is redirected to the pager. However, progress messages should not be part of that stream, as they are time-sensitive and would end up being hidden once we actually have output.

Signed-off-by: Jeff King <peff@peff.net>
---
Same as the last iteration.
 progress.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/progress.c b/progress.c
index 3971f49..bc7d3a3 100644
--- a/progress.c
+++ b/progress.c
@@ -10,6 +10,7 @@
 
 #include "git-compat-util.h"
 #include "progress.h"
+#include "cache.h"
 
 #define TP_IDX_MAX      8
 
@@ -71,6 +72,7 @@ static void clear_progress_signal(void)
 
 static int display(struct progress *progress, unsigned n, const char *done)
 {
+	FILE *out = original_stderr ? original_stderr : stderr;
 	const char *eol, *tp;
 
 	if (progress->delay) {
@@ -95,16 +97,16 @@ static int display(struct progress *progress, unsigned n, const char *done)
 		unsigned percent = n * 100 / progress->total;
 		if (percent != progress->last_percent || progress_update) {
 			progress->last_percent = percent;
-			fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
+			fprintf(out, "%s: %3u%% (%u/%u)%s%s",
 				progress->title, percent, n,
 				progress->total, tp, eol);
-			fflush(stderr);
+			fflush(out);
 			progress_update = 0;
 			return 1;
 		}
 	} else if (progress_update) {
-		fprintf(stderr, "%s: %u%s%s", progress->title, n, tp, eol);
-		fflush(stderr);
+		fprintf(out, "%s: %u%s%s", progress->title, n, tp, eol);
+		fflush(out);
 		progress_update = 0;
 		return 1;
 	}
@@ -211,11 +213,12 @@ int display_progress(struct progress *progress, unsigned n)
 struct progress *start_progress_delay(const char *title, unsigned total,
 				       unsigned percent_treshold, unsigned delay)
 {
+	FILE *out = original_stderr ? original_stderr : stderr;
 	struct progress *progress = malloc(sizeof(*progress));
 	if (!progress) {
 		/* unlikely, but here's a good fallback */
-		fprintf(stderr, "%s...\n", title);
-		fflush(stderr);
+		fprintf(out, "%s...\n", title);
+		fflush(out);
 		return NULL;
 	}
 	progress->title = title;
-- 
1.7.4.41.g423da
Previous: Jeff KingNext: Jeff King
Message 17 of 24 in “builtin/diff.c: remove duplicated call to diff_result_code()”
  1. builtin/diff.c: remove duplicated call to diff_result_code()Junio C Hamano, Mar 22, 2011
  2. 1/3 diffcore-rename: refactor "too many candidates" logicJunio C Hamano, Mar 22, 2011
  3. 2/3 diffcore-rename: record filepair for rename srcJunio C Hamano, Mar 22, 2011
  4. 3/3 diffcore-rename: fall back to -C when -C -C busts the rename limitJunio C Hamano, Mar 22, 2011
  5. Jeff KingMar 23, 2011
  6. Junio C HamanoMar 23, 2011
  7. Jeff KingMar 23, 2011
  8. Jeff KingMar 23, 2011
  9. 1/3 pager: save the original stderr when redirecting to pagerJeff King, Mar 23, 2011
  10. 2/3 progress: use pager's original_stderr if availableJeff King, Mar 23, 2011
  11. 3/3 show: turn on rename progressJeff King, Mar 23, 2011
  12. Junio C HamanoMar 23, 2011
  13. Jeff KingMar 24, 2011
  14. Junio C HamanoMar 24, 2011
  15. Jeff KingMar 24, 2011
  16. 1/4 pager: save the original stderr when redirecting to pagerJeff King, Mar 24, 2011
  17. 2/4 progress: use pager's original_stderr if availableJeff King, Mar 24, 2011
  18. 3/4 show: turn on rename detection progress reportingJeff King, Mar 24, 2011
  19. Junio C HamanoMar 24, 2011
  20. Jeff KingMar 25, 2011
  21. 4/4 diff: turn on rename detection progress reportingJeff King, Mar 24, 2011
  22. Johannes SixtMar 25, 2011
  23. Jeff KingMar 25, 2011
  24. Junio C HamanoMar 24, 2011

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.