diff --git a/radicle/src/rad.rs b/radicle/src/rad.rs index 87dfff83..7238b9c5 100644 --- a/radicle/src/rad.rs +++ b/radicle/src/rad.rs @@ -92,7 +92,7 @@ pub enum ForkError { #[error("project `{0}` was not found in storage")] NotFound(Id), #[error("project identity error: {0}")] - InvalidIdentity(#[from] storage::git::IdentityError), + InvalidIdentity(#[from] storage::git::ProjectError), #[error("git: invalid reference")] InvalidReference, } diff --git a/radicle/src/storage.rs b/radicle/src/storage.rs index 6c13df04..d5655ada 100644 --- a/radicle/src/storage.rs +++ b/radicle/src/storage.rs @@ -19,7 +19,7 @@ use crate::git::Url; use crate::git::{RefError, RefStr, RefString}; use crate::identity; use crate::identity::{Id, IdError}; -use crate::storage::git::IdentityError; +use crate::storage::git::ProjectError; use crate::storage::refs::Refs; use self::refs::SignedRefs; @@ -256,7 +256,7 @@ pub trait ReadRepository<'r> { fn remotes(&'r self) -> Result; /// Return the project associated with this repository. fn project(&self) -> Result, Error>; - fn project_identity(&self) -> Result<(Oid, identity::Doc), IdentityError>; + fn project_identity(&self) -> Result<(Oid, identity::Doc), ProjectError>; } pub trait WriteRepository<'r>: ReadRepository<'r> { diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 0cc3383f..6e530f58 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -8,6 +8,7 @@ use once_cell::sync::Lazy; use crate::crypto::{Signer, Unverified, Verified}; use crate::git; use crate::identity; +use crate::identity::project::{Identity, IdentityError}; use crate::identity::{Doc, Id}; use crate::storage::refs; use crate::storage::refs::{Refs, SignedRefs}; @@ -26,7 +27,7 @@ pub static SIGNATURES_GLOB: Lazy = Lazy::new(|| refspec::pattern!("refs/remotes/*/radicle/signature")); #[derive(Error, Debug)] -pub enum IdentityError { +pub enum ProjectError { #[error("identity branches diverge from each other")] BranchesDiverge, #[error("identity branches are in an invalid state")] @@ -69,7 +70,7 @@ impl ReadStorage for Storage { // TODO: Don't create a repo here if it doesn't exist? // Perhaps for checking we could have a `contains` method? self.repository(proj)? - .identity_of(remote) + .project_of(remote) .map_err(Error::from) } @@ -256,7 +257,11 @@ impl Repository { Ok(()) } - pub fn identity_of( + pub fn identity(&self, remote: &RemoteId) -> Result>, IdentityError> { + Identity::load(remote, self) + } + + pub fn project_of( &self, remote: &RemoteId, ) -> Result>, refs::Error> { @@ -268,7 +273,7 @@ impl Repository { } /// Return the canonical identity [`git::Oid`] and document. - pub fn identity(&self) -> Result<(Oid, identity::Doc), IdentityError> { + pub fn project(&self) -> Result<(Oid, identity::Doc), ProjectError> { let mut heads = Vec::new(); for remote in self.remote_ids()? { let remote = remote?; @@ -277,7 +282,7 @@ impl Repository { heads.push(oid.into()); } // Keep track of the longest identity branch. - let mut longest = heads.pop().ok_or(IdentityError::InvalidState)?; + let mut longest = heads.pop().ok_or(ProjectError::InvalidState)?; for head in &heads { let base = self.raw().merge_base(*head, longest)?; @@ -309,14 +314,14 @@ impl Repository { // o (base) // | // - return Err(IdentityError::BranchesDiverge); + return Err(ProjectError::BranchesDiverge); } } Doc::load_at(longest.into(), self)? .ok_or(refs::Error::NotFound) .map(|(doc, _)| (longest.into(), doc)) - .map_err(IdentityError::from) + .map_err(ProjectError::from) } pub fn remote_ids( @@ -439,8 +444,8 @@ impl<'r> ReadRepository<'r> for Repository { todo!() } - fn project_identity(&self) -> Result<(Oid, identity::Doc), IdentityError> { - Repository::identity(self) + fn project_identity(&self) -> Result<(Oid, identity::Doc), ProjectError> { + Repository::project(self) } } diff --git a/radicle/src/test/storage.rs b/radicle/src/test/storage.rs index 9d72530c..ef2452fe 100644 --- a/radicle/src/test/storage.rs +++ b/radicle/src/test/storage.rs @@ -132,7 +132,7 @@ impl ReadRepository<'_> for MockRepository { fn project_identity( &self, - ) -> Result<(Oid, crate::identity::Doc), git::IdentityError> { + ) -> Result<(Oid, crate::identity::Doc), git::ProjectError> { todo!() } }