@@ -142,15 +142,15 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
142
142
}
143
143
}
144
144
145
- let ( mut registry, _reg_cfg, reg_id ) = registry (
145
+ let ( mut registry, _reg_cfg, reg_ids ) = registry (
146
146
opts. config ,
147
147
opts. token . clone ( ) ,
148
148
opts. index . as_deref ( ) ,
149
149
publish_registry. as_deref ( ) ,
150
150
true ,
151
151
!opts. dry_run ,
152
152
) ?;
153
- verify_dependencies ( pkg, & registry, reg_id ) ?;
153
+ verify_dependencies ( pkg, & registry, reg_ids . original ) ?;
154
154
155
155
// Prepare a tarball, with a non-suppressible warning if metadata
156
156
// is missing since this is being put online.
@@ -180,7 +180,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
180
180
pkg,
181
181
tarball. file ( ) ,
182
182
& mut registry,
183
- reg_id ,
183
+ reg_ids . original ,
184
184
opts. dry_run ,
185
185
) ?;
186
186
@@ -456,12 +456,12 @@ fn registry(
456
456
registry : Option < & str > ,
457
457
force_update : bool ,
458
458
validate_token : bool ,
459
- ) -> CargoResult < ( Registry , RegistryConfig , SourceId ) > {
460
- let ( sid , sid_no_replacement ) = get_source_id ( config, index, registry) ?;
459
+ ) -> CargoResult < ( Registry , RegistryConfig , RegistrySourceIds ) > {
460
+ let source_ids = get_source_id ( config, index, registry) ?;
461
461
let reg_cfg = registry_configuration ( config, registry) ?;
462
462
let api_host = {
463
463
let _lock = config. acquire_package_cache_lock ( ) ?;
464
- let mut src = RegistrySource :: remote ( sid , & HashSet :: new ( ) , config) ?;
464
+ let mut src = RegistrySource :: remote ( source_ids . replacement , & HashSet :: new ( ) , config) ?;
465
465
// Only update the index if the config is not available or `force` is set.
466
466
if force_update {
467
467
src. invalidate_cache ( )
@@ -470,13 +470,14 @@ fn registry(
470
470
match src. config ( ) ? {
471
471
Poll :: Pending => src
472
472
. block_until_ready ( )
473
- . with_context ( || format ! ( "failed to update {}" , sid ) ) ?,
473
+ . with_context ( || format ! ( "failed to update {}" , source_ids . replacement ) ) ?,
474
474
Poll :: Ready ( cfg) => break cfg,
475
475
}
476
476
} ;
477
477
478
- cfg. and_then ( |cfg| cfg. api )
479
- . ok_or_else ( || format_err ! ( "{} does not support API commands" , sid) ) ?
478
+ cfg. and_then ( |cfg| cfg. api ) . ok_or_else ( || {
479
+ format_err ! ( "{} does not support API commands" , source_ids. replacement)
480
+ } ) ?
480
481
} ;
481
482
let token = if validate_token {
482
483
if index. is_some ( ) {
@@ -495,7 +496,7 @@ fn registry(
495
496
Ok ( (
496
497
Registry :: new_handle ( api_host, token, handle) ,
497
498
reg_cfg,
498
- sid_no_replacement ,
499
+ source_ids ,
499
500
) )
500
501
}
501
502
@@ -919,7 +920,7 @@ fn get_source_id(
919
920
config : & Config ,
920
921
index : Option < & str > ,
921
922
reg : Option < & str > ,
922
- ) -> CargoResult < ( SourceId , SourceId ) > {
923
+ ) -> CargoResult < RegistrySourceIds > {
923
924
let sid = match ( reg, index) {
924
925
( None , None ) => SourceId :: crates_io ( config) ?,
925
926
( Some ( r) , None ) => SourceId :: alt_registry ( config, r) ?,
@@ -943,18 +944,34 @@ fn get_source_id(
943
944
bail ! ( "crates-io is replaced with non-remote-registry source {replacement_sid};\n include `--registry crates-io` to use crates.io" ) ;
944
945
}
945
946
} else {
946
- Ok ( ( builtin_replacement_sid, sid) )
947
+ Ok ( RegistrySourceIds {
948
+ original : sid,
949
+ replacement : builtin_replacement_sid,
950
+ } )
947
951
}
948
952
}
949
953
954
+ struct RegistrySourceIds {
955
+ /// Use when looking up the auth token, or writing out `Cargo.lock`
956
+ original : SourceId ,
957
+ /// Use when interacting with the source (querying / publishing , etc)
958
+ ///
959
+ /// The source for crates.io may be replaced by a built-in source for accessing crates.io with
960
+ /// the sparse protocol, or a source for the testing framework (when the replace_crates_io
961
+ /// function is used)
962
+ ///
963
+ /// User-defined source replacement is not applied.
964
+ replacement : SourceId ,
965
+ }
966
+
950
967
pub fn search (
951
968
query : & str ,
952
969
config : & Config ,
953
970
index : Option < String > ,
954
971
limit : u32 ,
955
972
reg : Option < String > ,
956
973
) -> CargoResult < ( ) > {
957
- let ( mut registry, _, source_id ) =
974
+ let ( mut registry, _, source_ids ) =
958
975
registry ( config, None , index. as_deref ( ) , reg. as_deref ( ) , false , false ) ?;
959
976
let ( crates, total_crates) = registry. search ( query, limit) . with_context ( || {
960
977
format ! (
@@ -1011,7 +1028,7 @@ pub fn search(
1011
1028
& ColorSpec :: new ( ) ,
1012
1029
) ;
1013
1030
} else if total_crates > limit && limit >= search_max_limit {
1014
- let extra = if source_id . is_crates_io ( ) {
1031
+ let extra = if source_ids . original . is_crates_io ( ) {
1015
1032
format ! (
1016
1033
" (go to https://crates.io/search?q={} to see more)" ,
1017
1034
percent_encode( query. as_bytes( ) , NON_ALPHANUMERIC )
0 commit comments