Skip to content

Add progress bar to cache clean and show removal summary#1616

Merged
j178 merged 4 commits intoj178:masterfrom
shaanmajid:feat/cache-clean-summary
Feb 10, 2026
Merged

Add progress bar to cache clean and show removal summary#1616
j178 merged 4 commits intoj178:masterfrom
shaanmajid:feat/cache-clean-summary

Conversation

@shaanmajid
Copy link
Collaborator

Summary

  • Print Cleaning <path> before deletion starts for immediate feedback
  • Print Removed N files (X.X MiB) after completion
  • Extract shared DirStats struct from cache_size for reuse
  • Fix human_readable_bytes(0) returning NaN
  • Silence spurious fix_permissions error when Go cache doesn't exist
  • Standardize output formatting across cache commands (consistent spacing, styling, remove backticks)

Extract a shared `DirStats { file_count, total_bytes }` struct and
replace `dir_size_bytes` with `dir_stats` that returns full stats via
`walkdir::try_fold`. Error handling now propagates filesystem errors
instead of silently ignoring them. `dir_size_bytes` is retained as a
backward-compatible wrapper for existing call sites.
@shaanmajid shaanmajid force-pushed the feat/cache-clean-summary branch from b310aa2 to a53a46a Compare February 9, 2026 22:54
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 93.16770% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.75%. Comparing base (8fdc71d) to head (a13d144).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/cli/cache_clean.rs 90.75% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1616      +/-   ##
==========================================
+ Coverage   91.74%   91.75%   +0.01%     
==========================================
  Files          96       96              
  Lines       18637    18783     +146     
==========================================
+ Hits        17098    17235     +137     
- Misses       1539     1548       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 9, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (23.8 MiB → 23.8 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 66.6KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.2KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.5KiB              prek prek::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 25.0KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.8KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.2KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.4KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.0KiB              prek prek::hook::HookBuilder::build::{{closure}}
38.6%  91.6%  9.2MiB                   And 21022 smaller methods. Use -n N to show more.
42.1% 100.0% 10.0MiB                   .text section size, the file size is 23.8MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 71.2KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 66.4KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.1KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.7KiB              prek prek::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 25.0KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.8KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.2KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.4KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.0KiB              prek prek::hook::HookBuilder::build::{{closure}}
38.6%  91.6%  9.2MiB                   And 21030 smaller methods. Use -n N to show more.
42.1% 100.0% 10.0MiB                   .text section size, the file size is 23.8MiB

@shaanmajid shaanmajid marked this pull request as ready for review February 9, 2026 23:10
@shaanmajid shaanmajid requested a review from j178 as a code owner February 9, 2026 23:10
After cleaning the cache, print a summary line showing the number of
files removed and total reclaimed size (e.g. "Removed 42 files (3.2MiB)").
Symlinks are counted and removed without following their targets.
The fix_permissions call now silences the expected NotFound error when
the Go module cache directory does not exist.
@shaanmajid shaanmajid force-pushed the feat/cache-clean-summary branch from a53a46a to 64e1bfd Compare February 9, 2026 23:45
Print "Cleaning <path>" before deletion for immediate user feedback.
Add space before size units (e.g. "3.2 MiB" not "3.2MiB") across
cache clean, cache gc, and cache size. Style the full size+unit token
consistently. Bold "Nothing to clean" to match cache gc. Remove
markdown-style backticks from terminal output. Always print removal
summary even when cache contains no files.
@shaanmajid shaanmajid force-pushed the feat/cache-clean-summary branch from 64e1bfd to 7806425 Compare February 10, 2026 00:38
@shaanmajid shaanmajid added the enhancement New feature or request label Feb 10, 2026
@j178 j178 requested a review from Copilot February 10, 2026 03:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds more informative, standardized output for cache cleanup operations in prek, including progress feedback and a removal summary, while refactoring shared directory-stat logic and improving size formatting robustness.

Changes:

  • Update cache clean to print a “Cleaning …” line before deletion and a “Removed N files (X.X UNIT)” summary after completion.
  • Extract reusable DirStats + dir_stats() from cache_size, and fix human_readable_bytes(0) to avoid NaN.
  • Normalize output formatting/spacing across cache commands and update integration-test snapshot filtering accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/prek/tests/common/mod.rs Expands size regex filters and adds a dedicated filter helper for cache clean summary output.
crates/prek/tests/cache.rs Updates cache clean snapshots and seeds cache contents to exercise the new summary output.
crates/prek/src/cli/cache_size.rs Introduces DirStats/dir_stats, fixes human_readable_bytes(0), and adds unit tests.
crates/prek/src/cli/cache_gc.rs Adjusts removal summary formatting to include consistent spacing between value and unit.
crates/prek/src/cli/cache_clean.rs Implements “Cleaning …” pre-delete output, removal summary with counts/bytes, and silences missing Go cache permission-fix error.

@j178 j178 force-pushed the feat/cache-clean-summary branch from 4e10511 to a13d144 Compare February 10, 2026 10:12
@j178 j178 changed the title Add removal summary to cache clean output Add progress bar to cache clean and show removal summary Feb 10, 2026
@j178
Copy link
Owner

j178 commented Feb 10, 2026

Thank you!

@j178 j178 merged commit 2865d37 into j178:master Feb 10, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants