Skip to content

Commit f2e6d6a

Browse files
nasercaAlex Naser
andauthored
Parallelize dep lock status checks during deps.loadpaths (#15099)
To make this safe, git.ex's lock_status no longer uses File.cd! (which mutates global process state), instead passing the `:cd` into System.cmd. Co-authored-by: Alex Naser <alex.naser@remote.com>
1 parent a536143 commit f2e6d6a

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

lib/mix/lib/mix/scm/git.ex

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ defmodule Mix.SCM.Git do
7575

7676
cond do
7777
lock_rev = get_lock_rev(lock, opts) ->
78-
File.cd!(opts[:checkout], fn ->
79-
%{origin: origin, rev: rev} = get_rev_info()
78+
%{origin: origin, rev: rev} = get_rev_info(opts[:checkout])
8079

81-
if get_lock_repo(lock) == origin and lock_rev == rev do
82-
:ok
83-
else
84-
:mismatch
85-
end
86-
end)
80+
if get_lock_repo(lock) == origin and lock_rev == rev do
81+
:ok
82+
else
83+
:mismatch
84+
end
8785

8886
is_nil(lock) ->
8987
:mismatch
@@ -333,11 +331,11 @@ defmodule Mix.SCM.Git do
333331
end
334332
end
335333

336-
defp get_rev_info do
334+
defp get_rev_info(dir \\ nil) do
337335
# These commands can fail and we don't want to raise.
338336
origin_command = ["--git-dir=.git", "config", "remote.origin.url"]
339337
rev_command = ["--git-dir=.git", "rev-parse", "--verify", "--quiet", "HEAD"]
340-
opts = cmd_opts([])
338+
opts = if dir, do: cmd_opts(cd: dir), else: cmd_opts([])
341339

342340
with {origin, 0} <- System.cmd("git", origin_command, opts),
343341
{rev, 0} <- System.cmd("git", rev_command, opts) do
@@ -391,13 +389,17 @@ defmodule Mix.SCM.Git do
391389
end
392390
end
393391

394-
# Attempt to set the current working directory by default.
395-
# This addresses an issue changing the working directory when executing from
396-
# within a secondary node since file I/O is done through the main node.
397392
defp cmd_opts(opts) do
398-
case File.cwd() do
399-
{:ok, cwd} -> Keyword.put(opts, :cd, cwd)
400-
_ -> opts
393+
if Keyword.has_key?(opts, :cd) do
394+
opts
395+
else
396+
# Attempt to set the current working directory by default.
397+
# This addresses an issue changing the working directory when executing from
398+
# within a secondary node since file I/O is done through the main node.
399+
case File.cwd() do
400+
{:ok, cwd} -> Keyword.put(opts, :cd, cwd)
401+
_ -> opts
402+
end
401403
end
402404
end
403405

lib/mix/lib/mix/tasks/deps.loadpaths.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ defmodule Mix.Tasks.Deps.Loadpaths do
123123
end
124124

125125
defp deps_check(all, no_compile?) do
126-
all = Enum.map(all, &check_lock/1)
126+
all =
127+
all
128+
|> Task.async_stream(&check_lock/1, ordered: true, timeout: :infinity)
129+
|> Enum.map(fn {:ok, dep} -> dep end)
130+
127131
{not_ok, to_compile} = partition(all, [], [])
128132

129133
cond do

0 commit comments

Comments
 (0)