mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-21 02:20:44 +08:00
radicle-surf: refactor source objects
Refactor the source data types to reuse existing logic and update to the latest protocol. The `Blob` and `Tree` data types are updated to be backed by `File` and `Directory` respectively. This allows the construction of them to be much simpler and reuse any existing logic on those types. This also lead to the removal of `ObjectType` and `Info`. The `Revision` type was removed in favour of using the `Revision` trait. The `Revisions` type was renamed to `View`, while also renaming the `revision` module to `view`. A `View` is a simple encoding of what a peer's "view" would look like, i.e. what references do they have. This also required the introduction of getting free-form categories in the reference db, i.e. `refs/<category>`, and so a `Categories` iterator was also introduced. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
+29
-5
@@ -167,6 +167,14 @@ impl Revision for &str {
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for Branch {
|
||||
type Error = Error;
|
||||
|
||||
fn object_id(&self, repo: &Repository) -> Result<Oid, Self::Error> {
|
||||
(&self).object_id(repo)
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for &Branch {
|
||||
type Error = Error;
|
||||
|
||||
@@ -176,6 +184,14 @@ impl Revision for &Branch {
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for Tag {
|
||||
type Error = Infallible;
|
||||
|
||||
fn object_id(&self, repo: &Repository) -> Result<Oid, Self::Error> {
|
||||
(&self).object_id(repo)
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for &Tag {
|
||||
type Error = Infallible;
|
||||
|
||||
@@ -184,27 +200,35 @@ impl Revision for &Tag {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Revision> Revision for Box<R> {
|
||||
type Error = R::Error;
|
||||
|
||||
fn object_id(&self, repo: &Repository) -> Result<Oid, Self::Error> {
|
||||
self.as_ref().object_id(repo)
|
||||
}
|
||||
}
|
||||
|
||||
/// A common trait for anything that can convert to a `Commit`.
|
||||
pub trait ToCommit {
|
||||
type Error: std::error::Error + Send + Sync + 'static;
|
||||
|
||||
/// Converts to a commit in `repo`.
|
||||
fn to_commit(self, repo: &Repository) -> Result<Commit, Self::Error>;
|
||||
fn to_commit(&self, repo: &Repository) -> Result<Commit, Self::Error>;
|
||||
}
|
||||
|
||||
impl ToCommit for Commit {
|
||||
type Error = Infallible;
|
||||
|
||||
fn to_commit(self, _repo: &Repository) -> Result<Commit, Self::Error> {
|
||||
Ok(self)
|
||||
fn to_commit(&self, _repo: &Repository) -> Result<Commit, Self::Error> {
|
||||
Ok(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Revision> ToCommit for R {
|
||||
type Error = Error;
|
||||
|
||||
fn to_commit(self, repo: &Repository) -> Result<Commit, Self::Error> {
|
||||
let oid = repo.object_id(&self)?;
|
||||
fn to_commit(&self, repo: &Repository) -> Result<Commit, Self::Error> {
|
||||
let oid = repo.object_id(self)?;
|
||||
let commit = repo.git2_repo().find_commit(oid.into())?;
|
||||
Ok(Commit::try_from(commit)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user