From 6f3a598cc168479394b9e88c60ecd427f099f91b Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Sun, 30 Oct 2022 12:25:10 +0100 Subject: [PATCH] Remove `git-url` dependency Signed-off-by: Alexis Sellier --- Cargo.lock | 39 -------------------------------------- radicle-node/src/wire.rs | 5 ----- radicle/Cargo.toml | 1 - radicle/src/git.rs | 24 ++++++++++++++++++++++- radicle/src/storage/git.rs | 20 ++++++------------- 5 files changed, 29 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba65e93b..89f4aa26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,16 +197,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "memchr", - "serde", -] - [[package]] name = "bumpalo" version = "3.11.0" @@ -523,19 +513,6 @@ dependencies = [ "syn", ] -[[package]] -name = "git-url" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9fcc88c679f3dc55e1e4fe0324142abec612cafaafae1bf6a951c324c9d96f8" -dependencies = [ - "bstr", - "home", - "quick-error", - "serde", - "url", -] - [[package]] name = "git2" version = "0.15.0" @@ -592,15 +569,6 @@ dependencies = [ "digest 0.10.5", ] -[[package]] -name = "home" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" -dependencies = [ - "winapi", -] - [[package]] name = "http" version = "0.2.8" @@ -1076,12 +1044,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quick-error" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" - [[package]] name = "quickcheck" version = "1.0.3" @@ -1121,7 +1083,6 @@ dependencies = [ "ed25519-compact", "fastrand", "git-ref-format", - "git-url", "git2", "log", "multibase", diff --git a/radicle-node/src/wire.rs b/radicle-node/src/wire.rs index d2014031..71709de2 100644 --- a/radicle-node/src/wire.rs +++ b/radicle-node/src/wire.rs @@ -46,11 +46,6 @@ pub enum Error { InvalidFilterSize(usize), #[error(transparent)] InvalidRefName(#[from] fmt::Error), - #[error("invalid git url `{url}`: {error}")] - InvalidGitUrl { - url: String, - error: git::url::parse::Error, - }, #[error("unknown address type `{0}`")] UnknownAddressType(u8), #[error("unknown message type `{0}`")] diff --git a/radicle/Cargo.toml b/radicle/Cargo.toml index 70aeba41..30c91095 100644 --- a/radicle/Cargo.toml +++ b/radicle/Cargo.toml @@ -17,7 +17,6 @@ crossbeam-channel = { version = "0.5.6" } ed25519-compact = { version = "1.0.12", features = ["pem"] } fastrand = { version = "1.8.0" } git-ref-format = { version = "0", features = ["serde", "macro"] } -git-url = { version = "0.3.5", features = ["serde1"] } multibase = { version = "0.9.1" } log = { version = "0.4.17", features = ["std"] } once_cell = { version = "1.13" } diff --git a/radicle/src/git.rs b/radicle/src/git.rs index 7dec3bf7..9cf1cf84 100644 --- a/radicle/src/git.rs +++ b/radicle/src/git.rs @@ -21,7 +21,6 @@ pub use git_ref_format as fmt; pub use git_ref_format::{ lit, name, qualified, refname, Component, Namespaced, Qualified, RefStr, RefString, }; -pub use git_url as url; pub use radicle_git_ext as ext; pub use storage::git::transport::local::Url; pub use storage::BranchName; @@ -351,6 +350,29 @@ where )) } +/// Git URLs. +pub mod url { + use std::path::PathBuf; + + /// A Git URL using the `file://` scheme. + pub struct File { + pub path: PathBuf, + } + + impl File { + /// Create a new file URL pointing to the given path. + pub fn new(path: PathBuf) -> Self { + Self { path } + } + } + + impl ToString for File { + fn to_string(&self) -> String { + format!("file://{}", self.path.display()) + } + } +} + /// Parsing and formatting of commit objects. /// This module exists to work with commits that have multiple signature headers. pub mod commit { diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index be5b2e86..6f21948e 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -552,12 +552,9 @@ impl WriteRepository for Repository { // TODO: Due to this, I think we'll have to run GC when there is a failure. .clone_local(git2::build::CloneLocal::Local) .clone( - &git::url::Url { - scheme: git::url::Scheme::File, - path: self.backend.path().to_string_lossy().to_string().into(), - ..git::url::Url::default() - } - .to_string(), + git::url::File::new(self.backend.path().to_path_buf()) + .to_string() + .as_str(), &path, )?; @@ -602,14 +599,9 @@ impl WriteRepository for Repository { }); { - let mut remote = self.backend.remote_anonymous( - &git::url::Url { - scheme: git::url::Scheme::File, - path: staging.to_string_lossy().to_string().into(), - ..git::url::Url::default() - } - .to_string(), - )?; + let mut remote = self + .backend + .remote_anonymous(git::url::File::new(staging).to_string().as_str())?; let mut opts = git2::FetchOptions::default(); opts.remote_callbacks(callbacks);