make progress "title" part of the common progress interface

If the progress bar ends up in a box, better provide a title for it too.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Nicolas Pitre 2007-04-20 14:10:07 -04:00 committed by Junio C Hamano
parent 96a02f8f6d
commit 13aaf14825
6 changed files with 27 additions and 34 deletions

View File

@ -580,10 +580,8 @@ static off_t write_pack_file(void)
f = sha1fd(fd, pack_tmp_name); f = sha1fd(fd, pack_tmp_name);
} }
if (do_progress) { if (do_progress)
fprintf(stderr, "Writing %u objects.\n", nr_result); start_progress(&progress_state, "Writing %u objects...", "", nr_result);
start_progress(&progress_state, "", nr_result);
}
hdr.hdr_signature = htonl(PACK_SIGNATURE); hdr.hdr_signature = htonl(PACK_SIGNATURE);
hdr.hdr_version = htonl(PACK_VERSION); hdr.hdr_version = htonl(PACK_VERSION);
@ -1389,10 +1387,8 @@ static void find_deltas(struct object_entry **list, int window, int depth)
return; return;
array = xmalloc(array_size); array = xmalloc(array_size);
memset(array, 0, array_size); memset(array, 0, array_size);
if (progress) { if (progress)
fprintf(stderr, "Deltifying %u objects.\n", nr_result); start_progress(&progress_state, "Deltifying %u objects...", "", nr_result);
start_progress(&progress_state, "", nr_result);
}
do { do {
struct object_entry *entry = list[--i]; struct object_entry *entry = list[--i];
@ -1722,10 +1718,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
prepare_packed_git(); prepare_packed_git();
if (progress) { if (progress)
fprintf(stderr, "Generating pack...\n"); start_progress(&progress_state, "Generating pack...",
start_progress(&progress_state, "Counting objects: ", 0); "Counting objects: ", 0);
}
if (!use_internal_rev_list) if (!use_internal_rev_list)
read_object_list_from_stdin(); read_object_list_from_stdin();
else { else {

View File

@ -321,10 +321,8 @@ static void unpack_all(void)
die("unknown pack file version %d", ntohl(hdr->hdr_version)); die("unknown pack file version %d", ntohl(hdr->hdr_version));
use(sizeof(struct pack_header)); use(sizeof(struct pack_header));
if (!quiet) { if (!quiet)
fprintf(stderr, "Unpacking %d objects\n", nr_objects); start_progress(&progress, "Unpacking %u objects...", "", nr_objects);
start_progress(&progress, "", nr_objects);
}
obj_list = xmalloc(nr_objects * sizeof(*obj_list)); obj_list = xmalloc(nr_objects * sizeof(*obj_list));
for (i = 0; i < nr_objects; i++) { for (i = 0; i < nr_objects; i++) {
unpack_one(i); unpack_one(i);

View File

@ -407,10 +407,8 @@ static void parse_pack_objects(unsigned char *sha1)
* - calculate SHA1 of all non-delta objects; * - calculate SHA1 of all non-delta objects;
* - remember base (SHA1 or offset) for all deltas. * - remember base (SHA1 or offset) for all deltas.
*/ */
if (verbose) { if (verbose)
fprintf(stderr, "Indexing %d objects.\n", nr_objects); start_progress(&progress, "Indexing %u objects...", "", nr_objects);
start_progress(&progress, "", nr_objects);
}
for (i = 0; i < nr_objects; i++) { for (i = 0; i < nr_objects; i++) {
struct object_entry *obj = &objects[i]; struct object_entry *obj = &objects[i];
data = unpack_raw_entry(obj, &delta->base); data = unpack_raw_entry(obj, &delta->base);
@ -458,10 +456,8 @@ static void parse_pack_objects(unsigned char *sha1)
* recursively checking if the resulting object is used as a base * recursively checking if the resulting object is used as a base
* for some more deltas. * for some more deltas.
*/ */
if (verbose) { if (verbose)
fprintf(stderr, "Resolving %d deltas.\n", nr_deltas); start_progress(&progress, "Resolving %u deltas...", "", nr_deltas);
start_progress(&progress, "", nr_deltas);
}
for (i = 0; i < nr_objects; i++) { for (i = 0; i < nr_objects; i++) {
struct object_entry *obj = &objects[i]; struct object_entry *obj = &objects[i];
union delta_base base; union delta_base base;

View File

@ -40,23 +40,27 @@ int display_progress(struct progress *progress, unsigned n)
if (percent != progress->last_percent || progress_update) { if (percent != progress->last_percent || progress_update) {
progress->last_percent = percent; progress->last_percent = percent;
fprintf(stderr, "%s%4u%% (%u/%u) done\r", fprintf(stderr, "%s%4u%% (%u/%u) done\r",
progress->msg, percent, n, progress->total); progress->prefix, percent, n, progress->total);
progress_update = 0; progress_update = 0;
return 1; return 1;
} }
} else if (progress_update) { } else if (progress_update) {
fprintf(stderr, "%s%u\r", progress->msg, n); fprintf(stderr, "%s%u\r", progress->prefix, n);
progress_update = 0; progress_update = 0;
return 1; return 1;
} }
return 0; return 0;
} }
void start_progress(struct progress *progress, const char *msg, unsigned total) void start_progress(struct progress *progress, const char *title,
const char *prefix, unsigned total)
{ {
progress->msg = msg; char buf[80];
progress->prefix = prefix;
progress->total = total; progress->total = total;
progress->last_percent = -1; progress->last_percent = -1;
if (snprintf(buf, sizeof(buf), title, total))
fprintf(stderr, "%s\n", buf);
set_progress_signal(); set_progress_signal();
} }

View File

@ -2,13 +2,14 @@
#define __progress_h__ #define __progress_h__
struct progress { struct progress {
const char *msg; const char *prefix;
unsigned total; unsigned total;
unsigned last_percent; unsigned last_percent;
}; };
int display_progress(struct progress *progress, unsigned n); int display_progress(struct progress *progress, unsigned n);
void start_progress(struct progress *progress, const char *msg, unsigned total); void start_progress(struct progress *progress, const char *title,
const char *prefix, unsigned total);
void stop_progress(struct progress *progress); void stop_progress(struct progress *progress);
#endif #endif

View File

@ -308,10 +308,9 @@ static void check_updates(struct cache_entry **src, int nr,
if (total < 250) if (total < 250)
total = 0; total = 0;
if (total) { if (total)
fprintf(stderr, "Checking files out...\n"); start_progress(&progress, "Checking %u files out...",
start_progress(&progress, "", total); "", total);
}
cnt = 0; cnt = 0;
} }