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