Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: add ReadRepository::contains
Fintan Halpenny committed 2 years ago
commit ac849f1fd5ec61051d77bd21b371f082fa4f48c6
parent 40303cd8e158cf3620c370c566c26c4cf2792852
4 files changed +18 -0
modified radicle/src/storage.rs
@@ -433,6 +433,9 @@ pub trait ReadRepository: Sized + ValidateRepository {
    /// Perform a revision walk of a commit history starting from the given head.
    fn revwalk(&self, head: Oid) -> Result<git2::Revwalk, git2::Error>;

+
    /// Check if the underlying ODB contains the given `oid`.
+
    fn contains(&self, oid: Oid) -> Result<bool, git2::Error>;
+

    /// Check whether the given commit is an ancestor of another commit.
    fn is_ancestor_of(&self, ancestor: Oid, head: Oid) -> Result<bool, git::ext::Error>;

modified radicle/src/storage/git.rs
@@ -565,6 +565,10 @@ impl ReadRepository for Repository {
        Ok(revwalk)
    }

+
    fn contains(&self, oid: Oid) -> Result<bool, raw::Error> {
+
        self.backend.odb().map(|odb| odb.exists(oid.into()))
+
    }
+

    fn is_ancestor_of(&self, ancestor: Oid, head: Oid) -> Result<bool, git::Error> {
        self.backend
            .graph_descendant_of(head.into(), ancestor.into())
modified radicle/src/storage/git/cob.rs
@@ -278,6 +278,10 @@ impl<'a, R: storage::ReadRepository> ReadRepository for DraftStore<'a, R> {
        self.repo.revwalk(head)
    }

+
    fn contains(&self, oid: Oid) -> Result<bool, raw::Error> {
+
        self.repo.contains(oid)
+
    }
+

    fn is_ancestor_of(&self, ancestor: Oid, head: Oid) -> Result<bool, git_ext::Error> {
        self.repo.is_ancestor_of(ancestor, head)
    }
modified radicle/src/test/storage.rs
@@ -188,6 +188,13 @@ impl ReadRepository for MockRepository {
        todo!()
    }

+
    fn contains(&self, oid: Oid) -> Result<bool, git2::Error> {
+
        Ok(self
+
            .remotes
+
            .values()
+
            .any(|sigrefs| sigrefs.at == oid || sigrefs.refs.values().any(|oid_| *oid_ == oid)))
+
    }
+

    fn is_ancestor_of(&self, _ancestor: Oid, _head: Oid) -> Result<bool, git_ext::Error> {
        Ok(true)
    }