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>
Nicolas Pitre committed
Apr 20, 2007 at 14:10 UTC
13aaf148258808437c485d3ef54c7ae7668384d7
6 files changed
+27
-34
builtin-pack-objects.c
+7
-12
@@ -580,10 +580,8 @@ static off_t write_pack_file(void)
580
f = sha1fd(fd, pack_tmp_name);
581
}
582
583
- if (do_progress) {
584
- fprintf(stderr, "Writing %u objects.\n", nr_result);
585
- start_progress(&progress_state, "", nr_result);
586
- }
583
+ if (do_progress)
584
+ start_progress(&progress_state, "Writing %u objects...", "", nr_result);
585
586
hdr.hdr_signature = htonl(PACK_SIGNATURE);
587
hdr.hdr_version = htonl(PACK_VERSION);
@@ -1389,10 +1387,8 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1387
return;
1388
array = xmalloc(array_size);
1389
memset(array, 0, array_size);
1392
- if (progress) {
1393
- fprintf(stderr, "Deltifying %u objects.\n", nr_result);
1394
- start_progress(&progress_state, "", nr_result);
1395
- }
1390
+ if (progress)
1391
+ start_progress(&progress_state, "Deltifying %u objects...", "", nr_result);
1392
1393
do {
1394
struct object_entry *entry = list[--i];
@@ -1722,10 +1718,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1718
1719
prepare_packed_git();
1720
1725
- if (progress) {
1726
- fprintf(stderr, "Generating pack...\n");
1727
- start_progress(&progress_state, "Counting objects: ", 0);
1728
- }
1721
+ if (progress)
1722
+ start_progress(&progress_state, "Generating pack...",
1723
+ "Counting objects: ", 0);
1724
if (!use_internal_rev_list)
1725
read_object_list_from_stdin();
1726
else {
builtin-unpack-objects.c
+2
-4
@@ -321,10 +321,8 @@ static void unpack_all(void)
321
die("unknown pack file version %d", ntohl(hdr->hdr_version));
322
use(sizeof(struct pack_header));
323
324
- if (!quiet) {
325
- fprintf(stderr, "Unpacking %d objects\n", nr_objects);
326
- start_progress(&progress, "", nr_objects);
327
- }
324
+ if (!quiet)
325
+ start_progress(&progress, "Unpacking %u objects...", "", nr_objects);
326
obj_list = xmalloc(nr_objects * sizeof(*obj_list));
327
for (i = 0; i < nr_objects; i++) {
328
unpack_one(i);
index-pack.c
+4
-8
@@ -407,10 +407,8 @@ static void parse_pack_objects(unsigned char *sha1)
407
* - calculate SHA1 of all non-delta objects;
408
* - remember base (SHA1 or offset) for all deltas.
409
*/
410
- if (verbose) {
411
- fprintf(stderr, "Indexing %d objects.\n", nr_objects);
412
- start_progress(&progress, "", nr_objects);
413
- }
410
+ if (verbose)
411
+ start_progress(&progress, "Indexing %u objects...", "", nr_objects);
412
for (i = 0; i < nr_objects; i++) {
413
struct object_entry *obj = &objects[i];
414
data = unpack_raw_entry(obj, &delta->base);
@@ -458,10 +456,8 @@ static void parse_pack_objects(unsigned char *sha1)
456
* recursively checking if the resulting object is used as a base
457
* for some more deltas.
458
*/
461
- if (verbose) {
462
- fprintf(stderr, "Resolving %d deltas.\n", nr_deltas);
463
- start_progress(&progress, "", nr_deltas);
464
- }
459
+ if (verbose)
460
+ start_progress(&progress, "Resolving %u deltas...", "", nr_deltas);
461
for (i = 0; i < nr_objects; i++) {
462
struct object_entry *obj = &objects[i];
463
union delta_base base;
progress.c
+8
-4
@@ -40,23 +40,27 @@ int display_progress(struct progress *progress, unsigned n)
40
if (percent != progress->last_percent || progress_update) {
41
progress->last_percent = percent;
42
fprintf(stderr, "%s%4u%% (%u/%u) done\r",
43
- progress->msg, percent, n, progress->total);
43
+ progress->prefix, percent, n, progress->total);
44
progress_update = 0;
45
return 1;
46
}
47
} else if (progress_update) {
48
- fprintf(stderr, "%s%u\r", progress->msg, n);
48
+ fprintf(stderr, "%s%u\r", progress->prefix, n);
49
progress_update = 0;
50
return 1;
51
}
52
return 0;
53
}
54
55
-void start_progress(struct progress *progress, const char *msg, unsigned total)
55
+void start_progress(struct progress *progress, const char *title,
56
+ const char *prefix, unsigned total)
57
{
57
- progress->msg = msg;
58
+ char buf[80];
59
+ progress->prefix = prefix;
60
progress->total = total;
61
progress->last_percent = -1;
62
+ if (snprintf(buf, sizeof(buf), title, total))
63
+ fprintf(stderr, "%s\n", buf);
64
set_progress_signal();
65
}
66
progress.h
+3
-2
@@ -2,13 +2,14 @@
2
#define __progress_h__
3
4
struct progress {
5
- const char *msg;
5
+ const char *prefix;
6
unsigned total;
7
unsigned last_percent;
8
};
9
10
int display_progress(struct progress *progress, unsigned n);
11
-void start_progress(struct progress *progress, const char *msg, unsigned total);
11
+void start_progress(struct progress *progress, const char *title,
12
+ const char *prefix, unsigned total);
13
void stop_progress(struct progress *progress);
14
15
#endif
unpack-trees.c
+3
-4
@@ -308,10 +308,9 @@ static void check_updates(struct cache_entry **src, int nr,
308
if (total < 250)
309
total = 0;
310
311
- if (total) {
312
- fprintf(stderr, "Checking files out...\n");
313
- start_progress(&progress, "", total);
314
- }
311
+ if (total)
312
+ start_progress(&progress, "Checking %u files out...",
313
+ "", total);
314
cnt = 0;
315
}
316