Rename a few more things for clarity

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-09-22 16:15:59 +02:00
parent 62408234cf
commit 00ed8793af
No known key found for this signature in database
4 changed files with 18 additions and 13 deletions

View File

@ -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,
}

View File

@ -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<Self::Remotes, git2::Error>;
/// Return the project associated with this repository.
fn project(&self) -> Result<identity::Doc<Verified>, Error>;
fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), IdentityError>;
fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError>;
}
pub trait WriteRepository<'r>: ReadRepository<'r> {

View File

@ -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<refspec::PatternString> =
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<Option<Identity<Oid>>, IdentityError> {
Identity::load(remote, self)
}
pub fn project_of(
&self,
remote: &RemoteId,
) -> Result<Option<identity::Doc<Verified>>, refs::Error> {
@ -268,7 +273,7 @@ impl Repository {
}
/// Return the canonical identity [`git::Oid`] and document.
pub fn identity(&self) -> Result<(Oid, identity::Doc<Unverified>), IdentityError> {
pub fn project(&self) -> Result<(Oid, identity::Doc<Unverified>), 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<Unverified>), IdentityError> {
Repository::identity(self)
fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError> {
Repository::project(self)
}
}

View File

@ -132,7 +132,7 @@ impl ReadRepository<'_> for MockRepository {
fn project_identity(
&self,
) -> Result<(Oid, crate::identity::Doc<crate::crypto::Unverified>), git::IdentityError> {
) -> Result<(Oid, crate::identity::Doc<crate::crypto::Unverified>), git::ProjectError> {
todo!()
}
}