Improve some project path code

This commit is contained in:
Alexis Sellier 2022-09-26 15:34:03 +02:00
parent ca2f766d19
commit c991c0eea0
No known key found for this signature in database
2 changed files with 20 additions and 12 deletions

View File

@ -2,8 +2,7 @@
//! //!
//! $RAD_HOME/ # Radicle home //! $RAD_HOME/ # Radicle home
//! storage/ # Storage root //! storage/ # Storage root
//! zEQNunJUqkNahQ8VvQYuWZZV7EJB/ # Project root //! zEQNunJUqkNahQ8VvQYuWZZV7EJB/ # Project git repository
//! git/ # Project Git repository
//! ... # More projects... //! ... # More projects...
//! keys/ //! keys/
//! radicle # Secret key (PKCS 8) //! radicle # Secret key (PKCS 8)

View File

@ -56,7 +56,7 @@ impl ReadStorage for Storage {
} }
fn url(&self, proj: &Id) -> Url { fn url(&self, proj: &Id) -> Url {
let path = self.path().join(proj.to_string()); let path = paths::repository(self, proj);
Url { Url {
scheme: git_url::Scheme::File, scheme: git_url::Scheme::File,
@ -83,7 +83,7 @@ impl WriteStorage for Storage {
type Repository = Repository; type Repository = Repository;
fn repository(&self, proj: &Id) -> Result<Self::Repository, Error> { fn repository(&self, proj: &Id) -> Result<Self::Repository, Error> {
Repository::open(self.path.join(proj.to_string())) Repository::open(paths::repository(self, proj))
} }
fn sign_refs<G: Signer>( fn sign_refs<G: Signer>(
@ -609,6 +609,17 @@ pub mod trailers {
} }
} }
pub mod paths {
use std::path::PathBuf;
use super::Id;
use super::ReadStorage;
pub fn repository<S: ReadStorage>(storage: &S, proj: &Id) -> PathBuf {
storage.path().join(proj.to_string())
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -628,9 +639,11 @@ mod tests {
let inv = storage.inventory().unwrap(); let inv = storage.inventory().unwrap();
let proj = inv.first().unwrap(); let proj = inv.first().unwrap();
let mut refs = git::remote_refs(&git::Url { let mut refs = git::remote_refs(&git::Url {
host: Some(storage.path().to_string_lossy().to_string()),
scheme: git_url::Scheme::File, scheme: git_url::Scheme::File,
path: format!("/{}", proj).into(), path: paths::repository(&storage, proj)
.to_string_lossy()
.into_owned()
.into(),
..git::Url::default() ..git::Url::default()
}) })
.unwrap(); .unwrap();
@ -669,9 +682,7 @@ mod tests {
.unwrap() .unwrap()
.fetch(&git::Url { .fetch(&git::Url {
scheme: git_url::Scheme::File, scheme: git_url::Scheme::File,
path: alice path: paths::repository(&alice, proj)
.path()
.join(proj.to_string())
.to_string_lossy() .to_string_lossy()
.into_owned() .into_owned()
.into(), .into(),
@ -715,9 +726,7 @@ mod tests {
let refname = git::refname!("refs/heads/master"); let refname = git::refname!("refs/heads/master");
let alice_url = git::Url { let alice_url = git::Url {
scheme: git_url::Scheme::File, scheme: git_url::Scheme::File,
path: alice path: paths::repository(&alice, &proj_id)
.path()
.join(proj_id.to_string())
.to_string_lossy() .to_string_lossy()
.into_owned() .into_owned()
.into(), .into(),