X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=prune-packed.c;h=1e0fc0cd9e9694c0bad54e26367097cc499bf3d2;hb=9e48b389990c0201487e58f3bac32734a59a7e89;hp=41ee2a73bc325dd35831431ddfc176c1a19397df;hpb=f4b3a4c30b5ea3a5de2a2597a3c53266017d02ba;p=git.git diff --git a/prune-packed.c b/prune-packed.c index 41ee2a73..1e0fc0cd 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: usage: git-prune-packed"; +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,14 @@ 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; + if (!rmdir(pathname)) + mkdir(pathname, 0777); } static void prune_packed_objects(void) @@ -41,7 +49,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); } @@ -55,8 +63,11 @@ int main(int argc, char **argv) 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);