Skip to content

Commit

Permalink
Fix the progress code to output LF only when it is really needed
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Alex Riesen authored and Junio C Hamano committed May 23, 2007
1 parent 7ca055f commit 421f9d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
}
1 change: 1 addition & 0 deletions progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 421f9d1

Please sign in to comment.