Skip to content

Commit e6a059a

Browse files
authored
add sparse url in cargo package guide (#26937)
Hello, The current package guide for cargo gives you only the git index, with the HTTP Index stabilized being used as default for crates.io and being better for most use-cases. However, it's not documented that gitea supports the sparse spec, and it does not require the _crates-index git repo for the sparse api. I personally think we should push users to use the sparse instead of the git repository. (Even let users disable crates-index repos if they only want to use sparse)
1 parent aaeec2a commit e6a059a

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

docs/content/usage/packages/cargo.en-us.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ Add the following text to the configuration file located in the current users ho
5050
default = "gitea"
5151
5252
[registries.gitea]
53-
index = "https://gitea.example.com/{owner}/_cargo-index.git"
53+
index = "sparse+https://gitea.example.com/api/packages/{owner}/cargo/" # Sparse index
54+
# index = "https://gitea.example.com/{owner}/_cargo-index.git" # Git
5455
55-
[net]
56-
git-fetch-with-cli = true
56+
# [net]
57+
# git-fetch-with-cli = true
5758
```
5859

5960
| Parameter | Description |
@@ -72,6 +73,12 @@ token = "Bearer {token}"
7273
| --------- | ----------- |
7374
| `token` | Your [personal access token](development/api-usage.md#authentication) |
7475

76+
## Git vs Sparse
77+
78+
Currently, cargo supports two ways for fetching crates in a registry: Git index & sparse index.
79+
Sparse index is the newest method and offers better performance when updating crates compared to git.
80+
Since Rust 1.68, sparse is the default method for crates.io.
81+
7582
## Publish a package
7683

7784
Publish a package by running the following command in your project:

docs/content/usage/packages/cargo.zh-cn.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Cargo 将可用软件包的信息存储在一个存储在 git 仓库中的软件
5050
default = "gitea"
5151
5252
[registries.gitea]
53-
index = "https://gitea.example.com/{owner}/_cargo-index.git"
53+
index = "sparse+https://gitea.example.com/api/packages/{owner}/cargo/" # Sparse index
54+
# index = "https://gitea.example.com/{owner}/_cargo-index.git" # Git
5455
5556
[net]
5657
git-fetch-with-cli = true

templates/package/content/cargo.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
default = "gitea"
99

1010
[registries.gitea]
11-
index = "<gitea-origin-url data-url="{{AppSubUrl}}/{{.PackageDescriptor.Owner.Name}}/_cargo-index.git"></gitea-origin-url>"
11+
index = "<gitea-origin-url data-url="sparse+{{AppSubUrl}}/api/packages/{{.PackageDescriptor.Owner.Name}}/cargo/"></gitea-origin-url>" # Sparse index
12+
# index = "<gitea-origin-url data-url="{{AppSubUrl}}/{{.PackageDescriptor.Owner.Name}}/_cargo-index.git"></gitea-origin-url>" # Git
1213

1314
[net]
1415
git-fetch-with-cli = true</code></pre></div>

0 commit comments

Comments
 (0)