4 #include "parse-options.h"
7 static const char * const prune_packed_usage
[] = {
8 N_("git prune-packed [-n | --dry-run] [-q | --quiet]"),
12 static struct progress
*progress
;
14 static int prune_subdir(unsigned int nr
, const char *path
, void *data
)
17 display_progress(progress
, nr
+ 1);
18 if (!(*opts
& PRUNE_PACKED_DRY_RUN
))
23 static int prune_object(const struct object_id
*oid
, const char *path
,
28 if (!has_sha1_pack(oid
->hash
))
31 if (*opts
& PRUNE_PACKED_DRY_RUN
)
32 printf("rm -f %s\n", path
);
38 void prune_packed_objects(int opts
)
40 if (opts
& PRUNE_PACKED_VERBOSE
)
41 progress
= start_progress_delay(_("Removing duplicate objects"),
44 for_each_loose_file_in_objdir(get_object_directory(),
45 prune_object
, NULL
, prune_subdir
, &opts
);
47 /* Ensure we show 100% before finishing progress */
48 display_progress(progress
, 256);
49 stop_progress(&progress
);
52 int cmd_prune_packed(int argc
, const char **argv
, const char *prefix
)
54 int opts
= isatty(2) ? PRUNE_PACKED_VERBOSE
: 0;
55 const struct option prune_packed_options
[] = {
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
),
63 argc
= parse_options(argc
, argv
, prefix
, prune_packed_options
,
64 prune_packed_usage
, 0);
66 prune_packed_objects(opts
);