1#include "builtin.h"2#include "cache.h"3#include "progress.h"4#include "parse-options.h"5#include "packfile.h"6#include "object-store.h"78static const char * const prune_packed_usage[] = {9N_("git prune-packed [-n | --dry-run] [-q | --quiet]"),10NULL11};1213static struct progress *progress;1415static int prune_subdir(unsigned int nr, const char *path, void *data)16{17int *opts = data;18display_progress(progress, nr + 1);19if (!(*opts & PRUNE_PACKED_DRY_RUN))20rmdir(path);21return 0;22}2324static int prune_object(const struct object_id *oid, const char *path,25void *data)26{27int *opts = data;2829if (!has_object_pack(oid))30return 0;3132if (*opts & PRUNE_PACKED_DRY_RUN)33printf("rm -f %s\n", path);34else35unlink_or_warn(path);36return 0;37}3839void prune_packed_objects(int opts)40{41if (opts & PRUNE_PACKED_VERBOSE)42progress = start_delayed_progress(_("Removing duplicate objects"), 256);4344for_each_loose_file_in_objdir(get_object_directory(),45prune_object, NULL, prune_subdir, &opts);4647/* Ensure we show 100% before finishing progress */48display_progress(progress, 256);49stop_progress(&progress);50}5152int cmd_prune_packed(int argc, const char **argv, const char *prefix)53{54int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;55const struct option prune_packed_options[] = {56OPT_BIT('n', "dry-run", &opts, N_("dry run"),57PRUNE_PACKED_DRY_RUN),58OPT_NEGBIT('q', "quiet", &opts, N_("be quiet"),59PRUNE_PACKED_VERBOSE),60OPT_END()61};6263argc = parse_options(argc, argv, prefix, prune_packed_options,64prune_packed_usage, 0);6566prune_packed_objects(opts);67return 0;68}