Git fork
at reftables-rust 49 lines 1.1 kB view raw
1#define USE_THE_REPOSITORY_VARIABLE 2 3#include "git-compat-util.h" 4#include "gettext.h" 5#include "object-file.h" 6#include "packfile.h" 7#include "progress.h" 8#include "prune-packed.h" 9#include "repository.h" 10 11static struct progress *progress; 12 13static int prune_subdir(unsigned int nr, const char *path, void *data) 14{ 15 int *opts = data; 16 display_progress(progress, nr + 1); 17 if (!(*opts & PRUNE_PACKED_DRY_RUN)) 18 rmdir(path); 19 return 0; 20} 21 22static int prune_object(const struct object_id *oid, const char *path, 23 void *data) 24{ 25 int *opts = data; 26 27 if (!has_object_pack(the_repository, oid)) 28 return 0; 29 30 if (*opts & PRUNE_PACKED_DRY_RUN) 31 printf("rm -f %s\n", path); 32 else 33 unlink_or_warn(path); 34 return 0; 35} 36 37void prune_packed_objects(int opts) 38{ 39 if (opts & PRUNE_PACKED_VERBOSE) 40 progress = start_delayed_progress(the_repository, 41 _("Removing duplicate objects"), 256); 42 43 for_each_loose_file_in_source(the_repository->objects->sources, 44 prune_object, NULL, prune_subdir, &opts); 45 46 /* Ensure we show 100% before finishing progress */ 47 display_progress(progress, 256); 48 stop_progress(&progress); 49}