@@ -2,7 +2,7 @@ use crate::core::PackageId;
2
2
use crate :: sources:: registry:: CRATES_IO_HTTP_INDEX ;
3
3
use crate :: sources:: { DirectorySource , CRATES_IO_DOMAIN , CRATES_IO_INDEX , CRATES_IO_REGISTRY } ;
4
4
use crate :: sources:: { GitSource , PathSource , RegistrySource } ;
5
- use crate :: util:: { CanonicalUrl , CargoResult , Config , IntoUrl } ;
5
+ use crate :: util:: { config , CanonicalUrl , CargoResult , Config , IntoUrl } ;
6
6
use log:: trace;
7
7
use serde:: de;
8
8
use serde:: ser;
@@ -215,7 +215,7 @@ impl SourceId {
215
215
/// Returns the `SourceId` corresponding to the main repository, using the
216
216
/// sparse HTTP index if allowed.
217
217
pub fn crates_io_maybe_sparse_http ( config : & Config ) -> CargoResult < SourceId > {
218
- if config . cli_unstable ( ) . sparse_registry {
218
+ if Self :: crates_io_is_sparse ( config ) ? {
219
219
config. check_registry_index_not_set ( ) ?;
220
220
let url = CRATES_IO_HTTP_INDEX . into_url ( ) . unwrap ( ) ;
221
221
SourceId :: new ( SourceKind :: Registry , url, Some ( CRATES_IO_REGISTRY ) )
@@ -224,6 +224,21 @@ impl SourceId {
224
224
}
225
225
}
226
226
227
+ /// Returns whether to access crates.io over the sparse protocol.
228
+ pub fn crates_io_is_sparse ( config : & Config ) -> CargoResult < bool > {
229
+ let proto: Option < config:: Value < String > > = config. get ( "registries.crates-io.protocol" ) ?;
230
+ let is_sparse = match proto. as_ref ( ) . map ( |v| v. val . as_str ( ) ) {
231
+ Some ( "sparse" ) => true ,
232
+ Some ( "git" ) => false ,
233
+ Some ( unknown) => anyhow:: bail!(
234
+ "unsupported registry protocol `{unknown}` (defined in {})" ,
235
+ proto. as_ref( ) . unwrap( ) . definition
236
+ ) ,
237
+ None => config. cli_unstable ( ) . sparse_registry ,
238
+ } ;
239
+ Ok ( is_sparse)
240
+ }
241
+
227
242
/// Gets the `SourceId` associated with given name of the remote registry.
228
243
pub fn alt_registry ( config : & Config , key : & str ) -> CargoResult < SourceId > {
229
244
if key == CRATES_IO_REGISTRY {
0 commit comments