diff --git a/radicle/src/storage.rs b/radicle/src/storage.rs index bdc8c70e..9935c362 100644 --- a/radicle/src/storage.rs +++ b/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; + /// Check if the underlying ODB contains the given `oid`. + fn contains(&self, oid: Oid) -> Result; + /// Check whether the given commit is an ancestor of another commit. fn is_ancestor_of(&self, ancestor: Oid, head: Oid) -> Result; diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 3ae20434..20b4d829 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -565,6 +565,10 @@ impl ReadRepository for Repository { Ok(revwalk) } + fn contains(&self, oid: Oid) -> Result { + self.backend.odb().map(|odb| odb.exists(oid.into())) + } + fn is_ancestor_of(&self, ancestor: Oid, head: Oid) -> Result { self.backend .graph_descendant_of(head.into(), ancestor.into()) diff --git a/radicle/src/storage/git/cob.rs b/radicle/src/storage/git/cob.rs index 7c1be334..e5216b38 100644 --- a/radicle/src/storage/git/cob.rs +++ b/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 { + self.repo.contains(oid) + } + fn is_ancestor_of(&self, ancestor: Oid, head: Oid) -> Result { self.repo.is_ancestor_of(ancestor, head) } diff --git a/radicle/src/test/storage.rs b/radicle/src/test/storage.rs index 7c20a1ff..9f1f32ce 100644 --- a/radicle/src/test/storage.rs +++ b/radicle/src/test/storage.rs @@ -188,6 +188,13 @@ impl ReadRepository for MockRepository { todo!() } + fn contains(&self, oid: Oid) -> Result { + 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 { Ok(true) }