Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gc: add dry option and return num removed #441

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/dvc_data/hashfile/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def gc(
jobs: Optional[int] = None,
cache_odb: Optional["HashFileDB"] = None,
shallow: bool = True,
dry: bool = False,
):
from dvc_objects.errors import ObjectDBPermissionError

Expand All @@ -35,7 +36,7 @@ def _is_dir_hash(_hash):

return _hash.endswith(HASH_DIR_SUFFIX)

removed = False
num_removed = 0

dir_paths = []
file_paths = []
Expand All @@ -53,7 +54,8 @@ def _is_dir_hash(_hash):

for paths in (dir_paths, file_paths):
if paths:
removed = True
odb.fs.remove(paths)
num_removed += len(paths)
if not dry:
odb.fs.remove(paths)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could put some logging here in debug mode (or even info if you passed dry?
Or is the list of things to be removed logged elsewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't track down where, but it looks like it is already logged:

$ dvc gc -v --all-commits --all-branches --all-tags
2023-09-15 10:54:20,087 DEBUG: v3.19.1.dev20+gbf2af8639.d20230915, CPython 3.11.5 on macOS-13.5-arm64-arm-64bit
2023-09-15 10:54:20,087 DEBUG: command: /Users/dave/micromamba/envs/dvc-test/bin/dvc gc -v --all-commits --all-branches --all-tags
2023-09-15 10:54:20,288 WARNING: This will remove all cache except items used in the workspace and all git commits of the current repo.
Are you sure you want to proceed? [y/n]: y
2023-09-15 10:54:22,624 DEBUG: Estimated remote size: 256 files
2023-09-15 10:54:22,625 DEBUG: Removing '/Users/dave/repo/.dvc/cache/files/md5/91/52ab3f172b3e23fd6b1a3ab0e1d150'
Removed 1 objects from repo cache.
2023-09-15 10:54:22,625 DEBUG: Estimated remote size: 256 files
No unused 'local' cache to remove.
2023-09-15 10:54:22,625 DEBUG: Estimated remote size: 256 files
2023-09-15 10:54:22,625 DEBUG: '/Users/dave/repo/.dvc/cache/files/md5/5f/b7ba7e8447a836e774b66155f5776a' doesn't look like a cache file, skipping
No unused 'legacy' cache to remove.


return removed
return num_removed