Elijah Newren | 9875058 | 2023-03-21 06:26:04 +0000 | [diff] [blame] | 1 | #include "git-compat-util.h" |
Elijah Newren | 32a8f51 | 2023-03-21 06:26:03 +0000 | [diff] [blame] | 2 | #include "environment.h" |
Elijah Newren | f394e09 | 2023-03-21 06:25:54 +0000 | [diff] [blame] | 3 | #include "gettext.h" |
Elijah Newren | a034e91 | 2023-05-16 06:34:06 +0000 | [diff] [blame] | 4 | #include "object-store-ll.h" |
Denton Liu | 9460fd4 | 2020-03-23 21:07:52 -0400 | [diff] [blame] | 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 | { |
| 13 | int *opts = data; |
| 14 | display_progress(progress, nr + 1); |
| 15 | if (!(*opts & PRUNE_PACKED_DRY_RUN)) |
| 16 | rmdir(path); |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | static int prune_object(const struct object_id *oid, const char *path, |
| 21 | void *data) |
| 22 | { |
| 23 | int *opts = data; |
| 24 | |
| 25 | if (!has_object_pack(oid)) |
| 26 | return 0; |
| 27 | |
| 28 | if (*opts & PRUNE_PACKED_DRY_RUN) |
| 29 | printf("rm -f %s\n", path); |
| 30 | else |
| 31 | unlink_or_warn(path); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | void prune_packed_objects(int opts) |
| 36 | { |
| 37 | if (opts & PRUNE_PACKED_VERBOSE) |
| 38 | progress = start_delayed_progress(_("Removing duplicate objects"), 256); |
| 39 | |
| 40 | for_each_loose_file_in_objdir(get_object_directory(), |
| 41 | prune_object, NULL, prune_subdir, &opts); |
| 42 | |
| 43 | /* Ensure we show 100% before finishing progress */ |
| 44 | display_progress(progress, 256); |
| 45 | stop_progress(&progress); |
| 46 | } |