diff --git a/src/cargo/sources/registry/http_remote.rs b/src/cargo/sources/registry/http_remote.rs index 1c54c52bc3e3..7b0f88971bdd 100644 --- a/src/cargo/sources/registry/http_remote.rs +++ b/src/cargo/sources/registry/http_remote.rs @@ -131,7 +131,7 @@ impl<'cfg> HttpRegistry<'cfg> { config: &'cfg Config, name: &str, ) -> CargoResult> { - if !config.cli_unstable().sparse_registry { + if !source_id.is_crates_io() && !config.cli_unstable().sparse_registry { anyhow::bail!("usage of sparse registries requires `-Z sparse-registry`"); } let url = source_id.url().as_str(); diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md index f60c185e9165..1d9abbb38327 100644 --- a/src/doc/src/reference/config.md +++ b/src/doc/src/reference/config.md @@ -891,6 +891,13 @@ commands like [`cargo publish`] that require authentication. Can be overridden with the `--token` command-line option. +##### `registries.crates-io.protocol` +* Type: string +* Default: `git` (or `sparse` `-Z sparse-registry` is passed) +* Environment: `CARGO_REGISTRIES_CRATES_IO_PROTOCOL` + +Specifies the protocol used to access crates.io. Allowed values are `git` or `sparse`. + #### `[registry]` The `[registry]` table controls the default registry used when one is not diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index f97b1f93c50d..2ea2695804bd 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -832,7 +832,7 @@ fn main() { * Tracking Issue: [9069](https://github.com/rust-lang/cargo/issues/9069) * RFC: [#2789](https://github.com/rust-lang/rfcs/pull/2789) -The `sparse-registry` feature allows cargo to interact with remote registries served +The `sparse-registry` feature allows Cargo to interact with remote registries served over plain HTTP rather than git. These registries can be identified by urls starting with `sparse+http://` or `sparse+https://`. @@ -841,6 +841,17 @@ crates, which can save significant time and bandwidth. The format of the sparse index is identical to a checkout of a git-based index. +Note that this feature is not required for accessing crates.io over the sparse protocol. +To set the protocol used for crates.io, set in a [config file]: +```toml +[registries.crates-io] +protocol = 'sparse' +``` +Or use the environment variable `CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse`. + +Enabling this feature changes the default protocol for accessing crates.io to from `git` +to `sparse`. + ### credential-process * Tracking Issue: [#8933](https://github.com/rust-lang/cargo/issues/8933) * RFC: [#2730](https://github.com/rust-lang/rfcs/pull/2730) diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index 8eb827951360..2648eaf25cbb 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -2703,15 +2703,6 @@ fn http_requires_z_flag() { .run(); } -#[cargo_test] -fn protocol_sparse_requires_z_flag() { - cargo_process("install bar") - .with_status(101) - .env("CARGO_REGISTRIES_CRATES_IO_PROTOCOL", "sparse") - .with_stderr("[ERROR] usage of sparse registries requires `-Z sparse-registry`") - .run() -} - #[cargo_test] fn protocol() { cargo_process("install bar")