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

fix _brew completion default cache path #11027

Merged
merged 1 commit into from Apr 5, 2021
Merged

fix _brew completion default cache path #11027

merged 1 commit into from Apr 5, 2021

Conversation

bosr
Copy link
Contributor

@bosr bosr commented Apr 4, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally? (currently not possible on Apple Silicon)
  • Have you successfully run brew typecheck with your changes locally? (currently not possible on Apple Silicon)
  • Have you successfully run brew tests with your changes locally? (currently not possible on Apple Silicon)

Context

When we introduced the completion cache mechanism for zsh about 2 years ago, we needed the path to the installed Taps for checking if the current completion cache should be invalidated. This is the relevant code:

tmp=( ${HOMEBREW_REPOSITORY:-/usr/local/Homebrew}/Library/Taps/*/*/.git/index(om[1]N) )

But as you can see, the fallback value is hardcoded and often incorrect in more and more cases as users move to /opt/homebrew.

Why it matters

The HOMEBREW_REPOSITORY variable is automatically defined in Homebrew scripts, but not outside of those scripts, in particular during execution of shell autocompletion scripts. As a result, the fallback is incorrect if a user has moved to /opt/homebrew, and the cache is invalidated and recreated on each invocation, which is slow and defeats its purpose.

Proposed solution

After discussing with @Rylan12 in #11023 (thanks again), we settled on the following:

on line 50, replace the fallback /usr/local/Homebrew with $(brew --repository)

This was chosen because it always resolves to the correct path (/usr/local/Homebrew or /opt/homebrew), which no available env var like HOMEBREW_PREFIX is able to.

This PR implements this solution on both the _brew file and the erb template file. (edited)

@Bo98
Copy link
Member

Bo98 commented Apr 4, 2021

This file is generated from zsh.erb so you should modify that .erb file too.

@bosr
Copy link
Contributor Author

bosr commented Apr 4, 2021

I'll now rebase on the latest master to avoid the codecov failure.

@bosr
Copy link
Contributor Author

bosr commented Apr 4, 2021

Rebased on the latest master.

@bosr bosr requested a review from Rylan12 April 5, 2021 07:07
Copy link
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Thanks, @bosr!

@Rylan12 Rylan12 merged commit 1d612fb into Homebrew:master Apr 5, 2021
@bosr
Copy link
Contributor Author

bosr commented Apr 5, 2021

Thanks for doing this together

@bosr bosr deleted the fix/zsh-completion branch April 5, 2021 13:37
@github-actions github-actions bot added the outdated PR was locked due to age label May 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants