summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <junkio@cox.net>2007-05-23 11:39:58 -0700
committerLibravatar Junio C Hamano <junkio@cox.net>2007-05-23 11:39:58 -0700
commited82edc402c271a707da632083f1f4c19155d573 (patch)
tree4192a3f664bad405b32b8423f7cef0c31a93f1c6
parentMerge branch 'maint' (diff)
parentFix the progress code to output LF only when it is really needed (diff)
downloadtgif-ed82edc402c271a707da632083f1f4c19155d573.tar.xz
Merge branch 'ar/progress'
* ar/progress: Fix the progress code to output LF only when it is really needed
-rw-r--r--progress.c6
-rw-r--r--progress.h1
2 files changed, 6 insertions, 1 deletions
diff --git a/progress.c b/progress.c
index 05f7890314..4344f4eed5 100644
--- a/progress.c
+++ b/progress.c
@@ -62,11 +62,13 @@ int display_progress(struct progress *progress, unsigned n)
fprintf(stderr, "%s%4u%% (%u/%u) done\r",
progress->prefix, percent, n, progress->total);
progress_update = 0;
+ progress->need_lf = 1;
return 1;
}
} else if (progress_update) {
fprintf(stderr, "%s%u\r", progress->prefix, n);
progress_update = 0;
+ progress->need_lf = 1;
return 1;
}
return 0;
@@ -80,6 +82,7 @@ void start_progress(struct progress *progress, const char *title,
progress->total = total;
progress->last_percent = -1;
progress->delay = 0;
+ progress->need_lf = 0;
if (snprintf(buf, sizeof(buf), title, total))
fprintf(stderr, "%s\n", buf);
set_progress_signal();
@@ -95,12 +98,13 @@ void start_progress_delay(struct progress *progress, const char *title,
progress->delayed_percent_treshold = percent_treshold;
progress->delayed_title = title;
progress->delay = delay;
+ progress->need_lf = 0;
set_progress_signal();
}
void stop_progress(struct progress *progress)
{
clear_progress_signal();
- if (progress->total)
+ if (progress->need_lf)
fputc('\n', stderr);
}
diff --git a/progress.h b/progress.h
index 5ae1a89e5a..a7c17ca7c4 100644
--- a/progress.h
+++ b/progress.h
@@ -8,6 +8,7 @@ struct progress {
unsigned delay;
unsigned delayed_percent_treshold;
const char *delayed_title;
+ int need_lf;
};
int display_progress(struct progress *progress, unsigned n);