summaryrefslogtreecommitdiff
path: root/progress.c
diff options
context:
space:
mode:
Diffstat (limited to 'progress.c')
-rw-r--r--progress.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/progress.c b/progress.c
index 7629e0572b..c342e39c5d 100644
--- a/progress.c
+++ b/progress.c
@@ -1,6 +1,15 @@
#include "git-compat-util.h"
#include "progress.h"
+struct progress {
+ const char *title;
+ int last_value;
+ unsigned total;
+ unsigned last_percent;
+ unsigned delay;
+ unsigned delayed_percent_treshold;
+};
+
static volatile sig_atomic_t progress_update;
static void progress_interval(int signum)
@@ -76,12 +85,18 @@ static int display(struct progress *progress, unsigned n, int done)
int display_progress(struct progress *progress, unsigned n)
{
- return display(progress, n, 0);
+ return progress ? display(progress, n, 0) : 0;
}
-void start_progress_delay(struct progress *progress, const char *title,
- unsigned total, unsigned percent_treshold, unsigned delay)
+struct progress *start_progress_delay(const char *title, unsigned total,
+ unsigned percent_treshold, unsigned delay)
{
+ struct progress *progress = malloc(sizeof(*progress));
+ if (!progress) {
+ /* unlikely, but here's a good fallback */
+ fprintf(stderr, "%s...\n", title);
+ return NULL;
+ }
progress->title = title;
progress->total = total;
progress->last_value = -1;
@@ -89,19 +104,25 @@ void start_progress_delay(struct progress *progress, const char *title,
progress->delayed_percent_treshold = percent_treshold;
progress->delay = delay;
set_progress_signal();
+ return progress;
}
-void start_progress(struct progress *progress, const char *title, unsigned total)
+struct progress *start_progress(const char *title, unsigned total)
{
- start_progress_delay(progress, title, total, 0, 0);
+ return start_progress_delay(title, total, 0, 0);
}
-void stop_progress(struct progress *progress)
+void stop_progress(struct progress **p_progress)
{
+ struct progress *progress = *p_progress;
+ if (!progress)
+ return;
+ *p_progress = NULL;
if (progress->last_value != -1) {
/* Force the last update */
progress_update = 1;
display(progress, progress->last_value, 1);
}
clear_progress_signal();
+ free(progress);
}