Merge branch 'jk/blame-contents-with-arbitrary-commit'
[alt-git.git] / prune-packed.c
blobd2813f6a40547035daaff40fcd0bc296c0832cca
1 #include "git-compat-util.h"
2 #include "object-store.h"
3 #include "packfile.h"
4 #include "progress.h"
5 #include "prune-packed.h"
7 static struct progress *progress;
9 static int prune_subdir(unsigned int nr, const char *path, void *data)
11 int *opts = data;
12 display_progress(progress, nr + 1);
13 if (!(*opts & PRUNE_PACKED_DRY_RUN))
14 rmdir(path);
15 return 0;
18 static int prune_object(const struct object_id *oid, const char *path,
19 void *data)
21 int *opts = data;
23 if (!has_object_pack(oid))
24 return 0;
26 if (*opts & PRUNE_PACKED_DRY_RUN)
27 printf("rm -f %s\n", path);
28 else
29 unlink_or_warn(path);
30 return 0;
33 void prune_packed_objects(int opts)
35 if (opts & PRUNE_PACKED_VERBOSE)
36 progress = start_delayed_progress(_("Removing duplicate objects"), 256);
38 for_each_loose_file_in_objdir(get_object_directory(),
39 prune_object, NULL, prune_subdir, &opts);
41 /* Ensure we show 100% before finishing progress */
42 display_progress(progress, 256);
43 stop_progress(&progress);