3 static const char prune_packed_usage
[] =
4 "git-prune-packed [-n]";
8 static void prune_dir(int i
, DIR *dir
, char *pathname
, int len
)
13 sprintf(hex
, "%02x", i
);
14 while ((de
= readdir(dir
)) != NULL
) {
15 unsigned char sha1
[20];
16 if (strlen(de
->d_name
) != 38)
18 memcpy(hex
+2, de
->d_name
, 38);
19 if (get_sha1_hex(hex
, sha1
))
21 if (!has_sha1_pack(sha1
))
23 memcpy(pathname
+ len
, de
->d_name
, 38);
25 printf("rm -f %s\n", pathname
);
26 else if (unlink(pathname
) < 0)
27 error("unable to unlink %s", pathname
);
33 static void prune_packed_objects(void)
36 static char pathname
[PATH_MAX
];
37 const char *dir
= get_object_directory();
38 int len
= strlen(dir
);
40 if (len
> PATH_MAX
- 42)
41 die("impossible object directory");
42 memcpy(pathname
, dir
, len
);
43 if (len
&& pathname
[len
-1] != '/')
44 pathname
[len
++] = '/';
45 for (i
= 0; i
< 256; i
++) {
48 sprintf(pathname
+ len
, "%02x/", i
);
49 d
= opendir(pathname
);
52 prune_dir(i
, d
, pathname
, len
+ 3);
57 int main(int argc
, char **argv
)
61 for (i
= 1; i
< argc
; i
++) {
62 const char *arg
= argv
[i
];
65 if (!strcmp(arg
, "-n"))
68 usage(prune_packed_usage
);
71 /* Handle arguments here .. */
72 usage(prune_packed_usage
);
74 prune_packed_objects();