Repository navigation
Conversation
Mix checks the lock of every Git dependency on every command, which spawned git twice per dependency (~19ms on macOS). The revision is now read from a detached .git/HEAD and the origin from a plain url under [remote "origin"] in .git/config, which is the state Mix leaves checkouts in. Each falls back to git independently for anything else (symbolic HEAD, includes, worktree config, GIT_CONFIG* environment variables, quotes, escapes, comments, line continuations, several urls). Closes elixir-lang#16040
josevalim
reviewed
Oct 31, 2026
josevalim
left a comment
Member
There was a problem hiding this comment.
Thank you, some comments inline! I am afraid we should probably only read the HEAD instead.
| defp read_rev(git_dir) do | ||
| with {:ok, head} <- File.read(Path.join(git_dir, "HEAD")), | ||
| rev = String.trim_trailing(head), | ||
| true <- rev =~ ~r/\A([0-9a-f]{40}|[0-9a-f]{64})\z/ do |
Member
There was a problem hiding this comment.
Why do we need this validation? Can it ever be a non-valid ref?
| end | ||
| end | ||
|
|
||
| defp read_origin(git_dir) do |
Member
There was a problem hiding this comment.
Hrm, there is too much going on in here and I feel we are going to have more pitfalls. If we can't easily get the URL, then I am afraid we will need to use the git CLI indeed.
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.
Closes #16040.
Mix.SCM.Git.lock_status/1spawned git twice per Git dependency on every Mix command (~19ms per dependency on macOS). Now the revision is read from a detached.git/HEAD, and the origin from a plainurlunder[remote "origin"]in.git/config. That is the state Mix leaves its checkouts in.Each value falls back to git on its own for anything else, so the answer never differs from git's. Fallback cases: symbolic HEAD, includes,
config.worktree,GIT_CONFIG*environment variables, quotes, escapes, comments, line continuations, several urls.Checked against git 2.54 with a differential test covering ~80 config, HEAD and environment variants. The unusual configs are also part of the new tests, which compare
lock_status/1againstgit config remote.origin.url.Phoenix app with git dependencies on phoenix and phoenix_live_view:
lock_status/1goes from 19ms to 85µs per dependency.