@matheusbsbs / matheus-bagliano / commits / 421f9d1685
Fork 0

Fix the progress code to output LF only when it is really needed

Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Alex Riesen committed May 23, 2007 at 18:07 UTC 421f9d1685b4b7d286b5929489a0d95139c6ecce
2 files changed +6 -1
progress.c
+5 -1
@@ -62,11 +62,13 @@ int display_progress(struct progress *progress, unsigned n)
62 fprintf(stderr, "%s%4u%% (%u/%u) done\r",
63 progress->prefix, percent, n, progress->total);
64 progress_update = 0;
65 + progress->need_lf = 1;
66 return 1;
67 }
68 } else if (progress_update) {
69 fprintf(stderr, "%s%u\r", progress->prefix, n);
70 progress_update = 0;
71 + progress->need_lf = 1;
72 return 1;
73 }
74 return 0;
@@ -80,6 +82,7 @@ void start_progress(struct progress *progress, const char *title,
82 progress->total = total;
83 progress->last_percent = -1;
84 progress->delay = 0;
85 + progress->need_lf = 0;
86 if (snprintf(buf, sizeof(buf), title, total))
87 fprintf(stderr, "%s\n", buf);
88 set_progress_signal();
@@ -95,12 +98,13 @@ void start_progress_delay(struct progress *progress, const char *title,
98 progress->delayed_percent_treshold = percent_treshold;
99 progress->delayed_title = title;
100 progress->delay = delay;
101 + progress->need_lf = 0;
102 set_progress_signal();
103 }
104
105 void stop_progress(struct progress *progress)
106 {
107 clear_progress_signal();
104 - if (progress->total)
108 + if (progress->need_lf)
109 fputc('\n', stderr);
110 }
progress.h
+1
@@ -8,6 +8,7 @@ struct progress {
8 unsigned delay;
9 unsigned delayed_percent_treshold;
10 const char *delayed_title;
11 + int need_lf;
12 };
13
14 int display_progress(struct progress *progress, unsigned n);