Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Improve `ReadRepository` trait
Alexis Sellier committed 3 years ago
commit 507a41d22f9c9b93cd079492c7432a2976a7fd24
parent f1a6a86689ce6a5b6fb59b8c299ee4a05e28c144
4 files changed +19 -16
modified radicle/src/rad.rs
@@ -164,7 +164,7 @@ pub fn fork<G: Signer, S: storage::WriteStorage>(
    let me = signer.public_key();
    let repository = storage.repository(proj)?;
    // 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 raw = repository.raw();

modified radicle/src/storage.rs
@@ -266,7 +266,9 @@ pub trait ReadRepository {
    /// The [`Path`] to the git repository.
    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.
    ///
@@ -297,18 +299,27 @@ pub trait ReadRepository {
    /// Returns `None` if the commit did not exist.
    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>;
+

+
    /// Get the object id of a reference under the given remote.
    fn reference_oid(
        &self,
        remote: &RemoteId,
        reference: &Qualified,
    ) -> Result<Oid, git_ext::Error>;
+

+
    /// Get all references of the given remote.
    fn references_of(&self, remote: &RemoteId) -> Result<Refs, Error>;
+

+
    /// Get the given remote.
    fn remote(&self, remote: &RemoteId) -> Result<Remote<Verified>, refs::Error>;
+

+
    /// Get all remotes.
    fn remotes(&self) -> Result<Remotes<Verified>, refs::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>), ProjectError>;
+

+
    /// Get the repository's identity document.
+
    fn identity_doc(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError>;
}

pub trait WriteRepository: ReadRepository {
modified radicle/src/storage/git.rs
@@ -531,11 +531,7 @@ impl ReadRepository for Repository {
        Ok(Remotes::from_iter(remotes))
    }

-
    fn project(&self) -> Result<Doc<Verified>, Error> {
-
        todo!()
-
    }
-

-
    fn project_identity(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError> {
+
    fn identity_doc(&self) -> Result<(Oid, identity::Doc<Unverified>), ProjectError> {
        Repository::identity_doc(self)
    }

@@ -552,7 +548,7 @@ impl ReadRepository for Repository {
    fn canonical_head(&self) -> Result<(Qualified, Oid), ProjectError> {
        // TODO: In the `fork` function for example, we call Repository::project_identity again,
        // This should only be necessary once.
-
        let (_, doc) = self.project_identity()?;
+
        let (_, doc) = self.identity_doc()?;
        let doc = doc.verified()?;
        let project = doc.project()?;
        let branch_ref = Qualified::from(lit::refs_heads(&project.default_branch()));
modified radicle/src/test/storage.rs
@@ -120,11 +120,7 @@ impl ReadRepository for MockRepository {
        todo!()
    }

-
    fn project(&self) -> Result<Doc<Verified>, Error> {
-
        todo!()
-
    }
-

-
    fn project_identity(
+
    fn identity_doc(
        &self,
    ) -> Result<(Oid, crate::identity::Doc<crate::crypto::Unverified>), git::ProjectError> {
        todo!()