{"thread":{"id":"10373","subject":"[PATCH] Teach prune-packed to use the standard progress meter","startedAt":"2007-10-19T04:11:47Z","lastAt":"2007-10-19T04:11:47Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"56514","messageId":"20071019041147.GA16408@spearce.org","threadId":"10373","inReplyTo":null,"subject":"[PATCH] Teach prune-packed to use the standard progress meter","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-10-19T04:11:47Z","receivedAt":"2007-10-19T04:11:47Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Rather than reimplementing the progress meter logic and always\nshowing 100 lines of output while pruning already packed objects\nwe now use a delayed progress meter and only show it if there are\nenough objects to make us take a little while.\n\nMost users won't see the message anymore as it usually doesn't take\nvery long to delete the already packed loose objects.  This neatens\nthe output of a git-gc or git-repack execution, which is especially\nimportant for a `git gc --auto` triggered from within another\ncommand.\n\nWe perform the display_progress() call from within the very innermost\nloop in case we spend more than 1 second within any single object\ndirectory.  This ensures that a progress_update event from the\ntimer will still trigger in a timely fashion and allow the user to\nsee the progress meter.\n\nWhile I'm in here I changed the message to be more descriptive of\nits actual task.  \"Deleting unused objects\" is a little scary for\nnew users as they wonder where these unused objects came from and\nhow they should avoid them.  Truth is these objects aren't unused\nin the sense of what git-prune would call a dangling object, these\nare used but are just duplicates of things we have already stored\nin a packfile.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n On top of np/progress topic.  I kicked around a few different\n changes for the progress title but finally settled on this one.\n Improvement suggestions welcome.\n\n builtin-prune-packed.c |   15 +++++++++++----\n 1 files changed, 11 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-prune-packed.c b/builtin-prune-packed.c\nindex 9777300..015c8bb 100644\n--- a/builtin-prune-packed.c\n+++ b/builtin-prune-packed.c\n@@ -1,5 +1,6 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"progress.h\"\n \n static const char prune_packed_usage[] =\n \"git-prune-packed [-n] [-q]\";\n@@ -7,6 +8,8 @@ static const char prune_packed_usage[] =\n #define DRY_RUN 01\n #define VERBOSE 02\n \n+static struct progress progress;\n+\n static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)\n {\n \tstruct dirent *de;\n@@ -23,6 +26,8 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)\n \t\tif (!has_sha1_pack(sha1, NULL))\n \t\t\tcontinue;\n \t\tmemcpy(pathname + len, de->d_name, 38);\n+\t\tif (opts == VERBOSE)\n+\t\t\tdisplay_progress(&progress, i + 1);\n \t\tif (opts & DRY_RUN)\n \t\t\tprintf(\"rm -f %s\\n\", pathname);\n \t\telse if (unlink(pathname) < 0)\n@@ -39,6 +44,11 @@ void prune_packed_objects(int opts)\n \tconst char *dir = get_object_directory();\n \tint len = strlen(dir);\n \n+\tif (opts == VERBOSE)\n+\t\tstart_progress_delay(&progress,\n+\t\t\t\"Removing duplicate objects\",\n+\t\t\t256, 95, 2);\n+\n \tif (len > PATH_MAX - 42)\n \t\tdie(\"impossible object directory\");\n \tmemcpy(pathname, dir, len);\n@@ -49,16 +59,13 @@ void prune_packed_objects(int opts)\n \n \t\tsprintf(pathname + len, \"%02x/\", i);\n \t\td = opendir(pathname);\n-\t\tif (opts == VERBOSE && (d || i == 255))\n-\t\t\tfprintf(stderr, \"Removing unused objects %d%%...\\015\",\n-\t\t\t\t((i+1) * 100) / 256);\n \t\tif (!d)\n \t\t\tcontinue;\n \t\tprune_dir(i, d, pathname, len + 3, opts);\n \t\tclosedir(d);\n \t}\n \tif (opts == VERBOSE)\n-\t\tfprintf(stderr, \"\\nDone.\\n\");\n+\t\tstop_progress(&progress);\n }\n \n int cmd_prune_packed(int argc, const char **argv, const char *prefix)\n-- \n1.5.3.4.1249.g895be\n"}]}