From c991c0eea00996250aa7c60595b6e9d41d8a75b8 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 26 Sep 2022 15:34:03 +0200 Subject: [PATCH] Improve some project path code --- radicle/src/profile.rs | 3 +-- radicle/src/storage/git.rs | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index 0abc60e9..f2e063f1 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -2,8 +2,7 @@ //! //! $RAD_HOME/ # Radicle home //! storage/ # Storage root -//! zEQNunJUqkNahQ8VvQYuWZZV7EJB/ # Project root -//! git/ # Project Git repository +//! zEQNunJUqkNahQ8VvQYuWZZV7EJB/ # Project git repository //! ... # More projects... //! keys/ //! radicle # Secret key (PKCS 8) diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index ac1e71f6..7cc95eed 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -56,7 +56,7 @@ impl ReadStorage for Storage { } fn url(&self, proj: &Id) -> Url { - let path = self.path().join(proj.to_string()); + let path = paths::repository(self, proj); Url { scheme: git_url::Scheme::File, @@ -83,7 +83,7 @@ impl WriteStorage for Storage { type Repository = Repository; fn repository(&self, proj: &Id) -> Result { - Repository::open(self.path.join(proj.to_string())) + Repository::open(paths::repository(self, proj)) } fn sign_refs( @@ -609,6 +609,17 @@ pub mod trailers { } } +pub mod paths { + use std::path::PathBuf; + + use super::Id; + use super::ReadStorage; + + pub fn repository(storage: &S, proj: &Id) -> PathBuf { + storage.path().join(proj.to_string()) + } +} + #[cfg(test)] mod tests { use super::*; @@ -628,9 +639,11 @@ mod tests { let inv = storage.inventory().unwrap(); let proj = inv.first().unwrap(); let mut refs = git::remote_refs(&git::Url { - host: Some(storage.path().to_string_lossy().to_string()), scheme: git_url::Scheme::File, - path: format!("/{}", proj).into(), + path: paths::repository(&storage, proj) + .to_string_lossy() + .into_owned() + .into(), ..git::Url::default() }) .unwrap(); @@ -669,9 +682,7 @@ mod tests { .unwrap() .fetch(&git::Url { scheme: git_url::Scheme::File, - path: alice - .path() - .join(proj.to_string()) + path: paths::repository(&alice, proj) .to_string_lossy() .into_owned() .into(), @@ -715,9 +726,7 @@ mod tests { let refname = git::refname!("refs/heads/master"); let alice_url = git::Url { scheme: git_url::Scheme::File, - path: alice - .path() - .join(proj_id.to_string()) + path: paths::repository(&alice, &proj_id) .to_string_lossy() .into_owned() .into(),