4 static const char prune_packed_usage
[] =
5 "git-prune-packed [-n]";
7 static void prune_dir(int i
, DIR *dir
, char *pathname
, int len
, int dryrun
)
12 sprintf(hex
, "%02x", i
);
13 while ((de
= readdir(dir
)) != NULL
) {
14 unsigned char sha1
[20];
15 if (strlen(de
->d_name
) != 38)
17 memcpy(hex
+2, de
->d_name
, 38);
18 if (get_sha1_hex(hex
, sha1
))
20 if (!has_sha1_pack(sha1
, NULL
))
22 memcpy(pathname
+ len
, de
->d_name
, 38);
24 printf("rm -f %s\n", pathname
);
25 else if (unlink(pathname
) < 0)
26 error("unable to unlink %s", pathname
);
32 void prune_packed_objects(int dryrun
)
35 static char pathname
[PATH_MAX
];
36 const char *dir
= get_object_directory();
37 int len
= strlen(dir
);
39 if (len
> PATH_MAX
- 42)
40 die("impossible object directory");
41 memcpy(pathname
, dir
, len
);
42 if (len
&& pathname
[len
-1] != '/')
43 pathname
[len
++] = '/';
44 for (i
= 0; i
< 256; i
++) {
47 sprintf(pathname
+ len
, "%02x/", i
);
48 d
= opendir(pathname
);
51 prune_dir(i
, d
, pathname
, len
+ 3, dryrun
);
56 int cmd_prune_packed(int argc
, const char **argv
, const char *prefix
)
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
);
75 prune_packed_objects(dryrun
);