5 static const char prune_packed_usage[] =
6 "git-prune-packed [-n] [-q]";
11 static struct progress *progress;
13 static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
19 display_progress(progress, i + 1);
21 sprintf(hex, "%02x", i);
22 while ((de = readdir(dir)) != NULL) {
23 unsigned char sha1[20];
24 if (strlen(de->d_name) != 38)
26 memcpy(hex+2, de->d_name, 38);
27 if (get_sha1_hex(hex, sha1))
29 if (!has_sha1_pack(sha1, NULL))
31 memcpy(pathname + len, de->d_name, 38);
33 printf("rm -f %s\n", pathname);
34 else if (unlink(pathname) < 0)
35 error("unable to unlink %s", pathname);
41 void prune_packed_objects(int opts)
44 static char pathname[PATH_MAX];
45 const char *dir = get_object_directory();
46 int len = strlen(dir);
49 progress = start_progress_delay("Removing duplicate objects",
52 if (len > PATH_MAX - 42)
53 die("impossible object directory");
54 memcpy(pathname, dir, len);
55 if (len && pathname[len-1] != '/')
56 pathname[len++] = '/';
57 for (i = 0; i < 256; i++) {
60 sprintf(pathname + len, "%02x/", i);
61 d = opendir(pathname);
64 prune_dir(i, d, pathname, len + 3, opts);
68 stop_progress(&progress);
71 int cmd_prune_packed(int argc, const char **argv, const char *prefix)
76 for (i = 1; i < argc; i++) {
77 const char *arg = argv[i];
80 if (!strcmp(arg, "-n"))
82 else if (!strcmp(arg, "-q"))
85 usage(prune_packed_usage);
88 /* Handle arguments here .. */
89 usage(prune_packed_usage);
92 prune_packed_objects(opts);