Rename a few more things for clarity
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
62408234cf
commit
00ed8793af
|
|
@ -92,7 +92,7 @@ pub enum ForkError {
|
||||||
#[error("project `{0}` was not found in storage")]
|
#[error("project `{0}` was not found in storage")]
|
||||||
NotFound(Id),
|
NotFound(Id),
|
||||||
#[error("project identity error: {0}")]
|
#[error("project identity error: {0}")]
|
||||||
InvalidIdentity(#[from] storage::git::IdentityError),
|
InvalidIdentity(#[from] storage::git::ProjectError),
|
||||||
#[error("git: invalid reference")]
|
#[error("git: invalid reference")]
|
||||||
InvalidReference,
|
InvalidReference,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ use crate::git::Url;
|
||||||
use crate::git::{RefError, RefStr, RefString};
|
use crate::git::{RefError, RefStr, RefString};
|
||||||
use crate::identity;
|
use crate::identity;
|
||||||
use crate::identity::{Id, IdError};
|
use crate::identity::{Id, IdError};
|
||||||
use crate::storage::git::IdentityError;
|
use crate::storage::git::ProjectError;
|
||||||
use crate::storage::refs::Refs;
|
use crate::storage::refs::Refs;
|
||||||
|
|
||||||
use self::refs::SignedRefs;
|
use self::refs::SignedRefs;
|
||||||
|
|
@ -256,7 +256,7 @@ pub trait ReadRepository<'r> {
|
||||||
fn remotes(&'r self) -> Result<Self::Remotes, git2::Error>;
|
fn remotes(&'r self) -> Result<Self::Remotes, git2::Error>;
|
||||||
/// Return the project associated with this repository.
|
/// Return the project associated with this repository.
|
||||||
fn project(&self) -> Result<identity::Doc<Verified>, Error>;
|
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> {
|
pub trait WriteRepository<'r>: ReadRepository<'r> {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
|
||||||
use crate::crypto::{Signer, Unverified, Verified};
|
use crate::crypto::{Signer, Unverified, Verified};
|
||||||
use crate::git;
|
use crate::git;
|
||||||
use crate::identity;
|
use crate::identity;
|
||||||
|
use crate::identity::project::{Identity, IdentityError};
|
||||||
use crate::identity::{Doc, Id};
|
use crate::identity::{Doc, Id};
|
||||||
use crate::storage::refs;
|
use crate::storage::refs;
|
||||||
use crate::storage::refs::{Refs, SignedRefs};
|
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"));
|
Lazy::new(|| refspec::pattern!("refs/remotes/*/radicle/signature"));
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum IdentityError {
|
pub enum ProjectError {
|
||||||
#[error("identity branches diverge from each other")]
|
#[error("identity branches diverge from each other")]
|
||||||
BranchesDiverge,
|
BranchesDiverge,
|
||||||
#[error("identity branches are in an invalid state")]
|
#[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?
|
// TODO: Don't create a repo here if it doesn't exist?
|
||||||
// Perhaps for checking we could have a `contains` method?
|
// Perhaps for checking we could have a `contains` method?
|
||||||
self.repository(proj)?
|
self.repository(proj)?
|
||||||
.identity_of(remote)
|
.project_of(remote)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,7 +257,11 @@ impl Repository {
|
||||||
Ok(())
|
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,
|
&self,
|
||||||
remote: &RemoteId,
|
remote: &RemoteId,
|
||||||
) -> Result<Option<identity::Doc<Verified>>, refs::Error> {
|
) -> Result<Option<identity::Doc<Verified>>, refs::Error> {
|
||||||
|
|
@ -268,7 +273,7 @@ impl Repository {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the canonical identity [`git::Oid`] and document.
|
/// 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();
|
let mut heads = Vec::new();
|
||||||
for remote in self.remote_ids()? {
|
for remote in self.remote_ids()? {
|
||||||
let remote = remote?;
|
let remote = remote?;
|
||||||
|
|
@ -277,7 +282,7 @@ impl Repository {
|
||||||
heads.push(oid.into());
|
heads.push(oid.into());
|
||||||
}
|
}
|
||||||
// Keep track of the longest identity branch.
|
// 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 {
|
for head in &heads {
|
||||||
let base = self.raw().merge_base(*head, longest)?;
|
let base = self.raw().merge_base(*head, longest)?;
|
||||||
|
|
@ -309,14 +314,14 @@ impl Repository {
|
||||||
// o (base)
|
// o (base)
|
||||||
// |
|
// |
|
||||||
//
|
//
|
||||||
return Err(IdentityError::BranchesDiverge);
|
return Err(ProjectError::BranchesDiverge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Doc::load_at(longest.into(), self)?
|
Doc::load_at(longest.into(), self)?
|
||||||
.ok_or(refs::Error::NotFound)
|
.ok_or(refs::Error::NotFound)
|
||||||
.map(|(doc, _)| (longest.into(), doc))
|
.map(|(doc, _)| (longest.into(), doc))
|
||||||
.map_err(IdentityError::from)
|
.map_err(ProjectError::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remote_ids(
|
pub fn remote_ids(
|
||||||
|
|
@ -439,8 +444,8 @@ impl<'r> ReadRepository<'r> for Repository {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), IdentityError> {
|
fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError> {
|
||||||
Repository::identity(self)
|
Repository::project(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ impl ReadRepository<'_> for MockRepository {
|
||||||
|
|
||||||
fn project_identity(
|
fn project_identity(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<(Oid, crate::identity::Doc<crate::crypto::Unverified>), git::IdentityError> {
|
) -> Result<(Oid, crate::identity::Doc<crate::crypto::Unverified>), git::ProjectError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue