Skip to content

Commit 2c5b955

Browse files
committed
support for radicle urls
1 parent f8ab261 commit 2c5b955

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

etc/check-package-size.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ indent cargo diet -n --package-size-limit 25KB
1919
(enter git-hash && indent cargo diet -n --package-size-limit 5KB)
2020
(enter git-features && indent cargo diet -n --package-size-limit 15KB)
2121
(enter git-ref && indent cargo diet -n --package-size-limit 4KB)
22-
(enter git-url && indent cargo diet -n --package-size-limit 6KB)
22+
(enter git-url && indent cargo diet -n --package-size-limit 7KB)
2323
(enter git-object && indent cargo diet -n --package-size-limit 20KB)
2424
(enter git-commitgraph && indent cargo diet -n --package-size-limit 15KB)
2525
(enter git-odb && indent cargo diet -n --package-size-limit 65KB)
2626
(enter git-protocol && indent cargo diet -n --package-size-limit 20KB)
2727
(enter git-packetline && indent cargo diet -n --package-size-limit 10KB)
2828
(enter git-repository && indent cargo diet -n --package-size-limit 10KB)
2929
(enter git-transport && indent cargo diet -n --package-size-limit 20KB)
30-
(enter gitoxide-core && indent cargo diet -n --package-size-limit 10KB)
30+
(enter gitoxide-core && indent cargo diet -n --package-size-limit 15KB)

git-transport/src/client/connect.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ quick_error! {
2323
UnsupportedUrlTokens(url: bstr::BString, scheme: git_url::Scheme) {
2424
display("The url '{}' contains information that would not be used by the '{}' protocol", url, scheme)
2525
}
26+
UnsupportedScheme(scheme: git_url::Scheme) {
27+
display("The '{}' protocol is currently unsupported", scheme)
28+
}
2629
#[cfg(not(feature = "http-client-curl"))]
2730
CompiledWithoutHttp(scheme: git_url::Scheme) {
2831
display("'{}' is not compiled in. Compile with the 'http-client-curl' cargo feature", scheme)
@@ -82,6 +85,7 @@ pub fn connect(url: &[u8], desired_version: crate::Protocol) -> Result<Box<dyn T
8285
let urlb = url;
8386
let url = git_url::parse(urlb)?;
8487
Ok(match url.scheme {
88+
git_url::Scheme::Radicle => return Err(Error::UnsupportedScheme(url.scheme)),
8589
git_url::Scheme::File => {
8690
if url.user.is_some() || url.host.is_some() || url.port.is_some() {
8791
return Err(Error::UnsupportedUrlTokens(urlb.into(), url.scheme));

git-url/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum Scheme {
2727
Ssh,
2828
Http,
2929
Https,
30+
Radicle,
3031
}
3132

3233
impl fmt::Display for Scheme {
@@ -38,6 +39,7 @@ impl fmt::Display for Scheme {
3839
Ssh => "ssh",
3940
Http => "http",
4041
Https => "https",
42+
Radicle => "rad",
4143
})
4244
}
4345
}

git-url/src/parse.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn str_to_protocol(s: &str) -> Result<Scheme, Error> {
3535
"git" => Scheme::Git,
3636
"http" => Scheme::Http,
3737
"https" => Scheme::Https,
38+
"rad" => Scheme::Radicle,
3839
_ => return Err(Error::UnsupportedProtocol(s.into())),
3940
})
4041
}
@@ -122,7 +123,7 @@ pub fn parse(bytes: &[u8]) -> Result<crate::Url, Error> {
122123
url = url::Url::parse(&format!("ssh://{}", sanitize_for_protocol("ssh", url_str)))
123124
.map_err(|err| Error::Url(err.to_string()))?;
124125
}
125-
if url.path().is_empty() {
126+
if url.scheme() != "rad" && url.path().is_empty() {
126127
return Err(Error::EmptyPath);
127128
}
128129
if url.cannot_be_a_base() {

git-url/tests/parse/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ fn url(
3333
mod file;
3434
mod invalid;
3535
mod ssh;
36+
37+
mod radicle {
38+
use crate::parse::{assert_url_roundtrip, url};
39+
use git_url::Scheme;
40+
41+
#[test]
42+
fn basic() -> crate::Result {
43+
assert_url_roundtrip("rad://hynkuwzskprmswzeo4qdtku7grdrs4ffj3g9tjdxomgmjzhtzpqf81@hwd1yregyf1dudqwkx85x5ps3qsrqw3ihxpx3ieopq6ukuuq597p6m8161c.git", url(Scheme::Radicle, "hynkuwzskprmswzeo4qdtku7grdrs4ffj3g9tjdxomgmjzhtzpqf81", "hwd1yregyf1dudqwkx85x5ps3qsrqw3ihxpx3ieopq6ukuuq597p6m8161c.git", None, b""))
44+
}
45+
}
46+
3647
mod http {
3748
use crate::parse::{assert_url_roundtrip, url};
3849
use git_url::Scheme;

0 commit comments

Comments
 (0)