Skip to content

GitDownloadStrategy: fix slow repo_valid? by using -C flag#21969

Open
ismail wants to merge 1 commit intoHomebrew:mainfrom
ismail:fix-git-status-work-tree
Open

GitDownloadStrategy: fix slow repo_valid? by using -C flag#21969
ismail wants to merge 1 commit intoHomebrew:mainfrom
ismail:fix-git-status-work-tree

Conversation

@ismail
Copy link
Copy Markdown

@ismail ismail commented Apr 9, 2026

Summary

repo_valid? runs git status -s without specifying -C, so git falls back to the current working directory. If CWD happens to be a large directory (e.g. the user's home directory), this causes git to scan the entire tree, making the call unexpectedly slow.

Fix by using git -C cached_location status -s so git always operates in the correct directory regardless of CWD.

Test plan

  • Verify brew style --fix Library/Homebrew/download_strategy.rb passes
  • Verify brew typecheck passes

Before

Takes more than 10 minutes.

; timeout 10m git --git-dir ~/.cache/Homebrew/helix--git/.git status -s
; echo $?
124

After

; time git -C ~/.cache/Homebrew/helix--git status -s
git -C ~/.cache/Homebrew/helix--git status -  0.00s user 0.01s system 121% cpu 0.007 total
  • 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 (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

@MikeMcQuaid
Copy link
Copy Markdown
Member

@ismail Can you fill out the pull request template please? Can you provide before and after benchmark examples?

Without -C, git falls back to CWD as the work tree. If CWD is a large
directory (e.g. the user's home directory), git status scans the entire
tree, making repo_valid? unexpectedly slow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ismail ismail force-pushed the fix-git-status-work-tree branch from beb833d to ec19ead Compare April 9, 2026 19:36
@ismail ismail changed the title GitDownloadStrategy: fix slow repo_valid? by specifying --work-tree GitDownloadStrategy: fix slow repo_valid? by using -C flag Apr 9, 2026
@ismail
Copy link
Copy Markdown
Author

ismail commented Apr 9, 2026

@ismail Can you fill out the pull request template please? Can you provide before and after benchmark examples?

Thanks, updated.

@ismail ismail requested a review from MikeMcQuaid April 9, 2026 22:22
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.

2 participants