X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=prune-packed.c;h=d24b097114ef2610416b106ea9aa2000873924f3;hb=ae448e3854d8b6e7e37aa88fa3917f5dd97f3210;hp=a2f448830c8c89cd19f82f2ec215ad349583777e;hpb=6b7242aa1acc3c7835f80522914ffc4b2e789a29;p=git.git diff --git a/prune-packed.c b/prune-packed.c index a2f44883..d24b0971 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -1,6 +1,9 @@ #include "cache.h" -static const char prune_packed_usage[] = "git-prune-packed (no arguments)"; +static const char prune_packed_usage[] = +"git-prune-packed [-n]"; + +static int dryrun; static void prune_dir(int i, DIR *dir, char *pathname, int len) { @@ -18,9 +21,13 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len) if (!has_sha1_pack(sha1)) continue; memcpy(pathname + len, de->d_name, 38); - if (unlink(pathname) < 0) + if (dryrun) + printf("rm -f %s\n", pathname); + else if (unlink(pathname) < 0) error("unable to unlink %s", pathname); } + pathname[len] = 0; + rmdir(pathname); } static void prune_packed_objects(void) @@ -41,7 +48,7 @@ static void prune_packed_objects(void) sprintf(pathname + len, "%02x/", i); d = opendir(pathname); if (!d) - die("unable to open %s", pathname); + continue; prune_dir(i, d, pathname, len + 3); closedir(d); } @@ -51,16 +58,22 @@ int main(int argc, char **argv) { int i; + setup_git_directory(); + for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (*arg == '-') { - /* Handle flags here .. */ - usage(prune_packed_usage); + if (!strcmp(arg, "-n")) + dryrun = 1; + else + usage(prune_packed_usage); + continue; } /* Handle arguments here .. */ usage(prune_packed_usage); } + sync(); prune_packed_objects(); return 0; }