prune-packed.c 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "object-store.h"
  2. #include "packfile.h"
  3. #include "progress.h"
  4. #include "prune-packed.h"
  5. static struct progress *progress;
  6. static int prune_subdir(unsigned int nr, const char *path, void *data)
  7. {
  8. int *opts = data;
  9. display_progress(progress, nr + 1);
  10. if (!(*opts & PRUNE_PACKED_DRY_RUN))
  11. rmdir(path);
  12. return 0;
  13. }
  14. static int prune_object(const struct object_id *oid, const char *path,
  15. void *data)
  16. {
  17. int *opts = data;
  18. if (!has_object_pack(oid))
  19. return 0;
  20. if (*opts & PRUNE_PACKED_DRY_RUN)
  21. printf("rm -f %s\n", path);
  22. else
  23. unlink_or_warn(path);
  24. return 0;
  25. }
  26. void prune_packed_objects(int opts)
  27. {
  28. if (opts & PRUNE_PACKED_VERBOSE)
  29. progress = start_delayed_progress(_("Removing duplicate objects"), 256);
  30. for_each_loose_file_in_objdir(get_object_directory(),
  31. prune_object, NULL, prune_subdir, &opts);
  32. /* Ensure we show 100% before finishing progress */
  33. display_progress(progress, 256);
  34. stop_progress(&progress);
  35. }