git
/
prune-packed.c
46 строк · 1.0 Кб
1#include "git-compat-util.h"2#include "environment.h"3#include "gettext.h"4#include "object-store-ll.h"5#include "packfile.h"6#include "progress.h"7#include "prune-packed.h"8
9static struct progress *progress;10
11static int prune_subdir(unsigned int nr, const char *path, void *data)12{
13int *opts = data;14display_progress(progress, nr + 1);15if (!(*opts & PRUNE_PACKED_DRY_RUN))16rmdir(path);17return 0;18}
19
20static int prune_object(const struct object_id *oid, const char *path,21void *data)22{
23int *opts = data;24
25if (!has_object_pack(oid))26return 0;27
28if (*opts & PRUNE_PACKED_DRY_RUN)29printf("rm -f %s\n", path);30else31unlink_or_warn(path);32return 0;33}
34
35void prune_packed_objects(int opts)36{
37if (opts & PRUNE_PACKED_VERBOSE)38progress = start_delayed_progress(_("Removing duplicate objects"), 256);39
40for_each_loose_file_in_objdir(get_object_directory(),41prune_object, NULL, prune_subdir, &opts);42
43/* Ensure we show 100% before finishing progress */44display_progress(progress, 256);45stop_progress(&progress);46}
47