@@ -6,7 +6,7 @@ use crate::core::{Dependency, PackageId, Source, SourceId, SourceMap, Summary};
6
6
use crate :: sources:: config:: SourceConfigMap ;
7
7
use crate :: util:: errors:: CargoResult ;
8
8
use crate :: util:: interning:: InternedString ;
9
- use crate :: util:: { profile , CanonicalUrl , Config } ;
9
+ use crate :: util:: { CanonicalUrl , Config } ;
10
10
use anyhow:: { bail, Context as _} ;
11
11
use log:: { debug, trace} ;
12
12
use url:: Url ;
@@ -180,6 +180,7 @@ impl<'cfg> PackageRegistry<'cfg> {
180
180
}
181
181
182
182
self . load ( namespace, kind) ?;
183
+ self . block_until_ready ( ) ?;
183
184
Ok ( ( ) )
184
185
}
185
186
@@ -446,38 +447,46 @@ impl<'cfg> PackageRegistry<'cfg> {
446
447
}
447
448
448
449
fn load ( & mut self , source_id : SourceId , kind : Kind ) -> CargoResult < ( ) > {
449
- ( || {
450
- debug ! ( "loading source {}" , source_id) ;
451
- let source = self . source_config . load ( source_id, & self . yanked_whitelist ) ?;
452
- assert_eq ! ( source. source_id( ) , source_id) ;
453
-
454
- if kind == Kind :: Override {
455
- self . overrides . push ( source_id) ;
456
- }
457
- self . add_source ( source, kind) ;
450
+ debug ! ( "loading source {}" , source_id) ;
451
+ let source = self
452
+ . source_config
453
+ . load ( source_id, & self . yanked_whitelist )
454
+ . with_context ( || format ! ( "Unable to update {}" , source_id) ) ?;
455
+ assert_eq ! ( source. source_id( ) , source_id) ;
456
+
457
+ if kind == Kind :: Override {
458
+ self . overrides . push ( source_id) ;
459
+ }
460
+ self . add_source ( source, kind) ;
458
461
459
- // Ensure the source has fetched all necessary remote data.
460
- let _p = profile:: start ( format ! ( "updating: {}" , source_id) ) ;
461
- self . sources . get_mut ( source_id) . unwrap ( ) . update ( )
462
- } ) ( )
463
- . with_context ( || format ! ( "Unable to update {}" , source_id) ) ?;
462
+ // If we have an imprecise version then we don't know what we're going
463
+ // to look for, so we always attempt to perform an update here.
464
+ //
465
+ // If we have a precise version, then we'll update lazily during the
466
+ // querying phase. Note that precise in this case is only
467
+ // `Some("locked")` as other `Some` values indicate a `cargo update
468
+ // --precise` request
469
+ if source_id. precise ( ) != Some ( "locked" ) {
470
+ self . sources . get_mut ( source_id) . unwrap ( ) . invalidate_cache ( ) ;
471
+ } else {
472
+ debug ! ( "skipping update due to locked registry" ) ;
473
+ }
464
474
Ok ( ( ) )
465
475
}
466
476
467
- fn query_overrides ( & mut self , dep : & Dependency ) -> CargoResult < Option < Summary > > {
477
+ fn query_overrides ( & mut self , dep : & Dependency ) -> Poll < CargoResult < Option < Summary > > > {
468
478
for & s in self . overrides . iter ( ) {
469
479
let src = self . sources . get_mut ( s) . unwrap ( ) ;
470
480
let dep = Dependency :: new_override ( dep. package_name ( ) , s) ;
471
- match src. query_vec ( & dep) ? {
472
- Poll :: Ready ( mut results) => {
473
- if !results. is_empty ( ) {
474
- return Ok ( Some ( results. remove ( 0 ) ) ) ;
475
- }
476
- }
477
- Poll :: Pending => panic ! ( "overrides have to be on path deps, how did we get here?" ) ,
481
+ let mut results = match src. query_vec ( & dep) {
482
+ Poll :: Ready ( results) => results?,
483
+ Poll :: Pending => return Poll :: Pending ,
484
+ } ;
485
+ if !results. is_empty ( ) {
486
+ return Poll :: Ready ( Ok ( Some ( results. remove ( 0 ) ) ) ) ;
478
487
}
479
488
}
480
- Ok ( None )
489
+ Poll :: Ready ( Ok ( None ) )
481
490
}
482
491
483
492
/// This function is used to transform a summary to another locked summary
@@ -567,7 +576,10 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
567
576
assert ! ( self . patches_locked) ;
568
577
let ( override_summary, n, to_warn) = {
569
578
// Look for an override and get ready to query the real source.
570
- let override_summary = self . query_overrides ( dep) ?;
579
+ let override_summary = match self . query_overrides ( dep) {
580
+ Poll :: Ready ( override_summary) => override_summary?,
581
+ Poll :: Pending => return Poll :: Pending ,
582
+ } ;
571
583
572
584
// Next up on our list of candidates is to check the `[patch]`
573
585
// section of the manifest. Here we look through all patches
@@ -715,8 +727,10 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
715
727
}
716
728
717
729
fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
718
- for ( _, source) in self . sources . sources_mut ( ) {
719
- source. block_until_ready ( ) ?;
730
+ for ( source_id, source) in self . sources . sources_mut ( ) {
731
+ source
732
+ . block_until_ready ( )
733
+ . with_context ( || format ! ( "Unable to update {}" , source_id) ) ?;
720
734
}
721
735
Ok ( ( ) )
722
736
}
0 commit comments