@matheusbsbs / matheus-bagliano / commits / a984a06a07
Fork 0

nicer display of thin pack completion

In the same spirit of prettifying Git's output display for mere mortals, here's a simple extension to the progress API allowing for a final message to be provided when terminating a progress line, and use it for the display of the number of objects needed to complete a thin pack, saving yet one more line of screen display. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Nov 8, 2007 at 15:45 UTC a984a06a07cdd0a843eb6107ad56e346d99ac840
3 files changed +19 -11
index-pack.c
+5 -5
@@ -792,6 +792,7 @@ int main(int argc, char **argv)
792 flush();
793 } else {
794 if (fix_thin_pack) {
795 + char msg[48];
796 int nr_unresolved = nr_deltas - nr_resolved_deltas;
797 int nr_objects_initial = nr_objects;
798 if (nr_unresolved <= 0)
@@ -800,12 +801,11 @@ int main(int argc, char **argv)
801 (nr_objects + nr_unresolved + 1)
802 * sizeof(*objects));
803 fix_unresolved_deltas(nr_unresolved);
803 - stop_progress(&progress);
804 - if (verbose)
805 - fprintf(stderr, "%d objects were added to complete this thin pack.\n",
806 - nr_objects - nr_objects_initial);
804 + sprintf(msg, "completed with %d local objects",
805 + nr_objects - nr_objects_initial);
806 + stop_progress_msg(&progress, msg);
807 fixup_pack_header_footer(output_fd, sha1,
808 - curr_pack, nr_objects);
808 + curr_pack, nr_objects);
809 }
810 if (nr_deltas != nr_resolved_deltas)
811 die("pack has %d unresolved deltas",
progress.c
+13 -6
@@ -69,9 +69,9 @@ static void clear_progress_signal(void)
69 progress_update = 0;
70 }
71
72 -static int display(struct progress *progress, unsigned n, int done)
72 +static int display(struct progress *progress, unsigned n, const char *done)
73 {
74 - char *eol, *tp;
74 + const char *eol, *tp;
75
76 if (progress->delay) {
77 if (!progress_update || --progress->delay)
@@ -90,7 +90,7 @@ static int display(struct progress *progress, unsigned n, int done)
90
91 progress->last_value = n;
92 tp = (progress->throughput) ? progress->throughput->display : "";
93 - eol = done ? ", done. \n" : " \r";
93 + eol = done ? done : " \r";
94 if (progress->total) {
95 unsigned percent = n * 100 / progress->total;
96 if (percent != progress->last_percent || progress_update) {
@@ -191,13 +191,13 @@ void display_throughput(struct progress *progress, off_t total)
191
192 throughput_string(tp, total, rate);
193 if (progress->last_value != -1 && progress_update)
194 - display(progress, progress->last_value, 0);
194 + display(progress, progress->last_value, NULL);
195 }
196 }
197
198 int display_progress(struct progress *progress, unsigned n)
199 {
200 - return progress ? display(progress, n, 0) : 0;
200 + return progress ? display(progress, n, NULL) : 0;
201 }
202
203 struct progress *start_progress_delay(const char *title, unsigned total,
@@ -226,6 +226,11 @@ struct progress *start_progress(const char *title, unsigned total)
226 }
227
228 void stop_progress(struct progress **p_progress)
229 +{
230 + stop_progress_msg(p_progress, "done");
231 +}
232 +
233 +void stop_progress_msg(struct progress **p_progress, const char *msg)
234 {
235 struct progress *progress = *p_progress;
236 if (!progress)
@@ -233,6 +238,7 @@ void stop_progress(struct progress **p_progress)
238 *p_progress = NULL;
239 if (progress->last_value != -1) {
240 /* Force the last update */
241 + char buf[strlen(msg) + 5];
242 struct throughput *tp = progress->throughput;
243 if (tp) {
244 unsigned int rate = !tp->avg_misecs ? 0 :
@@ -240,7 +246,8 @@ void stop_progress(struct progress **p_progress)
246 throughput_string(tp, tp->curr_total, rate);
247 }
248 progress_update = 1;
243 - display(progress, progress->last_value, 1);
249 + sprintf(buf, ", %s.\n", msg);
250 + display(progress, progress->last_value, buf);
251 }
252 clear_progress_signal();
253 free(progress->throughput);
progress.h
+1
@@ -9,5 +9,6 @@ struct progress *start_progress(const char *title, unsigned total);
9 struct progress *start_progress_delay(const char *title, unsigned total,
10 unsigned percent_treshold, unsigned delay);
11 void stop_progress(struct progress **progress);
12 +void stop_progress_msg(struct progress **progress, const char *msg);
13
14 #endif