From 3aac7cefbe50665653debeb0bd88109b4ad48865 Mon Sep 17 00:00:00 2001 From: Robert Deaton Date: Sat, 2 Nov 2024 20:35:16 -0700 Subject: [PATCH 1/2] Enable support for arbitrary git transports --- crates/uv-pep508/src/verbatim_url.rs | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/crates/uv-pep508/src/verbatim_url.rs b/crates/uv-pep508/src/verbatim_url.rs index 5d2f62597cbd..2c1830085349 100644 --- a/crates/uv-pep508/src/verbatim_url.rs +++ b/crates/uv-pep508/src/verbatim_url.rs @@ -413,20 +413,12 @@ fn split_fragment(path: &Path) -> (Cow, Option<&str>) { } /// A supported URL scheme for PEP 508 direct-URL requirements. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Scheme { /// `file://...` File, - /// `git+git://...` - GitGit, - /// `git+http://...` - GitHttp, - /// `git+file://...` - GitFile, - /// `git+ssh://...` - GitSsh, - /// `git+https://...` - GitHttps, + /// `git+{transport}://...` as git supports arbitrary transports through gitremote-helpers + Git(String), /// `bzr+http://...` BzrHttp, /// `bzr+https://...` @@ -470,13 +462,11 @@ pub enum Scheme { impl Scheme { /// Determine the [`Scheme`] from the given string, if possible. pub fn parse(s: &str) -> Option { + if let Some(("git", transport)) = s.split_once("+") { + return Some(Self::Git(transport.into())); + } match s { "file" => Some(Self::File), - "git+git" => Some(Self::GitGit), - "git+http" => Some(Self::GitHttp), - "git+file" => Some(Self::GitFile), - "git+ssh" => Some(Self::GitSsh), - "git+https" => Some(Self::GitHttps), "bzr+http" => Some(Self::BzrHttp), "bzr+https" => Some(Self::BzrHttps), "bzr+ssh" => Some(Self::BzrSsh), @@ -510,11 +500,7 @@ impl std::fmt::Display for Scheme { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::File => write!(f, "file"), - Self::GitGit => write!(f, "git+git"), - Self::GitHttp => write!(f, "git+http"), - Self::GitFile => write!(f, "git+file"), - Self::GitSsh => write!(f, "git+ssh"), - Self::GitHttps => write!(f, "git+https"), + Self::Git(transport) => write!(f, "git+{}", transport), Self::BzrHttp => write!(f, "bzr+http"), Self::BzrHttps => write!(f, "bzr+https"), Self::BzrSsh => write!(f, "bzr+ssh"), From 43506e6d01f3331ee80cdacb3446c0e168ec8ea8 Mon Sep 17 00:00:00 2001 From: Robert Deaton Date: Sat, 2 Nov 2024 20:55:06 -0700 Subject: [PATCH 2/2] Clippy fixes --- crates/uv-pep508/src/verbatim_url.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/uv-pep508/src/verbatim_url.rs b/crates/uv-pep508/src/verbatim_url.rs index 2c1830085349..467bea6a0545 100644 --- a/crates/uv-pep508/src/verbatim_url.rs +++ b/crates/uv-pep508/src/verbatim_url.rs @@ -462,7 +462,7 @@ pub enum Scheme { impl Scheme { /// Determine the [`Scheme`] from the given string, if possible. pub fn parse(s: &str) -> Option { - if let Some(("git", transport)) = s.split_once("+") { + if let Some(("git", transport)) = s.split_once('+') { return Some(Self::Git(transport.into())); } match s { @@ -500,7 +500,7 @@ impl std::fmt::Display for Scheme { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::File => write!(f, "file"), - Self::Git(transport) => write!(f, "git+{}", transport), + Self::Git(transport) => write!(f, "git+{transport}"), Self::BzrHttp => write!(f, "bzr+http"), Self::BzrHttps => write!(f, "bzr+https"), Self::BzrSsh => write!(f, "bzr+ssh"),