diff options
author | Nicolas Pitre <nico@cam.org> | 2007-04-18 14:27:45 -0400 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-04-22 22:18:05 -0700 |
commit | 96a02f8f6d2192d3686cd1c719044082c89e8391 (patch) | |
tree | 773d4edb5a05f860ed36d6e0d9f2562fb9b19c74 /unpack-trees.c | |
parent | f1af60bdba465779df92090ed370988f202ff043 (diff) | |
download | git-96a02f8f6d2192d3686cd1c719044082c89e8391.tar.gz git-96a02f8f6d2192d3686cd1c719044082c89e8391.tar.xz |
common progress display support
Instead of having this code duplicated in multiple places, let's have
a common interface for progress display. If someday someone wishes to
display a cheezy progress bar instead then only one file will have to
be changed.
Note: I left merge-recursive.c out since it has a strange notion of
progress as it apparently increase the expected total number as it goes.
Someone with more intimate knowledge of what that is supposed to mean
might look at converting it to the common progress interface.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r-- | unpack-trees.c | 54 |
1 files changed, 9 insertions, 45 deletions
diff --git a/unpack-trees.c b/unpack-trees.c index 513948135..8a11622cc 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -4,6 +4,7 @@ #include "tree-walk.h" #include "cache-tree.h" #include "unpack-trees.h" +#include "progress.h" #define DBRT_DEBUG 1 @@ -288,36 +289,13 @@ static void unlink_entry(char *name) } } -static volatile sig_atomic_t progress_update; - -static void progress_interval(int signum) -{ - progress_update = 1; -} - -static void setup_progress_signal(void) -{ - struct sigaction sa; - struct itimerval v; - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = progress_interval; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction(SIGALRM, &sa, NULL); - - v.it_interval.tv_sec = 1; - v.it_interval.tv_usec = 0; - v.it_value = v.it_interval; - setitimer(ITIMER_REAL, &v, NULL); -} - static struct checkout state; static void check_updates(struct cache_entry **src, int nr, struct unpack_trees_options *o) { unsigned short mask = htons(CE_UPDATE); - unsigned last_percent = 200, cnt = 0, total = 0; + unsigned cnt = 0, total = 0; + struct progress progress; if (o->update && o->verbose_update) { for (total = cnt = 0; cnt < nr; cnt++) { @@ -332,8 +310,7 @@ static void check_updates(struct cache_entry **src, int nr, if (total) { fprintf(stderr, "Checking files out...\n"); - setup_progress_signal(); - progress_update = 1; + start_progress(&progress, "", total); } cnt = 0; } @@ -341,20 +318,9 @@ static void check_updates(struct cache_entry **src, int nr, while (nr--) { struct cache_entry *ce = *src++; - if (total) { - if (!ce->ce_mode || ce->ce_flags & mask) { - unsigned percent; - cnt++; - percent = (cnt * 100) / total; - if (percent != last_percent || - progress_update) { - fprintf(stderr, "%4u%% (%u/%u) done\r", - percent, cnt, total); - last_percent = percent; - progress_update = 0; - } - } - } + if (total) + if (!ce->ce_mode || ce->ce_flags & mask) + display_progress(&progress, ++cnt); if (!ce->ce_mode) { if (o->update) unlink_entry(ce->name); @@ -366,10 +332,8 @@ static void check_updates(struct cache_entry **src, int nr, checkout_entry(ce, &state, NULL); } } - if (total) { - signal(SIGALRM, SIG_IGN); - fputc('\n', stderr); - } + if (total) + stop_progress(&progress);; } int unpack_trees(struct object_list *trees, struct unpack_trees_options *o) |