@@ -29,6 +29,7 @@ pub struct RegistryQueryer<'a> {
2929 pub registry : & ' a mut ( dyn Registry + ' a ) ,
3030 replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
3131 try_to_use : & ' a HashSet < PackageId > ,
32+ prefer_patch_deps : & ' a HashMap < InternedString , HashSet < Dependency > > ,
3233 /// If set the list of dependency candidates will be sorted by minimal
3334 /// versions first. That allows `cargo update -Z minimal-versions` which will
3435 /// specify minimum dependency versions to be used.
@@ -49,12 +50,14 @@ impl<'a> RegistryQueryer<'a> {
4950 registry : & ' a mut dyn Registry ,
5051 replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
5152 try_to_use : & ' a HashSet < PackageId > ,
53+ prefer_patch_deps : & ' a HashMap < InternedString , HashSet < Dependency > > ,
5254 minimal_versions : bool ,
5355 ) -> Self {
5456 RegistryQueryer {
5557 registry,
5658 replacements,
5759 try_to_use,
60+ prefer_patch_deps,
5861 minimal_versions,
5962 registry_cache : HashMap :: new ( ) ,
6063 summary_cache : HashMap :: new ( ) ,
@@ -164,14 +167,22 @@ impl<'a> RegistryQueryer<'a> {
164167 }
165168 }
166169
167- // When we attempt versions for a package we'll want to do so in a
168- // sorted fashion to pick the "best candidates" first. Currently we try
169- // prioritized summaries (those in `try_to_use`) and failing that we
170- // list everything from the maximum version to the lowest version.
170+ // When we attempt versions for a package we'll want to do so in a sorted fashion to pick
171+ // the "best candidates" first. Currently we try prioritized summaries (those in
172+ // `try_to_use` or `prefer_patch_deps`) and failing that we list everything from the
173+ // maximum version to the lowest version.
174+ let should_prefer = |package_id : & PackageId | {
175+ self . try_to_use . contains ( package_id)
176+ || self
177+ . prefer_patch_deps
178+ . get ( & package_id. name ( ) )
179+ . map ( |deps| deps. iter ( ) . any ( |d| d. matches_id ( * package_id) ) )
180+ . unwrap_or ( false )
181+ } ;
171182 ret. sort_unstable_by ( |a, b| {
172- let a_in_previous = self . try_to_use . contains ( & a. package_id ( ) ) ;
173- let b_in_previous = self . try_to_use . contains ( & b. package_id ( ) ) ;
174- let previous_cmp = a_in_previous . cmp ( & b_in_previous ) . reverse ( ) ;
183+ let prefer_a = should_prefer ( & a. package_id ( ) ) ;
184+ let prefer_b = should_prefer ( & b. package_id ( ) ) ;
185+ let previous_cmp = prefer_a . cmp ( & prefer_b ) . reverse ( ) ;
175186 match previous_cmp {
176187 Ordering :: Equal => {
177188 let cmp = a. version ( ) . cmp ( b. version ( ) ) ;
0 commit comments