Signed-off-by: Pierre Habouzit <madcoder@xxxxxxxxxx> --- builtin-pack-objects.c | 12 +++--------- builtin-unpack-objects.c | 2 +- index-pack.c | 4 ++-- progress.c | 35 +++++++++++++++++------------------ progress.h | 8 +++----- unpack-trees.c | 2 +- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 0be539e..6f87737 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -606,7 +606,7 @@ static void write_pack_file(void) uint32_t nr_remaining = nr_result; if (do_progress) - start_progress(&progress_state, "Writing %u objects...", "", nr_result); + start_progress(&progress_state, "Writing objects", nr_result); written_list = xmalloc(nr_objects * sizeof(struct object_entry *)); do { @@ -1718,8 +1718,7 @@ static void prepare_pack(int window, int depth) unsigned nr_done = 0; if (progress) start_progress(&progress_state, - "Deltifying %u objects...", "", - nr_deltas); + "Deltifying objects", nr_deltas); qsort(delta_list, n, sizeof(*delta_list), type_size_sort); ll_find_deltas(delta_list, n, window+1, depth, &nr_done); if (progress) @@ -2135,8 +2134,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) prepare_packed_git(); if (progress) - start_progress(&progress_state, "Generating pack...", - "Counting objects: ", 0); + start_progress(&progress_state, "Counting objects", 0); if (!use_internal_rev_list) read_object_list_from_stdin(); else { @@ -2145,7 +2143,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) } if (progress) { stop_progress(&progress_state); - fprintf(stderr, "Done counting %u objects.\n", nr_objects); } if (non_empty && !nr_result) @@ -2155,8 +2152,5 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (nr_result) prepare_pack(window, depth); write_pack_file(); - if (progress) - fprintf(stderr, "Total %u (delta %u), reused %u (delta %u)\n", - written, written_delta, reused, reused_delta); return 0; } diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c index a6ff62f..2317b8f 100644 --- a/builtin-unpack-objects.c +++ b/builtin-unpack-objects.c @@ -322,7 +322,7 @@ static void unpack_all(void) use(sizeof(struct pack_header)); if (!quiet) - start_progress(&progress, "Unpacking %u objects...", "", nr_objects); + start_progress(&progress, "Unpacking objects", nr_objects); obj_list = xmalloc(nr_objects * sizeof(*obj_list)); for (i = 0; i < nr_objects; i++) { unpack_one(i); diff --git a/index-pack.c b/index-pack.c index db58e05..c784dec 100644 --- a/index-pack.c +++ b/index-pack.c @@ -406,7 +406,7 @@ static void parse_pack_objects(unsigned char *sha1) * - remember base (SHA1 or offset) for all deltas. */ if (verbose) - start_progress(&progress, "Indexing %u objects...", "", nr_objects); + start_progress(&progress, "Indexing objects", nr_objects); for (i = 0; i < nr_objects; i++) { struct object_entry *obj = &objects[i]; data = unpack_raw_entry(obj, &delta->base); @@ -455,7 +455,7 @@ static void parse_pack_objects(unsigned char *sha1) * for some more deltas. */ if (verbose) - start_progress(&progress, "Resolving %u deltas...", "", nr_deltas); + start_progress(&progress, "Resolving deltas", nr_deltas); for (i = 0; i < nr_objects; i++) { struct object_entry *obj = &objects[i]; union delta_base base; diff --git a/progress.c b/progress.c index 4344f4e..ee4dade 100644 --- a/progress.c +++ b/progress.c @@ -35,6 +35,10 @@ static void clear_progress_signal(void) progress_update = 0; } +#define PROGRESS_BAR_LEN 50 +static char const equals[] = + "=========================================================="; + int display_progress(struct progress *progress, unsigned n) { if (progress->delay) { @@ -53,58 +57,53 @@ int display_progress(struct progress *progress, unsigned n) } if (snprintf(buf, sizeof(buf), progress->delayed_title, progress->total)) - fprintf(stderr, "%s\n", buf); + fprintf(stderr, "%s", buf); } if (progress->total) { unsigned percent = n * 100 / progress->total; + unsigned tip = n * PROGRESS_BAR_LEN / progress->total; + if (percent != progress->last_percent || progress_update) { progress->last_percent = percent; - fprintf(stderr, "%s%4u%% (%u/%u) done\r", - progress->prefix, percent, n, progress->total); + fprintf(stderr, "%s[%.*s%c%*s] %u%%\r", + progress->title, tip, equals, + percent == 100 ? '=' : '>', + PROGRESS_BAR_LEN - tip, "", percent); progress_update = 0; - progress->need_lf = 1; return 1; } } else if (progress_update) { - fprintf(stderr, "%s%u\r", progress->prefix, n); + fprintf(stderr, "%s%u\r", progress->title, n); progress_update = 0; - progress->need_lf = 1; return 1; } return 0; } void start_progress(struct progress *progress, const char *title, - const char *prefix, unsigned total) + unsigned total) { - char buf[80]; - progress->prefix = prefix; 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); + snprintf(progress->title, sizeof(progress->title), "%-20s: ", title); + fprintf(stderr, "%s\r", progress->title); set_progress_signal(); } void start_progress_delay(struct progress *progress, const char *title, - const char *prefix, unsigned total, - unsigned percent_treshold, unsigned delay) + unsigned total, unsigned percent_treshold, unsigned delay) { - progress->prefix = prefix; progress->total = total; progress->last_percent = -1; 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->need_lf) - fputc('\n', stderr); + fputc('\n', stderr); } diff --git a/progress.h b/progress.h index a7c17ca..dd816cc 100644 --- a/progress.h +++ b/progress.h @@ -2,21 +2,19 @@ #define PROGRESS_H struct progress { - const char *prefix; + char title[80]; unsigned total; unsigned last_percent; unsigned delay; unsigned delayed_percent_treshold; const char *delayed_title; - int need_lf; }; int display_progress(struct progress *progress, unsigned n); void start_progress(struct progress *progress, const char *title, - const char *prefix, unsigned total); + unsigned total); void start_progress_delay(struct progress *progress, const char *title, - const char *prefix, unsigned total, - unsigned percent_treshold, unsigned delay); + unsigned total, unsigned percent_treshold, unsigned delay); void stop_progress(struct progress *progress); #endif diff --git a/unpack-trees.c b/unpack-trees.c index ccfeb6e..f7e3f3d 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -308,7 +308,7 @@ static void check_updates(struct cache_entry **src, int nr, } start_progress_delay(&progress, "Checking %u files out...", - "", total, 50, 2); + total, 50, 2); cnt = 0; } -- 1.5.3.2.1114.ga57c3 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html