Skip to content

add sparse url in cargo package guide #26937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 13, 2023
Merged
13 changes: 10 additions & 3 deletions docs/content/usage/packages/cargo.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ Add the following text to the configuration file located in the current users ho
default = "gitea"

[registries.gitea]
index = "https://gitea.example.com/{owner}/_cargo-index.git"
index = "sparse+https://gitea.example.com/api/packages/{owner}/cargo/" # Sparse index
# index = "https://gitea.example.com/{owner}/_cargo-index.git" # Git

[net]
git-fetch-with-cli = true
# [net]
# git-fetch-with-cli = true
```

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

## Git vs Sparse

Currently, cargo supports two ways for fetching crates in a registry: Git index & sparse index.
Sparse index is the newest method and offers better performance when updating crates compared to git.
Since Rust 1.68, sparse is the default method for crates.io.

## Publish a package

Publish a package by running the following command in your project:
Expand Down
3 changes: 2 additions & 1 deletion docs/content/usage/packages/cargo.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Cargo 将可用软件包的信息存储在一个存储在 git 仓库中的软件
default = "gitea"

[registries.gitea]
index = "https://gitea.example.com/{owner}/_cargo-index.git"
index = "sparse+https://gitea.example.com/api/packages/{owner}/cargo/" # Sparse index
# index = "https://gitea.example.com/{owner}/_cargo-index.git" # Git

[net]
git-fetch-with-cli = true
Expand Down
3 changes: 2 additions & 1 deletion templates/package/content/cargo.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
default = "gitea"

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

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