Skip to content

Commit

Permalink
support for radicle urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 14, 2021
1 parent f8ab261 commit 2c5b955
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions etc/check-package-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ indent cargo diet -n --package-size-limit 25KB
(enter git-hash && indent cargo diet -n --package-size-limit 5KB)
(enter git-features && indent cargo diet -n --package-size-limit 15KB)
(enter git-ref && indent cargo diet -n --package-size-limit 4KB)
(enter git-url && indent cargo diet -n --package-size-limit 6KB)
(enter git-url && indent cargo diet -n --package-size-limit 7KB)
(enter git-object && indent cargo diet -n --package-size-limit 20KB)
(enter git-commitgraph && indent cargo diet -n --package-size-limit 15KB)
(enter git-odb && indent cargo diet -n --package-size-limit 65KB)
(enter git-protocol && indent cargo diet -n --package-size-limit 20KB)
(enter git-packetline && indent cargo diet -n --package-size-limit 10KB)
(enter git-repository && indent cargo diet -n --package-size-limit 10KB)
(enter git-transport && indent cargo diet -n --package-size-limit 20KB)
(enter gitoxide-core && indent cargo diet -n --package-size-limit 10KB)
(enter gitoxide-core && indent cargo diet -n --package-size-limit 15KB)
4 changes: 4 additions & 0 deletions git-transport/src/client/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ quick_error! {
UnsupportedUrlTokens(url: bstr::BString, scheme: git_url::Scheme) {
display("The url '{}' contains information that would not be used by the '{}' protocol", url, scheme)
}
UnsupportedScheme(scheme: git_url::Scheme) {
display("The '{}' protocol is currently unsupported", scheme)
}
#[cfg(not(feature = "http-client-curl"))]
CompiledWithoutHttp(scheme: git_url::Scheme) {
display("'{}' is not compiled in. Compile with the 'http-client-curl' cargo feature", scheme)
Expand Down Expand Up @@ -82,6 +85,7 @@ pub fn connect(url: &[u8], desired_version: crate::Protocol) -> Result<Box<dyn T
let urlb = url;
let url = git_url::parse(urlb)?;
Ok(match url.scheme {
git_url::Scheme::Radicle => return Err(Error::UnsupportedScheme(url.scheme)),
git_url::Scheme::File => {
if url.user.is_some() || url.host.is_some() || url.port.is_some() {
return Err(Error::UnsupportedUrlTokens(urlb.into(), url.scheme));
Expand Down
2 changes: 2 additions & 0 deletions git-url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum Scheme {
Ssh,
Http,
Https,
Radicle,
}

impl fmt::Display for Scheme {
Expand All @@ -38,6 +39,7 @@ impl fmt::Display for Scheme {
Ssh => "ssh",
Http => "http",
Https => "https",
Radicle => "rad",
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion git-url/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn str_to_protocol(s: &str) -> Result<Scheme, Error> {
"git" => Scheme::Git,
"http" => Scheme::Http,
"https" => Scheme::Https,
"rad" => Scheme::Radicle,
_ => return Err(Error::UnsupportedProtocol(s.into())),
})
}
Expand Down Expand Up @@ -122,7 +123,7 @@ pub fn parse(bytes: &[u8]) -> Result<crate::Url, Error> {
url = url::Url::parse(&format!("ssh://{}", sanitize_for_protocol("ssh", url_str)))
.map_err(|err| Error::Url(err.to_string()))?;
}
if url.path().is_empty() {
if url.scheme() != "rad" && url.path().is_empty() {
return Err(Error::EmptyPath);
}
if url.cannot_be_a_base() {
Expand Down
11 changes: 11 additions & 0 deletions git-url/tests/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ fn url(
mod file;
mod invalid;
mod ssh;

mod radicle {
use crate::parse::{assert_url_roundtrip, url};
use git_url::Scheme;

#[test]
fn basic() -> crate::Result {
assert_url_roundtrip("rad://hynkuwzskprmswzeo4qdtku7grdrs4ffj3g9tjdxomgmjzhtzpqf81@hwd1yregyf1dudqwkx85x5ps3qsrqw3ihxpx3ieopq6ukuuq597p6m8161c.git", url(Scheme::Radicle, "hynkuwzskprmswzeo4qdtku7grdrs4ffj3g9tjdxomgmjzhtzpqf81", "hwd1yregyf1dudqwkx85x5ps3qsrqw3ihxpx3ieopq6ukuuq597p6m8161c.git", None, b""))
}
}

mod http {
use crate::parse::{assert_url_roundtrip, url};
use git_url::Scheme;
Expand Down

0 comments on commit 2c5b955

Please sign in to comment.