@@ -29,6 +29,7 @@ pub struct RegistryQueryer<'a> {
29
29
pub registry : & ' a mut ( dyn Registry + ' a ) ,
30
30
replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
31
31
try_to_use : & ' a HashSet < PackageId > ,
32
+ prefer_patch_deps : & ' a HashMap < InternedString , HashSet < Dependency > > ,
32
33
/// If set the list of dependency candidates will be sorted by minimal
33
34
/// versions first. That allows `cargo update -Z minimal-versions` which will
34
35
/// specify minimum dependency versions to be used.
@@ -49,12 +50,14 @@ impl<'a> RegistryQueryer<'a> {
49
50
registry : & ' a mut dyn Registry ,
50
51
replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
51
52
try_to_use : & ' a HashSet < PackageId > ,
53
+ prefer_patch_deps : & ' a HashMap < InternedString , HashSet < Dependency > > ,
52
54
minimal_versions : bool ,
53
55
) -> Self {
54
56
RegistryQueryer {
55
57
registry,
56
58
replacements,
57
59
try_to_use,
60
+ prefer_patch_deps,
58
61
minimal_versions,
59
62
registry_cache : HashMap :: new ( ) ,
60
63
summary_cache : HashMap :: new ( ) ,
@@ -164,14 +167,22 @@ impl<'a> RegistryQueryer<'a> {
164
167
}
165
168
}
166
169
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
+ } ;
171
182
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 ( ) ;
175
186
match previous_cmp {
176
187
Ordering :: Equal => {
177
188
let cmp = a. version ( ) . cmp ( b. version ( ) ) ;
0 commit comments