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
)
18 sprintf(hex
, "%02x", i
);
19 while ((de
= readdir(dir
)) != NULL
) {
20 unsigned char sha1
[20];
21 if (strlen(de
->d_name
) != 38)
23 memcpy(hex
+2, de
->d_name
, 38);
24 if (get_sha1_hex(hex
, sha1
))
26 if (!has_sha1_pack(sha1
))
28 memcpy(pathname
+ len
, de
->d_name
, 38);
30 printf("rm -f %s\n", pathname
);
31 else if (unlink(pathname
) < 0)
32 error("unable to unlink %s", pathname
);
33 display_progress(progress
, i
+ 1);
39 void prune_packed_objects(int opts
)
42 static char pathname
[PATH_MAX
];
43 const char *dir
= get_object_directory();
44 int len
= strlen(dir
);
47 progress
= start_progress_delay("Removing duplicate objects",
50 if (len
> PATH_MAX
- 42)
51 die("impossible object directory");
52 memcpy(pathname
, dir
, len
);
53 if (len
&& pathname
[len
-1] != '/')
54 pathname
[len
++] = '/';
55 for (i
= 0; i
< 256; i
++) {
58 display_progress(progress
, i
+ 1);
59 sprintf(pathname
+ len
, "%02x/", i
);
60 d
= opendir(pathname
);
63 prune_dir(i
, d
, pathname
, len
+ 3, opts
);
66 stop_progress(&progress
);
69 int cmd_prune_packed(int argc
, const char **argv
, const char *prefix
)
74 for (i
= 1; i
< argc
; i
++) {
75 const char *arg
= argv
[i
];
78 if (!strcmp(arg
, "-n"))
80 else if (!strcmp(arg
, "-q"))
83 usage(prune_packed_usage
);
86 /* Handle arguments here .. */
87 usage(prune_packed_usage
);
89 prune_packed_objects(opts
);