more compact progress display
Each progress can be on a single line instead of two. [sp: Changed "Checking files out" to "Checking out files" at Johannes Sixt's suggestion as it better explains the action that is taking place] Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Nicolas Pitre committed
Oct 16, 2007 at 21:55 UTC
42e18fbf5f94dd6bd303bf702e030a29fa39d6c4
6 files changed
+39
-50
builtin-pack-objects.c
+5
-11
@@ -606,7 +606,7 @@ static void write_pack_file(void)
606
uint32_t nr_remaining = nr_result;
607
608
if (do_progress)
609
- start_progress(&progress_state, "Writing %u objects...", "", nr_result);
609
+ start_progress(&progress_state, "Writing objects", nr_result);
610
written_list = xmalloc(nr_objects * sizeof(struct object_entry *));
611
612
do {
@@ -1717,9 +1717,8 @@ static void prepare_pack(int window, int depth)
1717
if (nr_deltas) {
1718
unsigned nr_done = 0;
1719
if (progress)
1720
- start_progress(&progress_state,
1721
- "Deltifying %u objects...", "",
1722
- nr_deltas);
1720
+ start_progress(&progress_state, "Deltifying objects",
1721
+ nr_deltas);
1722
qsort(delta_list, n, sizeof(*delta_list), type_size_sort);
1723
ll_find_deltas(delta_list, n, window+1, depth, &nr_done);
1724
if (progress)
@@ -2135,23 +2134,18 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2134
prepare_packed_git();
2135
2136
if (progress)
2138
- start_progress(&progress_state, "Generating pack...",
2139
- "Counting objects: ", 0);
2137
+ start_progress(&progress_state, "Counting objects", 0);
2138
if (!use_internal_rev_list)
2139
read_object_list_from_stdin();
2140
else {
2141
rp_av[rp_ac] = NULL;
2142
get_object_list(rp_ac, rp_av);
2143
}
2146
- if (progress) {
2144
+ if (progress)
2145
stop_progress(&progress_state);
2148
- fprintf(stderr, "Done counting %u objects.\n", nr_objects);
2149
- }
2146
2147
if (non_empty && !nr_result)
2148
return 0;
2153
- if (progress && (nr_objects != nr_result))
2154
- fprintf(stderr, "Result has %u objects.\n", nr_result);
2149
if (nr_result)
2150
prepare_pack(window, depth);
2151
write_pack_file();
builtin-unpack-objects.c
+1
-1
@@ -322,7 +322,7 @@ static void unpack_all(void)
322
use(sizeof(struct pack_header));
323
324
if (!quiet)
325
- start_progress(&progress, "Unpacking %u objects...", "", nr_objects);
325
+ start_progress(&progress, "Unpacking 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
+2
-2
@@ -406,7 +406,7 @@ static void parse_pack_objects(unsigned char *sha1)
406
* - remember base (SHA1 or offset) for all deltas.
407
*/
408
if (verbose)
409
- start_progress(&progress, "Indexing %u objects...", "", nr_objects);
409
+ start_progress(&progress, "Indexing objects", nr_objects);
410
for (i = 0; i < nr_objects; i++) {
411
struct object_entry *obj = &objects[i];
412
data = unpack_raw_entry(obj, &delta->base);
@@ -455,7 +455,7 @@ static void parse_pack_objects(unsigned char *sha1)
455
* for some more deltas.
456
*/
457
if (verbose)
458
- start_progress(&progress, "Resolving %u deltas...", "", nr_deltas);
458
+ start_progress(&progress, "Resolving deltas", nr_deltas);
459
for (i = 0; i < nr_objects; i++) {
460
struct object_entry *obj = &objects[i];
461
union delta_base base;
progress.c
+25
-28
@@ -35,10 +35,11 @@ static void clear_progress_signal(void)
35
progress_update = 0;
36
}
37
38
-int display_progress(struct progress *progress, unsigned n)
38
+static int display(struct progress *progress, unsigned n, int done)
39
{
40
+ char *eol;
41
+
42
if (progress->delay) {
41
- char buf[80];
43
if (!progress_update || --progress->delay)
44
return 0;
45
if (progress->total) {
@@ -51,60 +52,56 @@ int display_progress(struct progress *progress, unsigned n)
52
return 0;
53
}
54
}
54
- if (snprintf(buf, sizeof(buf),
55
- progress->delayed_title, progress->total))
56
- fprintf(stderr, "%s\n", buf);
55
}
56
+
57
+ progress->last_value = n;
58
+ eol = done ? ", done. \n" : " \r";
59
if (progress->total) {
60
unsigned percent = n * 100 / progress->total;
61
if (percent != progress->last_percent || progress_update) {
62
progress->last_percent = percent;
62
- fprintf(stderr, "%s%4u%% (%u/%u) done\r",
63
- progress->prefix, percent, n, progress->total);
63
+ fprintf(stderr, "%s: %3u%% (%u/%u)%s", progress->title,
64
+ percent, n, progress->total, eol);
65
progress_update = 0;
65
- progress->need_lf = 1;
66
return 1;
67
}
68
} else if (progress_update) {
69
- fprintf(stderr, "%s%u\r", progress->prefix, n);
69
+ fprintf(stderr, "%s: %u%s", progress->title, n, eol);
70
progress_update = 0;
71
- progress->need_lf = 1;
71
return 1;
72
}
73
+
74
return 0;
75
}
76
77
-void start_progress(struct progress *progress, const char *title,
78
- const char *prefix, unsigned total)
77
+int display_progress(struct progress *progress, unsigned n)
78
{
80
- char buf[80];
81
- progress->prefix = prefix;
82
- progress->total = total;
83
- progress->last_percent = -1;
84
- progress->delay = 0;
85
- progress->need_lf = 0;
86
- if (snprintf(buf, sizeof(buf), title, total))
87
- fprintf(stderr, "%s\n", buf);
88
- set_progress_signal();
79
+ return display(progress, n, 0);
80
}
81
82
void start_progress_delay(struct progress *progress, const char *title,
92
- const char *prefix, unsigned total,
93
- unsigned percent_treshold, unsigned delay)
83
+ unsigned total, unsigned percent_treshold, unsigned delay)
84
{
95
- progress->prefix = prefix;
85
+ progress->title = title;
86
progress->total = total;
87
+ progress->last_value = -1;
88
progress->last_percent = -1;
89
progress->delayed_percent_treshold = percent_treshold;
99
- progress->delayed_title = title;
90
progress->delay = delay;
101
- progress->need_lf = 0;
91
set_progress_signal();
92
}
93
94
+void start_progress(struct progress *progress, const char *title, unsigned total)
95
+{
96
+ start_progress_delay(progress, title, total, 0, 0);
97
+}
98
+
99
void stop_progress(struct progress *progress)
100
{
101
+ if (progress->last_value != -1) {
102
+ /* Force the last update */
103
+ progress_update = 1;
104
+ display(progress, progress->last_value, 1);
105
+ }
106
clear_progress_signal();
108
- if (progress->need_lf)
109
- fputc('\n', stderr);
107
}
progress.h
+4
-6
@@ -2,21 +2,19 @@
2
#define PROGRESS_H
3
4
struct progress {
5
- const char *prefix;
5
+ const char *title;
6
+ int last_value;
7
unsigned total;
8
unsigned last_percent;
9
unsigned delay;
10
unsigned delayed_percent_treshold;
10
- const char *delayed_title;
11
- int need_lf;
11
};
12
13
int display_progress(struct progress *progress, unsigned n);
14
void start_progress(struct progress *progress, const char *title,
16
- const char *prefix, unsigned total);
15
+ unsigned total);
16
void start_progress_delay(struct progress *progress, const char *title,
18
- const char *prefix, unsigned total,
19
- unsigned percent_treshold, unsigned delay);
17
+ unsigned total, unsigned percent_treshold, unsigned delay);
18
void stop_progress(struct progress *progress);
19
20
#endif
unpack-trees.c
+2
-2
@@ -307,8 +307,8 @@ static void check_updates(struct cache_entry **src, int nr,
307
total++;
308
}
309
310
- start_progress_delay(&progress, "Checking %u files out...",
311
- "", total, 50, 2);
310
+ start_progress_delay(&progress, "Checking out files",
311
+ total, 50, 2);
312
cnt = 0;
313
}
314