Improve `ReadRepository` trait

This commit is contained in:
Alexis Sellier 2023-01-30 11:45:55 +01:00
parent f1a6a86689
commit 507a41d22f
No known key found for this signature in database
4 changed files with 19 additions and 16 deletions

View File

@ -164,7 +164,7 @@ pub fn fork<G: Signer, S: storage::WriteStorage>(
let me = signer.public_key(); let me = signer.public_key();
let repository = storage.repository(proj)?; let repository = storage.repository(proj)?;
// TODO: We should get the id branch pointer from a stored canonical reference. // TODO: We should get the id branch pointer from a stored canonical reference.
let (canonical_id, _) = repository.project_identity()?; let (canonical_id, _) = repository.identity_doc()?;
let (canonical_branch, canonical_head) = repository.head()?; let (canonical_branch, canonical_head) = repository.head()?;
let raw = repository.raw(); let raw = repository.raw();

View File

@ -266,7 +266,9 @@ pub trait ReadRepository {
/// The [`Path`] to the git repository. /// The [`Path`] to the git repository.
fn path(&self) -> &Path; fn path(&self) -> &Path;
fn blob_at<'a>(&'a self, oid: Oid, path: &'a Path) -> Result<git2::Blob<'a>, git_ext::Error>; /// Get a blob in this repository at the given commit and path.
fn blob_at<'a>(&'a self, commit: Oid, path: &'a Path)
-> Result<git2::Blob<'a>, git_ext::Error>;
/// Get the head of this repository. /// Get the head of this repository.
/// ///
@ -297,18 +299,27 @@ pub trait ReadRepository {
/// Returns `None` if the commit did not exist. /// Returns `None` if the commit did not exist.
fn commit(&self, oid: Oid) -> Result<git2::Commit, git_ext::Error>; fn commit(&self, oid: Oid) -> Result<git2::Commit, git_ext::Error>;
/// Perform a revision walk of a commit history starting from the given head.
fn revwalk(&self, head: Oid) -> Result<git2::Revwalk, git2::Error>; fn revwalk(&self, head: Oid) -> Result<git2::Revwalk, git2::Error>;
/// Get the object id of a reference under the given remote.
fn reference_oid( fn reference_oid(
&self, &self,
remote: &RemoteId, remote: &RemoteId,
reference: &Qualified, reference: &Qualified,
) -> Result<Oid, git_ext::Error>; ) -> Result<Oid, git_ext::Error>;
/// Get all references of the given remote.
fn references_of(&self, remote: &RemoteId) -> Result<Refs, Error>; fn references_of(&self, remote: &RemoteId) -> Result<Refs, Error>;
/// Get the given remote.
fn remote(&self, remote: &RemoteId) -> Result<Remote<Verified>, refs::Error>; fn remote(&self, remote: &RemoteId) -> Result<Remote<Verified>, refs::Error>;
/// Get all remotes.
fn remotes(&self) -> Result<Remotes<Verified>, refs::Error>; fn remotes(&self) -> Result<Remotes<Verified>, refs::Error>;
/// Return the project associated with this repository.
fn project(&self) -> Result<identity::Doc<Verified>, Error>; /// Get the repository's identity document.
fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError>; fn identity_doc(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError>;
} }
pub trait WriteRepository: ReadRepository { pub trait WriteRepository: ReadRepository {

View File

@ -531,11 +531,7 @@ impl ReadRepository for Repository {
Ok(Remotes::from_iter(remotes)) Ok(Remotes::from_iter(remotes))
} }
fn project(&self) -> Result<Doc<Verified>, Error> { fn identity_doc(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError> {
todo!()
}
fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError> {
Repository::identity_doc(self) Repository::identity_doc(self)
} }
@ -552,7 +548,7 @@ impl ReadRepository for Repository {
fn canonical_head(&self) -> Result<(Qualified, Oid), ProjectError> { fn canonical_head(&self) -> Result<(Qualified, Oid), ProjectError> {
// TODO: In the `fork` function for example, we call Repository::project_identity again, // TODO: In the `fork` function for example, we call Repository::project_identity again,
// This should only be necessary once. // This should only be necessary once.
let (_, doc) = self.project_identity()?; let (_, doc) = self.identity_doc()?;
let doc = doc.verified()?; let doc = doc.verified()?;
let project = doc.project()?; let project = doc.project()?;
let branch_ref = Qualified::from(lit::refs_heads(&project.default_branch())); let branch_ref = Qualified::from(lit::refs_heads(&project.default_branch()));

View File

@ -120,11 +120,7 @@ impl ReadRepository for MockRepository {
todo!() todo!()
} }
fn project(&self) -> Result<Doc<Verified>, Error> { fn identity_doc(
todo!()
}
fn project_identity(
&self, &self,
) -> Result<(Oid, crate::identity::Doc<crate::crypto::Unverified>), git::ProjectError> { ) -> Result<(Oid, crate::identity::Doc<crate::crypto::Unverified>), git::ProjectError> {
todo!() todo!()