Skip to content

Commit bcf19b8

Browse files
authored
Merge pull request #48 from l4l/custom-registry
Support custom registries
2 parents d2c0723 + 67f1d88 commit bcf19b8

File tree

9 files changed

+266
-139
lines changed

9 files changed

+266
-139
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## Unreleased
77

8+
### Added
9+
10+
- New method `Crate::registry` for alternative registries.
11+
812
### Changed
913

1014
- allow workspaces by having validate_manifest now use `metadata --no-deps` instead of deprecated `read-manifest`

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ remove_dir_all = "0.5.2"
3838
base64 = "0.12.0"
3939
getrandom = { version = "0.1.12", features = ["std"] }
4040
thiserror = "1.0.20"
41+
git2 = "0.13.12"
4142

4243
[target.'cfg(unix)'.dependencies]
4344
nix = "0.11.0"

src/crates/cratesio.rs

Lines changed: 0 additions & 120 deletions
This file was deleted.

src/crates/git.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@ use crate::prepare::PrepareError;
44
use crate::Workspace;
55
use failure::{Error, ResultExt};
66
use log::{info, warn};
7-
use percent_encoding::{percent_encode, AsciiSet, CONTROLS};
87
use std::path::{Path, PathBuf};
98

10-
const ENCODE_SET: AsciiSet = CONTROLS
11-
.add(b'/')
12-
.add(b'\\')
13-
.add(b'<')
14-
.add(b'>')
15-
.add(b':')
16-
.add(b'"')
17-
.add(b'|')
18-
.add(b'?')
19-
.add(b'*')
20-
.add(b' ');
21-
229
pub(super) struct GitRepo {
2310
url: String,
2411
}
@@ -54,7 +41,7 @@ impl GitRepo {
5441
workspace
5542
.cache_dir()
5643
.join("git-repos")
57-
.join(percent_encode(self.url.as_bytes(), &ENCODE_SET).to_string())
44+
.join(crate::utils::escape_path(self.url.as_bytes()))
5845
}
5946

6047
fn suppress_password_prompt_args(&self, workspace: &Workspace) -> Vec<String> {

src/crates/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
mod cratesio;
21
mod git;
32
mod local;
3+
mod registry;
44

55
use crate::Workspace;
66
use failure::Error;
@@ -14,7 +14,7 @@ trait CrateTrait: std::fmt::Display {
1414
}
1515

1616
enum CrateType {
17-
CratesIO(cratesio::CratesIOCrate),
17+
Registry(registry::RegistryCrate),
1818
Git(git::GitRepo),
1919
Local(local::Local),
2020
}
@@ -23,10 +23,21 @@ enum CrateType {
2323
pub struct Crate(CrateType);
2424

2525
impl Crate {
26+
/// Load a crate from specified registry.
27+
pub fn registry(registry_index: &str, name: &str, version: &str) -> Self {
28+
Crate(CrateType::Registry(registry::RegistryCrate::new(
29+
registry::Registry::Alternative(registry::AlternativeRegistry::new(registry_index)),
30+
name,
31+
version,
32+
)))
33+
}
34+
2635
/// Load a crate from the [crates.io registry](https://crates.io).
2736
pub fn crates_io(name: &str, version: &str) -> Self {
28-
Crate(CrateType::CratesIO(cratesio::CratesIOCrate::new(
29-
name, version,
37+
Crate(CrateType::Registry(registry::RegistryCrate::new(
38+
registry::Registry::CratesIo,
39+
name,
40+
version,
3041
)))
3142
}
3243

@@ -75,7 +86,7 @@ impl Crate {
7586

7687
fn as_trait(&self) -> &dyn CrateTrait {
7788
match &self.0 {
78-
CrateType::CratesIO(krate) => krate,
89+
CrateType::Registry(krate) => krate,
7990
CrateType::Git(repo) => repo,
8091
CrateType::Local(local) => local,
8192
}

0 commit comments

Comments
 (0)