progress: no progress in background
Disable the display of the progress if stderr is not the current foreground process. Still display the final result when done. Signed-off-by: Luke Mewburn <luke@mewburn.net> Acked-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Luke Mewburn committed
Apr 13, 2015 at 23:30 UTC
85cb8906f0e9b5639230fe247d5d916db8806777
1 file changed
+16
-6
progress.c
+16
-6
@@ -72,6 +72,11 @@ static void clear_progress_signal(void)
72
progress_update = 0;
73
}
74
75
+static int is_foreground_fd(int fd)
76
+{
77
+ return getpgid(0) == tcgetpgrp(fd);
78
+}
79
+
80
static int display(struct progress *progress, unsigned n, const char *done)
81
{
82
const char *eol, *tp;
@@ -98,16 +103,21 @@ static int display(struct progress *progress, unsigned n, const char *done)
103
unsigned percent = n * 100 / progress->total;
104
if (percent != progress->last_percent || progress_update) {
105
progress->last_percent = percent;
101
- fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
102
- progress->title, percent, n,
103
- progress->total, tp, eol);
104
- fflush(stderr);
106
+ if (is_foreground_fd(fileno(stderr)) || done) {
107
+ fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
108
+ progress->title, percent, n,
109
+ progress->total, tp, eol);
110
+ fflush(stderr);
111
+ }
112
progress_update = 0;
113
return 1;
114
}
115
} else if (progress_update) {
109
- fprintf(stderr, "%s: %u%s%s", progress->title, n, tp, eol);
110
- fflush(stderr);
116
+ if (is_foreground_fd(fileno(stderr)) || done) {
117
+ fprintf(stderr, "%s: %u%s%s",
118
+ progress->title, n, tp, eol);
119
+ fflush(stderr);
120
+ }
121
progress_update = 0;
122
return 1;
123
}