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

[PATCH] progress: don't print if !isatty(2).

From
Avery Pennarun <apenwarr@gmail.com>
Date
May 24, 2012, 05:18 UTC
Message-ID
<1337836732-26778-1-git-send-email-apenwarr@gmail.com>

If stderr isn't a tty, we shouldn't be printing incremental progress messages. In particular, this affected 'git checkout -f . >&logfile' unless you provided -q. And git-new-workdir has no way to provide -q.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
---
 progress.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/progress.c b/progress.c
index 3971f49..4d9f416 100644
--- a/progress.c
+++ b/progress.c
@@ -211,9 +211,11 @@ int display_progress(struct progress *progress, unsigned n)
 struct progress *start_progress_delay(const char *title, unsigned total,
 				       unsigned percent_treshold, unsigned delay)
 {
-	struct progress *progress = malloc(sizeof(*progress));
+	struct progress *progress = NULL;
+	if (isatty(2))
+		progress = malloc(sizeof(*progress));
 	if (!progress) {
-		/* unlikely, but here's a good fallback */
+		/* use a simple fallback */
 		fprintf(stderr, "%s...\n", title);
 		fflush(stderr);
 		return NULL;
-- 
1.7.9.dirty
Next: Jeff King
Message 1 of 11 in “progress: don't print if !isatty(2).”
  1. progress: don't print if !isatty(2).Avery Pennarun, May 24, 2012
  2. Jeff KingMay 24, 2012
  3. checkout: default to quiet if !isatty(2).Avery Pennarun, May 24, 2012
  4. Jeff KingMay 24, 2012
  5. checkout: no progress messages if !isatty(2).Avery Pennarun, May 24, 2012
  6. Junio C HamanoMay 24, 2012
  7. Jeff KingMay 24, 2012
  8. Avery PennarunMay 24, 2012
  9. Avery PennarunMay 24, 2012
  10. Junio C HamanoMay 24, 2012
  11. Avery PennarunMay 24, 2012

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.