Skip to content

Commit 9923c9d

Browse files
committed
feat: remove url crate
1 parent dd32e8a commit 9923c9d

File tree

4 files changed

+10
-23
lines changed

4 files changed

+10
-23
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ toml = "0.8.19"
1313
tracing = "0.1.41"
1414
tracing-indicatif = "0.3.9"
1515
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
16-
url = "2.5.4"

rust/patchable/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ toml.workspace = true
1414
tracing.workspace = true
1515
tracing-indicatif.workspace = true
1616
tracing-subscriber.workspace = true
17-
url.workspace = true

rust/patchable/src/utils.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
use std::path::Path;
22

33
use git2::Repository;
4-
use snafu::{OptionExt as _, ResultExt as _, Snafu};
4+
use snafu::{OptionExt as _, Snafu};
55
use tracing::Span;
66
use tracing_indicatif::{span_ext::IndicatifSpanExt, style::ProgressStyle};
7-
use url::Url;
87

9-
/// Errors that can occur during URL rewriting.
108
#[derive(Debug, Snafu)]
119
pub enum UrlRewriteError {
12-
#[snafu(display("Failed to parse URL {url:?}: {source}"))]
13-
ParseUrl { source: url::ParseError, url: String },
14-
#[snafu(display("URL {url:?} has no host component"))]
15-
NoHostInUrl { url: String },
10+
#[snafu(display("URL does not have https schema: {}", url))]
11+
NoHttpsSchema { url: String },
1612
}
1713

1814
/// Rewrites a given URL to an SSH-style Git URL
1915
/// For example, `https://github.com/user/repo.git` becomes `[email protected]:user/repo.git`.
20-
pub fn rewrite_git_https_url_to_ssh(
21-
original_url: &str,
22-
) -> Result<String, UrlRewriteError> {
23-
let parsed_url = Url::parse(original_url).context(ParseUrlSnafu {
24-
url: original_url,
25-
})?;
26-
27-
let host = parsed_url.host_str().context(NoHostInUrlSnafu {
28-
url: original_url,
29-
})?;
30-
let path = parsed_url.path().trim_start_matches('/');
31-
32-
Ok(format!("git@{}:{}", host, path))
16+
pub fn rewrite_git_https_url_to_ssh(original_url: &str) -> Result<String, UrlRewriteError> {
17+
let schemaless = original_url
18+
.strip_prefix("https://")
19+
.context(NoHttpsSchemaSnafu {
20+
url: original_url.to_string(),
21+
})?;
22+
Ok(format!("ssh://git@{schemaless}"))
3323
}
3424

3525
/// Runs a function whenever a `value` changes "enough".

0 commit comments

Comments
 (0)