8 static const char prune_usage[] = "git-prune [-n]";
11 static int prune_object(char *path, const char *filename, const unsigned char *sha1)
17 if (sha1_object_info(sha1, buf, NULL))
21 printf("%s %s\n", sha1_to_hex(sha1), type);
24 unlink(mkpath("%s/%s", path, filename));
29 static int prune_dir(int i, char *path)
31 DIR *dir = opendir(path);
37 while ((de = readdir(dir)) != NULL) {
39 unsigned char sha1[20];
40 int len = strlen(de->d_name);
44 if (de->d_name[1] != '.')
47 if (de->d_name[0] != '.')
51 sprintf(name, "%02x", i);
52 memcpy(name+2, de->d_name, len+1);
53 if (get_sha1_hex(name, sha1) < 0)
57 * Do we know about this object?
58 * It must have been reachable
60 if (lookup_object(sha1))
63 prune_object(path, de->d_name, sha1);
66 fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
72 static void prune_object_dir(const char *path)
75 for (i = 0; i < 256; i++) {
76 static char dir[4096];
77 sprintf(dir, "%s/%02x", path, i);
82 int cmd_prune(int argc, const char **argv, const char *prefix)
87 for (i = 1; i < argc; i++) {
88 const char *arg = argv[i];
89 if (!strcmp(arg, "-n")) {
96 save_commit_buffer = 0;
97 init_revisions(&revs, prefix);
98 mark_reachable_objects(&revs, 1);
100 prune_object_dir(get_object_directory());
103 prune_packed_objects(show_only);