{"thread":{"id":"1597","subject":"[PATCH] Call prune-packed from \"git prune\" as well.","startedAt":"2005-08-20T04:41:57Z","lastAt":"2005-08-20T04:41:57Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7582","messageId":"7vll2xqkx6.fsf@assigned-by-dhcp.cox.net","threadId":"1597","inReplyTo":null,"subject":"[PATCH] Call prune-packed from \"git prune\" as well.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-20T04:41:57Z","receivedAt":"2005-08-20T04:41:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Add -n (dryrun) flag to git-prune-packed, and call it from \"git prune\".\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n git-prune-script |    6 ++++--\n prune-packed.c   |   16 ++++++++++++----\n 2 files changed, 16 insertions(+), 6 deletions(-)\n\n51890a64eb152fb914d0dd3676f549ab8d8cc49a\ndiff --git a/git-prune-script b/git-prune-script\n--- a/git-prune-script\n+++ b/git-prune-script\n@@ -3,10 +3,11 @@\n . git-sh-setup-script || die \"Not a git archive\"\n \n dryrun=\n+echo=\n while case \"$#\" in 0) break ;; esac\n do\n     case \"$1\" in\n-    -n) dryrun=echo ;;\n+    -n) dryrun=-n echo=echo ;;\n     --) break ;;\n     -*) echo >&2 \"usage: git-prune-script [ -n ] [ heads... ]\"; exit 1 ;;\n     *)  break ;;\n@@ -20,6 +21,7 @@ sed -ne '/unreachable /{\n     s|\\(..\\)|\\1/|p\n }' | {\n \tcd \"$GIT_OBJECT_DIRECTORY\" || exit\n-\txargs $dryrun rm -f\n+\txargs $echo rm -f\n }\n \n+git-prune-packed $dryrun\ndiff --git a/prune-packed.c b/prune-packed.c\n--- a/prune-packed.c\n+++ b/prune-packed.c\n@@ -1,6 +1,9 @@\n #include \"cache.h\"\n \n-static const char prune_packed_usage[] = \"git-prune-packed (no arguments)\";\n+static const char prune_packed_usage[] =\n+\"git-prune-packed [-n]\";\n+\n+static int dryrun;\n \n static void prune_dir(int i, DIR *dir, char *pathname, int len)\n {\n@@ -18,7 +21,9 @@ static void prune_dir(int i, DIR *dir, c\n \t\tif (!has_sha1_pack(sha1))\n \t\t\tcontinue;\n \t\tmemcpy(pathname + len, de->d_name, 38);\n-\t\tif (unlink(pathname) < 0)\n+\t\tif (dryrun)\n+\t\t\tprintf(\"rm -f %s\\n\", pathname);\n+\t\telse if (unlink(pathname) < 0)\n \t\t\terror(\"unable to unlink %s\", pathname);\n \t}\n }\n@@ -55,8 +60,11 @@ int main(int argc, char **argv)\n \t\tconst char *arg = argv[i];\n \n \t\tif (*arg == '-') {\n-\t\t\t/* Handle flags here .. */\n-\t\t\tusage(prune_packed_usage);\n+\t\t\tif (!strcmp(arg, \"-n\"))\n+\t\t\t\tdryrun = 1;\n+\t\t\telse\n+\t\t\t\tusage(prune_packed_usage);\n+\t\t\tcontinue;\n \t\t}\n \t\t/* Handle arguments here .. */\n \t\tusage(prune_packed_usage);\n"}]}