Skip to content

Avoid rescanning casks when none are outdated - #24040

Open
joseph1020 wants to merge 1 commit into
Homebrew:mainfrom
joseph1020:avoid-empty-cask-rescan
Open

joseph1020 wants to merge 1 commit into
Homebrew:mainfrom
joseph1020:avoid-empty-cask-rescan

Conversation

@joseph1020

Copy link
Copy Markdown
Contributor

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

When brew upgrade runs without named casks, the cask prefetch path checks the installed casks for outdated packages before the actual upgrade step.

If no outdated casks are found, prefetch_outdated_casks! currently returns false. The caller treats that the same as a failed or unavailable prefetch and falls back to upgrade_outdated_casks!, which scans the installed casks again.

This means a no-op cask upgrade traverses the installed Cask set twice.

This change treats an empty outdated-cask result as a successful prefetch. When the prefetched cask list is empty, the upgrade step now returns without rescanning the installed Casks. Cases where casks were discovered but cannot be prefetched, such as manual-installer casks, continue to use the existing fallback path.

I noticed this while investigating repeated load-time Cask DSL warnings. With installed third-party casks that emit deprecation warnings, both:

brew upgrade --no-ask

and:

brew upgrade --cask --no-ask

emitted the same warning set twice when there were no outdated casks. After this change, the warning set is emitted once.

A regression test verifies that Cask::Upgrade.outdated_casks is called only once when cask prefetch finds nothing to upgrade.

The test was added before the implementation change and failed because Cask::Upgrade.outdated_casks was called twice. It passes after the change.

Local verification:

./bin/brew tests --only=cmd/upgrade

./bin/brew typecheck

./bin/brew tests --online --changed

./bin/brew style --changed --fix

./bin/brew lgtm --online

git diff --check

All passed successfully.

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI/LLM disclosure: I used ChatGPT (GPT-5.6 Sol) to help trace the duplicate Cask-loading path, review the prefetch/fallback control flow, and draft the regression test and PR description. I manually reproduced the duplicate Cask loading, reviewed the changes, confirmed the regression test failed before the implementation change and passed afterwards, verified the real brew upgrade --cask --no-ask behaviour changed from two installed-Cask warning sets to one, and ran the Homebrew validation commands listed above. I will answer maintainer questions and review comments myself without AI/LLM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant