]>
Commit | Line | Data |
---|---|---|
25f38f06 | 1 | #include "builtin.h" |
2396ec85 | 2 | #include "cache.h" |
b5d72f0a | 3 | #include "progress.h" |
7cfe0c98 | 4 | #include "parse-options.h" |
150e3001 | 5 | #include "packfile.h" |
0889aae1 | 6 | #include "object-store.h" |
2396ec85 | 7 | |
7cfe0c98 | 8 | static const char * const prune_packed_usage[] = { |
9c9b4f2f | 9 | N_("git prune-packed [-n | --dry-run] [-q | --quiet]"), |
7cfe0c98 SB |
10 | NULL |
11 | }; | |
51890a64 | 12 | |
dc6a0757 | 13 | static struct progress *progress; |
b5d72f0a | 14 | |
70c49050 | 15 | static int prune_subdir(unsigned int nr, const char *path, void *data) |
2396ec85 | 16 | { |
0d3b7296 JK |
17 | int *opts = data; |
18 | display_progress(progress, nr + 1); | |
19 | if (!(*opts & PRUNE_PACKED_DRY_RUN)) | |
20 | rmdir(path); | |
21 | return 0; | |
22 | } | |
23 | ||
76c1d9a0 | 24 | static int prune_object(const struct object_id *oid, const char *path, |
0d3b7296 JK |
25 | void *data) |
26 | { | |
27 | int *opts = data; | |
2396ec85 | 28 | |
14c3c80c | 29 | if (!has_object_pack(oid)) |
0d3b7296 | 30 | return 0; |
c235d960 | 31 | |
0d3b7296 JK |
32 | if (*opts & PRUNE_PACKED_DRY_RUN) |
33 | printf("rm -f %s\n", path); | |
34 | else | |
35 | unlink_or_warn(path); | |
36 | return 0; | |
2396ec85 LT |
37 | } |
38 | ||
b60daf05 | 39 | void prune_packed_objects(int opts) |
2396ec85 | 40 | { |
af0b4a3b | 41 | if (opts & PRUNE_PACKED_VERBOSE) |
8aade107 | 42 | progress = start_delayed_progress(_("Removing duplicate objects"), 256); |
b5d72f0a | 43 | |
0d3b7296 JK |
44 | for_each_loose_file_in_objdir(get_object_directory(), |
45 | prune_object, NULL, prune_subdir, &opts); | |
2396ec85 | 46 | |
0d3b7296 JK |
47 | /* Ensure we show 100% before finishing progress */ |
48 | display_progress(progress, 256); | |
4d4fcc54 | 49 | stop_progress(&progress); |
2396ec85 LT |
50 | } |
51 | ||
25f38f06 | 52 | int cmd_prune_packed(int argc, const char **argv, const char *prefix) |
2396ec85 | 53 | { |
af0b4a3b | 54 | int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0; |
7cfe0c98 | 55 | const struct option prune_packed_options[] = { |
af0b4a3b NTND |
56 | OPT_BIT('n', "dry-run", &opts, N_("dry run"), |
57 | PRUNE_PACKED_DRY_RUN), | |
58 | OPT_NEGBIT('q', "quiet", &opts, N_("be quiet"), | |
59 | PRUNE_PACKED_VERBOSE), | |
7cfe0c98 SB |
60 | OPT_END() |
61 | }; | |
2396ec85 | 62 | |
7cfe0c98 SB |
63 | argc = parse_options(argc, argv, prefix, prune_packed_options, |
64 | prune_packed_usage, 0); | |
2396ec85 | 65 | |
9b0bd87e RJ |
66 | if (argc > 0) |
67 | usage_msg_opt(_("too many arguments"), | |
68 | prune_packed_usage, | |
69 | prune_packed_options); | |
70 | ||
b60daf05 | 71 | prune_packed_objects(opts); |
2396ec85 LT |
72 | return 0; |
73 | } |