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