4 #include "parse-options.h"
6 static const char * const prune_packed_usage[] = {
7 N_("git prune-packed [-n | --dry-run] [-q | --quiet]"),
11 static struct progress *progress;
13 static int prune_subdir(int nr, const char *path, void *data)
16 display_progress(progress, nr + 1);
17 if (!(*opts & PRUNE_PACKED_DRY_RUN))
22 static int prune_object(const struct object_id *oid, const char *path,
27 if (!has_sha1_pack(oid->hash))
30 if (*opts & PRUNE_PACKED_DRY_RUN)
31 printf("rm -f %s\n", path);
37 void prune_packed_objects(int opts)
39 if (opts & PRUNE_PACKED_VERBOSE)
40 progress = start_progress_delay(_("Removing duplicate objects"),
43 for_each_loose_file_in_objdir(get_object_directory(),
44 prune_object, NULL, prune_subdir, &opts);
46 /* Ensure we show 100% before finishing progress */
47 display_progress(progress, 256);
48 stop_progress(&progress);
51 int cmd_prune_packed(int argc, const char **argv, const char *prefix)
53 int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
54 const struct option prune_packed_options[] = {
55 OPT_BIT('n', "dry-run", &opts, N_("dry run"),
56 PRUNE_PACKED_DRY_RUN),
57 OPT_NEGBIT('q', "quiet", &opts, N_("be quiet"),
58 PRUNE_PACKED_VERBOSE),
62 argc = parse_options(argc, argv, prefix, prune_packed_options,
63 prune_packed_usage, 0);
65 prune_packed_objects(opts);