]>
Commit | Line | Data |
---|---|---|
9460fd48 DL |
1 | #include "object-store.h" |
2 | #include "packfile.h" | |
3 | #include "progress.h" | |
4 | #include "prune-packed.h" | |
5 | ||
6 | static struct progress *progress; | |
7 | ||
8 | static int prune_subdir(unsigned int nr, const char *path, void *data) | |
9 | { | |
10 | int *opts = data; | |
11 | display_progress(progress, nr + 1); | |
12 | if (!(*opts & PRUNE_PACKED_DRY_RUN)) | |
13 | rmdir(path); | |
14 | return 0; | |
15 | } | |
16 | ||
17 | static int prune_object(const struct object_id *oid, const char *path, | |
18 | void *data) | |
19 | { | |
20 | int *opts = data; | |
21 | ||
22 | if (!has_object_pack(oid)) | |
23 | return 0; | |
24 | ||
25 | if (*opts & PRUNE_PACKED_DRY_RUN) | |
26 | printf("rm -f %s\n", path); | |
27 | else | |
28 | unlink_or_warn(path); | |
29 | return 0; | |
30 | } | |
31 | ||
32 | void prune_packed_objects(int opts) | |
33 | { | |
34 | if (opts & PRUNE_PACKED_VERBOSE) | |
35 | progress = start_delayed_progress(_("Removing duplicate objects"), 256); | |
36 | ||
37 | for_each_loose_file_in_objdir(get_object_directory(), | |
38 | prune_object, NULL, prune_subdir, &opts); | |
39 | ||
40 | /* Ensure we show 100% before finishing progress */ | |
41 | display_progress(progress, 256); | |
42 | stop_progress(&progress); | |
43 | } |