abspath.h: move absolute path functions from cache.h
[git/debian.git] / prune-packed.c
blobcff5ad569c7b1b8c6f243cb4fabf159573bb459a
1 #include "cache.h"
2 #include "gettext.h"
3 #include "object-store.h"
4 #include "packfile.h"
5 #include "progress.h"
6 #include "prune-packed.h"
8 static struct progress *progress;
10 static int prune_subdir(unsigned int nr, const char *path, void *data)
12 int *opts = data;
13 display_progress(progress, nr + 1);
14 if (!(*opts & PRUNE_PACKED_DRY_RUN))
15 rmdir(path);
16 return 0;
19 static int prune_object(const struct object_id *oid, const char *path,
20 void *data)
22 int *opts = data;
24 if (!has_object_pack(oid))
25 return 0;
27 if (*opts & PRUNE_PACKED_DRY_RUN)
28 printf("rm -f %s\n", path);
29 else
30 unlink_or_warn(path);
31 return 0;
34 void prune_packed_objects(int opts)
36 if (opts & PRUNE_PACKED_VERBOSE)
37 progress = start_delayed_progress(_("Removing duplicate objects"), 256);
39 for_each_loose_file_in_objdir(get_object_directory(),
40 prune_object, NULL, prune_subdir, &opts);
42 /* Ensure we show 100% before finishing progress */
43 display_progress(progress, 256);
44 stop_progress(&progress);