Skip to content

Commit a984a06

Browse files
Nicolas Pitregitster
authored andcommitted
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>
1 parent 53ed7b5 commit a984a06

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

index-pack.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ int main(int argc, char **argv)
792792
flush();
793793
} else {
794794
if (fix_thin_pack) {
795+
char msg[48];
795796
int nr_unresolved = nr_deltas - nr_resolved_deltas;
796797
int nr_objects_initial = nr_objects;
797798
if (nr_unresolved <= 0)
@@ -800,12 +801,11 @@ int main(int argc, char **argv)
800801
(nr_objects + nr_unresolved + 1)
801802
* sizeof(*objects));
802803
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);
807807
fixup_pack_header_footer(output_fd, sha1,
808-
curr_pack, nr_objects);
808+
curr_pack, nr_objects);
809809
}
810810
if (nr_deltas != nr_resolved_deltas)
811811
die("pack has %d unresolved deltas",

progress.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ static void clear_progress_signal(void)
6969
progress_update = 0;
7070
}
7171

72-
static int display(struct progress *progress, unsigned n, int done)
72+
static int display(struct progress *progress, unsigned n, const char *done)
7373
{
74-
char *eol, *tp;
74+
const char *eol, *tp;
7575

7676
if (progress->delay) {
7777
if (!progress_update || --progress->delay)
@@ -90,7 +90,7 @@ static int display(struct progress *progress, unsigned n, int done)
9090

9191
progress->last_value = n;
9292
tp = (progress->throughput) ? progress->throughput->display : "";
93-
eol = done ? ", done. \n" : " \r";
93+
eol = done ? done : " \r";
9494
if (progress->total) {
9595
unsigned percent = n * 100 / progress->total;
9696
if (percent != progress->last_percent || progress_update) {
@@ -191,13 +191,13 @@ void display_throughput(struct progress *progress, off_t total)
191191

192192
throughput_string(tp, total, rate);
193193
if (progress->last_value != -1 && progress_update)
194-
display(progress, progress->last_value, 0);
194+
display(progress, progress->last_value, NULL);
195195
}
196196
}
197197

198198
int display_progress(struct progress *progress, unsigned n)
199199
{
200-
return progress ? display(progress, n, 0) : 0;
200+
return progress ? display(progress, n, NULL) : 0;
201201
}
202202

203203
struct progress *start_progress_delay(const char *title, unsigned total,
@@ -226,21 +226,28 @@ struct progress *start_progress(const char *title, unsigned total)
226226
}
227227

228228
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)
229234
{
230235
struct progress *progress = *p_progress;
231236
if (!progress)
232237
return;
233238
*p_progress = NULL;
234239
if (progress->last_value != -1) {
235240
/* Force the last update */
241+
char buf[strlen(msg) + 5];
236242
struct throughput *tp = progress->throughput;
237243
if (tp) {
238244
unsigned int rate = !tp->avg_misecs ? 0 :
239245
tp->avg_bytes / tp->avg_misecs;
240246
throughput_string(tp, tp->curr_total, rate);
241247
}
242248
progress_update = 1;
243-
display(progress, progress->last_value, 1);
249+
sprintf(buf, ", %s.\n", msg);
250+
display(progress, progress->last_value, buf);
244251
}
245252
clear_progress_signal();
246253
free(progress->throughput);

progress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ struct progress *start_progress(const char *title, unsigned total);
99
struct progress *start_progress_delay(const char *title, unsigned total,
1010
unsigned percent_treshold, unsigned delay);
1111
void stop_progress(struct progress **progress);
12+
void stop_progress_msg(struct progress **progress, const char *msg);
1213

1314
#endif

0 commit comments

Comments
 (0)