3 static const char prune_packed_usage[] = "git-prune-packed: usage: git-prune-packed";
5 static void prune_dir(int i, DIR *dir, char *pathname, int len)
10 sprintf(hex, "%02x", i);
11 while ((de = readdir(dir)) != NULL) {
12 unsigned char sha1[20];
13 if (strlen(de->d_name) != 38)
15 memcpy(hex+2, de->d_name, 38);
16 if (get_sha1_hex(hex, sha1))
18 if (!has_sha1_pack(sha1))
20 memcpy(pathname + len, de->d_name, 38);
21 if (unlink(pathname) < 0)
22 error("unable to unlink %s", pathname);
26 static void prune_packed_objects(void)
29 static char pathname[PATH_MAX];
30 const char *dir = get_object_directory();
31 int len = strlen(dir);
33 if (len > PATH_MAX - 42)
34 die("impossible object directory");
35 memcpy(pathname, dir, len);
36 if (len && pathname[len-1] != '/')
37 pathname[len++] = '/';
38 for (i = 0; i < 256; i++) {
41 sprintf(pathname + len, "%02x/", i);
42 d = opendir(pathname);
44 die("unable to open %s", pathname);
45 prune_dir(i, d, pathname, len + 3);
50 int main(int argc, char **argv)
54 for (i = 1; i < argc; i++) {
55 const char *arg = argv[i];
58 /* Handle flags here .. */
59 usage(prune_packed_usage);
61 /* Handle arguments here .. */
62 usage(prune_packed_usage);
64 prune_packed_objects();