{"thread":{"id":"10741","subject":"[PATCH] nicer display of thin pack completion","startedAt":"2007-11-08T20:45:41Z","lastAt":"2007-11-08T20:45:41Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"58934","messageId":"alpine.LFD.0.9999.0711081536540.21255@xanadu.home","threadId":"10741","inReplyTo":null,"subject":"[PATCH] nicer display of thin pack completion","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-11-08T20:45:41Z","receivedAt":"2007-11-08T20:45:41Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"In the same spirit of prettifying Git's output display for mere mortals,\nhere's a simple extension to the progress API allowing for a final \nmessage to be provided when terminating a progress line, and use it for\nthe display of the number of objects needed to complete a thin pack,\nsaving yet one more line of screen display.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\ndiff --git a/index-pack.c b/index-pack.c\nindex 581a7f5..469a330 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -792,6 +792,7 @@ int main(int argc, char **argv)\n \t\tflush();\n \t} else {\n \t\tif (fix_thin_pack) {\n+\t\t\tchar msg[48];\n \t\t\tint nr_unresolved = nr_deltas - nr_resolved_deltas;\n \t\t\tint nr_objects_initial = nr_objects;\n \t\t\tif (nr_unresolved <= 0)\n@@ -800,12 +801,11 @@ int main(int argc, char **argv)\n \t\t\t\t\t   (nr_objects + nr_unresolved + 1)\n \t\t\t\t\t   * sizeof(*objects));\n \t\t\tfix_unresolved_deltas(nr_unresolved);\n-\t\t\tstop_progress(&progress);\n-\t\t\tif (verbose)\n-\t\t\t\tfprintf(stderr, \"%d objects were added to complete this thin pack.\\n\",\n-\t\t\t\t\tnr_objects - nr_objects_initial);\n+\t\t\tsprintf(msg, \"completed with %d local objects\",\n+\t\t\t\tnr_objects - nr_objects_initial);\n+\t\t\tstop_progress_msg(&progress, msg);\n \t\t\tfixup_pack_header_footer(output_fd, sha1,\n-\t\t\t\tcurr_pack, nr_objects);\n+\t\t\t\t\t\t curr_pack, nr_objects);\n \t\t}\n \t\tif (nr_deltas != nr_resolved_deltas)\n \t\t\tdie(\"pack has %d unresolved deltas\",\ndiff --git a/progress.c b/progress.c\nindex 0700dcf..4bd650f 100644\n--- a/progress.c\n+++ b/progress.c\n@@ -69,9 +69,9 @@ static void clear_progress_signal(void)\n \tprogress_update = 0;\n }\n \n-static int display(struct progress *progress, unsigned n, int done)\n+static int display(struct progress *progress, unsigned n, const char *done)\n {\n-\tchar *eol, *tp;\n+\tconst char *eol, *tp;\n \n \tif (progress->delay) {\n \t\tif (!progress_update || --progress->delay)\n@@ -90,7 +90,7 @@ static int display(struct progress *progress, unsigned n, int done)\n \n \tprogress->last_value = n;\n \ttp = (progress->throughput) ? progress->throughput->display : \"\";\n-\teol = done ? \", done.   \\n\" : \"   \\r\";\n+\teol = done ? done : \"   \\r\";\n \tif (progress->total) {\n \t\tunsigned percent = n * 100 / progress->total;\n \t\tif (percent != progress->last_percent || progress_update) {\n@@ -191,13 +191,13 @@ void display_throughput(struct progress *progress, off_t total)\n \n \t\tthroughput_string(tp, total, rate);\n \t\tif (progress->last_value != -1 && progress_update)\n-\t\t\tdisplay(progress, progress->last_value, 0);\n+\t\t\tdisplay(progress, progress->last_value, NULL);\n \t}\n }\n \n int display_progress(struct progress *progress, unsigned n)\n {\n-\treturn progress ? display(progress, n, 0) : 0;\n+\treturn progress ? display(progress, n, NULL) : 0;\n }\n \n struct progress *start_progress_delay(const char *title, unsigned total,\n@@ -227,12 +227,18 @@ struct progress *start_progress(const char *title, unsigned total)\n \n void stop_progress(struct progress **p_progress)\n {\n+\tstop_progress_msg(p_progress, \"done\");\n+}\n+\n+void stop_progress_msg(struct progress **p_progress, const char *msg)\n+{\n \tstruct progress *progress = *p_progress;\n \tif (!progress)\n \t\treturn;\n \t*p_progress = NULL;\n \tif (progress->last_value != -1) {\n \t\t/* Force the last update */\n+\t\tchar buf[strlen(msg) + 5];\n \t\tstruct throughput *tp = progress->throughput;\n \t\tif (tp) {\n \t\t\tunsigned int rate = !tp->avg_misecs ? 0 :\n@@ -240,7 +246,8 @@ void stop_progress(struct progress **p_progress)\n \t\t\tthroughput_string(tp, tp->curr_total, rate);\n \t\t}\n \t\tprogress_update = 1;\n-\t\tdisplay(progress, progress->last_value, 1);\n+\t\tsprintf(buf, \", %s.\\n\", msg);\n+\t\tdisplay(progress, progress->last_value, buf);\n \t}\n \tclear_progress_signal();\n \tfree(progress->throughput);\ndiff --git a/progress.h b/progress.h\nindex 3912969..611e4c4 100644\n--- a/progress.h\n+++ b/progress.h\n@@ -9,5 +9,6 @@ struct progress *start_progress(const char *title, unsigned total);\n struct progress *start_progress_delay(const char *title, unsigned total,\n \t\t\t\t       unsigned percent_treshold, unsigned delay);\n void stop_progress(struct progress **progress);\n+void stop_progress_msg(struct progress **progress, const char *msg);\n \n #endif\n"}]}