Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb60d3d

Browse files
committed
Merge branch 'main' into adjustments-for-cargo
Conflicts: git-url/src/parse.rs
2 parents 89230f4 + 3e27550 commit bb60d3d

7 files changed

Lines changed: 42 additions & 28 deletions

File tree

git-repository/tests/fixtures/make_remote_repos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ git init --bare bad-url-rewriting
165165
[remote "origin"]
166166
pushUrl = "file://dev/null"
167167
168-
[url "foo://"]
168+
[url "invalid:://"]
169169
pushInsteadOf = "file://"
170170
171171
[url "https://github.com/byron/"]

git-repository/tests/repository/remote.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mod find_remote {
215215
"…but is able to replace the fetch url successfully"
216216
);
217217

218-
let expected_err_msg = "The rewritten push url \"foo://dev/null\" failed to parse";
218+
let expected_err_msg = "The rewritten push url \"invalid:://dev/null\" failed to parse";
219219
assert_eq!(
220220
repo.find_remote("origin").unwrap_err().to_string(),
221221
expected_err_msg,
@@ -237,7 +237,6 @@ mod find_remote {
237237
"it can rewrite a single url like git can"
238238
);
239239
}
240-
assert_eq!(remote.url(Direction::Push).unwrap().to_bstring(), "file://dev/null",);
241240
assert_eq!(
242241
remote.rewrite_urls().unwrap_err().to_string(),
243242
expected_err_msg,

git-transport/src/client/blocking_io/ssh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn connect(
4343
if desired_version != Protocol::V1 {
4444
let mut args = vec![Cow::from("-o"), "SendEnv=GIT_PROTOCOL".into()];
4545
if let Some(port) = port {
46-
args.push(format!("-p={}", port).into());
46+
args.push(format!("-p{}", port).into());
4747
}
4848
Some((
4949
args,

git-url/src/parse.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::{
2-
borrow::Cow,
3-
convert::{Infallible, TryFrom},
4-
};
1+
use std::{borrow::Cow, convert::Infallible};
52

63
pub use bstr;
74
use bstr::{BStr, BString, ByteSlice};
@@ -16,8 +13,6 @@ pub enum Error {
1613
Utf8(#[from] std::str::Utf8Error),
1714
#[error(transparent)]
1815
Url(#[from] url::ParseError),
19-
#[error("Protocol {protocol:?} is not supported")]
20-
UnsupportedProtocol { protocol: String },
2116
#[error("urls require the path to the repository")]
2217
MissingResourceLocation,
2318
#[error("file urls require an absolute or relative path to the repository repository")]
@@ -34,10 +29,8 @@ impl From<Infallible> for Error {
3429
}
3530
}
3631

37-
fn str_to_protocol(s: &str) -> Result<Scheme, Error> {
38-
Scheme::try_from(s).map_err(|invalid| Error::UnsupportedProtocol {
39-
protocol: invalid.into(),
40-
})
32+
fn str_to_protocol(s: &str) -> Scheme {
33+
Scheme::from(s)
4134
}
4235

4336
fn guess_protocol(url: &[u8]) -> Option<&str> {
@@ -70,7 +63,7 @@ fn has_no_explicit_protocol(url: &[u8]) -> bool {
7063
fn to_owned_url(url: url::Url) -> Result<crate::Url, Error> {
7164
Ok(crate::Url {
7265
serialize_alternative_form: false,
73-
scheme: str_to_protocol(url.scheme())?,
66+
scheme: str_to_protocol(url.scheme()),
7467
user: if url.username().is_empty() {
7568
None
7669
} else {

git-url/src/scheme.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
use std::convert::TryFrom;
2-
3-
/// A scheme for use in a [`Url`][crate::Url].
1+
/// A scheme or protocol for use in a [`Url`][crate::Url].
2+
///
3+
/// It defines how to talk to a given repository.
44
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
55
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
66
#[allow(missing_docs)]
77
pub enum Scheme {
8+
/// A local resource that is accessible on the current host.
89
File,
10+
/// A git daemon, like `File` over TCP/IP.
911
Git,
12+
/// Launch `git-upload-pack` through an `ssh` tunnel.
1013
Ssh,
14+
/// Use the HTTP protocol to talk to git servers.
1115
Http,
16+
/// Use the HTTPS protocol to talk to git servers.
1217
Https,
18+
/// Any other protocol or transport that isn't known at compile time.
19+
///
20+
/// It's used to support plug-in transports.
1321
Ext(String),
1422
}
1523

16-
impl<'a> TryFrom<&'a str> for Scheme {
17-
type Error = &'a str;
18-
19-
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
20-
Ok(match value {
24+
impl<'a> From<&'a str> for Scheme {
25+
fn from(value: &'a str) -> Self {
26+
match value {
2127
"ssh" => Scheme::Ssh,
2228
"file" => Scheme::File,
2329
"git" => Scheme::Git,
2430
"http" => Scheme::Http,
2531
"https" => Scheme::Https,
26-
"rad" => Scheme::Ext("rad".into()),
27-
unknown => return Err(unknown),
28-
})
32+
unknown => Scheme::Ext(unknown.into()),
33+
}
2934
}
3035
}
3136

git-url/tests/parse/invalid.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ use crate::parse::assert_failure;
22
use git_url::parse::Error;
33

44
#[test]
5-
fn unknown_protocol() {
6-
assert_failure("foo://host.xz/path/to/repo.git/", "Protocol \"foo\" is not supported")
5+
fn relative_path_due_to_double_colon() {
6+
assert_failure(
7+
"invalid:://host.xz/path/to/repo.git/",
8+
"Relative URLs are not permitted: \"invalid:://host.xz/path/to/repo.git/\"",
9+
)
710
}
811

912
#[test]

git-url/tests/parse/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,17 @@ mod git {
127127
)
128128
}
129129
}
130+
131+
mod unknown {
132+
use git_url::Scheme;
133+
134+
use crate::parse::{assert_url_roundtrip, url};
135+
136+
#[test]
137+
fn any_protocol_is_supported_via_the_ext_scheme() -> crate::Result {
138+
assert_url_roundtrip(
139+
"abc://example.com/~byron/hello",
140+
url(Scheme::Ext("abc".into()), None, "example.com", None, b"/~byron/hello"),
141+
)
142+
}
143+
}

0 commit comments

Comments
 (0)