Skip to content

Commit

Permalink
Stabilize sparse-registry for crates.io
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi committed Oct 12, 2022
1 parent 3516206 commit 62ee867
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/cargo/sources/registry/http_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 131,7 @@ impl<'cfg> HttpRegistry<'cfg> {
config: &'cfg Config,
name: &str,
) -> CargoResult<HttpRegistry<'cfg>> {
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();
Expand Down
7 changes: 7 additions & 0 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://`.

Expand All @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 62ee867

Please sign in to comment.