Avoid rescanning casks when none are outdated - #24040
Open
joseph1020 wants to merge 1 commit into
Open
joseph1020 wants to merge 1 commit into
joseph1020 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
brew benchmarkresults.brewcommands to reproduce the bug?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.
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.