|
1 | 1 | #include "builtin.h" |
2 | | -#include "cache.h" |
3 | | -#include "progress.h" |
4 | 2 | #include "parse-options.h" |
5 | | -#include "packfile.h" |
6 | | -#include "object-store.h" |
| 3 | +#include "prune-packed.h" |
7 | 4 |
|
8 | 5 | static const char * const prune_packed_usage[] = { |
9 | 6 | N_("git prune-packed [-n | --dry-run] [-q | --quiet]"), |
10 | 7 | NULL |
11 | 8 | }; |
12 | 9 |
|
13 | | -static struct progress *progress; |
14 | | - |
15 | | -static int prune_subdir(unsigned int nr, const char *path, void *data) |
16 | | -{ |
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 | | - |
24 | | -static int prune_object(const struct object_id *oid, const char *path, |
25 | | - void *data) |
26 | | -{ |
27 | | - int *opts = data; |
28 | | - |
29 | | - if (!has_object_pack(oid)) |
30 | | - return 0; |
31 | | - |
32 | | - if (*opts & PRUNE_PACKED_DRY_RUN) |
33 | | - printf("rm -f %s\n", path); |
34 | | - else |
35 | | - unlink_or_warn(path); |
36 | | - return 0; |
37 | | -} |
38 | | - |
39 | | -void prune_packed_objects(int opts) |
40 | | -{ |
41 | | - if (opts & PRUNE_PACKED_VERBOSE) |
42 | | - progress = start_delayed_progress(_("Removing duplicate objects"), 256); |
43 | | - |
44 | | - for_each_loose_file_in_objdir(get_object_directory(), |
45 | | - prune_object, NULL, prune_subdir, &opts); |
46 | | - |
47 | | - /* Ensure we show 100% before finishing progress */ |
48 | | - display_progress(progress, 256); |
49 | | - stop_progress(&progress); |
50 | | -} |
51 | | - |
52 | 10 | int cmd_prune_packed(int argc, const char **argv, const char *prefix) |
53 | 11 | { |
54 | 12 | int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0; |
|
0 commit comments