@@ -5,8 +5,8 @@ use log::{debug, trace};
55use semver:: VersionReq ;
66use url:: Url ;
77
8- use crate :: core:: PackageSet ;
98use crate :: core:: { Dependency , PackageId , Source , SourceId , SourceMap , Summary } ;
9+ use crate :: core:: { InternedString , PackageSet } ;
1010use crate :: sources:: config:: SourceConfigMap ;
1111use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
1212use crate :: util:: { profile, CanonicalUrl , Config } ;
@@ -91,16 +91,13 @@ pub struct PackageRegistry<'cfg> {
9191type LockedMap = HashMap <
9292 // The first level of key-ing done in this hash map is the source that
9393 // dependencies come from, identified by a `SourceId`.
94- SourceId ,
95- HashMap <
96- // This next level is keyed by the name of the package...
97- String ,
98- // ... and the value here is a list of tuples. The first element of each
99- // tuple is a package which has the source/name used to get to this
100- // point. The second element of each tuple is the list of locked
101- // dependencies that the first element has.
102- Vec < ( PackageId , Vec < PackageId > ) > ,
103- > ,
94+ // The next level is keyed by the name of the package...
95+ ( SourceId , InternedString ) ,
96+ // ... and the value here is a list of tuples. The first element of each
97+ // tuple is a package which has the source/name used to get to this
98+ // point. The second element of each tuple is the list of locked
99+ // dependencies that the first element has.
100+ Vec < ( PackageId , Vec < PackageId > ) > ,
104101> ;
105102
106103#[ derive( PartialEq , Eq , Clone , Copy ) ]
@@ -198,17 +195,20 @@ impl<'cfg> PackageRegistry<'cfg> {
198195 self . yanked_whitelist . extend ( pkgs) ;
199196 }
200197
198+ /// remove all residual state from previous lock files.
199+ pub fn clear_lock ( & mut self ) {
200+ trace ! ( "clear_lock" ) ;
201+ self . locked = HashMap :: new ( ) ;
202+ }
203+
201204 pub fn register_lock ( & mut self , id : PackageId , deps : Vec < PackageId > ) {
202205 trace ! ( "register_lock: {}" , id) ;
203206 for dep in deps. iter ( ) {
204207 trace ! ( "\t -> {}" , dep) ;
205208 }
206- let sub_map = self
209+ let sub_vec = self
207210 . locked
208- . entry ( id. source_id ( ) )
209- . or_insert_with ( HashMap :: new) ;
210- let sub_vec = sub_map
211- . entry ( id. name ( ) . to_string ( ) )
211+ . entry ( ( id. source_id ( ) , id. name ( ) ) )
212212 . or_insert_with ( Vec :: new) ;
213213 sub_vec. push ( ( id, deps) ) ;
214214 }
@@ -639,8 +639,7 @@ fn lock(
639639 summary : Summary ,
640640) -> Summary {
641641 let pair = locked
642- . get ( & summary. source_id ( ) )
643- . and_then ( |map| map. get ( & * summary. name ( ) ) )
642+ . get ( & ( summary. source_id ( ) , summary. name ( ) ) )
644643 . and_then ( |vec| vec. iter ( ) . find ( |& & ( id, _) | id == summary. package_id ( ) ) ) ;
645644
646645 trace ! ( "locking summary of {}" , summary. package_id( ) ) ;
@@ -729,8 +728,7 @@ fn lock(
729728 // all known locked packages to see if they match this dependency.
730729 // If anything does then we lock it to that and move on.
731730 let v = locked
732- . get ( & dep. source_id ( ) )
733- . and_then ( |map| map. get ( & * dep. package_name ( ) ) )
731+ . get ( & ( dep. source_id ( ) , dep. package_name ( ) ) )
734732 . and_then ( |vec| vec. iter ( ) . find ( |& & ( id, _) | dep. matches_id ( id) ) ) ;
735733 if let Some ( & ( id, _) ) = v {
736734 trace ! ( "\t second hit on {}" , id) ;
0 commit comments