@@ -40,6 +40,8 @@ defmodule Mix.Config do
4040 @ doc """
4141 Configures the given application.
4242
43+ Keyword lists are always deep merged.
44+
4345 ## Examples
4446
4547 The given `opts` are merged into the existing configuration
@@ -69,6 +71,8 @@ defmodule Mix.Config do
6971 @ doc """
7072 Configures the given key for the given application.
7173
74+ Keyword lists are always deep merged.
75+
7276 ## Examples
7377
7478 The given `opts` are merged into the existing values for `key`
@@ -91,8 +95,7 @@ defmodule Mix.Config do
9195 quote do
9296 var! ( config , Mix.Config ) =
9397 Mix.Config . merge ( var! ( config , Mix.Config ) ,
94- [ { unquote ( app ) , [ { unquote ( key ) , unquote ( opts ) } ] } ] ,
95- fn _app , _key , v1 , v2 -> Keyword . merge ( v1 , v2 ) end )
98+ [ { unquote ( app ) , [ { unquote ( key ) , unquote ( opts ) } ] } ] )
9699 end
97100 end
98101
@@ -116,7 +119,7 @@ defmodule Mix.Config do
116119 defmacro import_config ( file ) do
117120 quote do
118121 var! ( config , Mix.Config ) =
119- Mix.Config . read_wildcard! ( Path . expand ( unquote ( file ) , __DIR__ ) , var! ( config , Mix.Config ) )
122+ Mix.Config . read_wildcard! ( var! ( config , Mix.Config ) , Path . expand ( unquote ( file ) , __DIR__ ) )
120123 end
121124 end
122125
@@ -142,7 +145,7 @@ defmodule Mix.Config do
142145 @ doc """
143146 Reads many configuration files given by wildcard into a single config.
144147 """
145- def read_wildcard! ( path , config ) do
148+ def read_wildcard! ( config , path ) do
146149 paths = case Path . wildcard ( path ) do
147150 [ ] -> [ path ]
148151 o -> o
@@ -201,34 +204,15 @@ defmodule Mix.Config do
201204 """
202205 def merge ( config1 , config2 ) do
203206 Keyword . merge ( config1 , config2 , fn _ , app1 , app2 ->
204- Keyword . merge ( app1 , app2 )
207+ Keyword . merge ( app1 , app2 , & deep_merge / 3 )
205208 end )
206209 end
207210
208- @ doc """
209- Merges two configurations.
210-
211- The configuration of each application is merged together
212- and a callback is invoked in case of conflicts receiving
213- the app, the conflicting key and both values. It must return
214- a value that will be used as part of the conflict resolution.
215-
216- ## Examples
217-
218- iex> Mix.Config.merge([app: [k: :v1]], [app: [k: :v2]],
219- ...> fn app, k, v1, v2 -> {app, k, v1, v2} end)
220- [app: [k: {:app, :k, :v1, :v2}]]
221-
222- """
223- def merge ( config1 , config2 , callback ) do
224- Keyword . merge ( config1 , config2 , fn app , app1 , app2 ->
225- Keyword . merge ( app1 , app2 , fn k , v1 , v2 ->
226- if v1 == v2 do
227- v1
228- else
229- callback . ( app , k , v1 , v2 )
230- end
231- end )
232- end )
211+ defp deep_merge ( _key , value1 , value2 ) do
212+ if Keyword . keyword? ( value1 ) and Keyword . keyword? ( value2 ) do
213+ Keyword . merge ( value1 , value2 , & deep_merge / 3 )
214+ else
215+ value2
216+ end
233217 end
234218end
0 commit comments