Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Resolve conflict
✗ CI failure Adrian Duke committed 24 days ago
commit 46d916fac0a6cb4a877c41768217607a10a2ccd9
parent 832d377d58c273c26e07b7f75b14723663a413b5
1 failed (1 total) View logs
10 files changed +174 -174
modified crates/radicle/src/git/repository.rs
@@ -11,7 +11,7 @@
//!
//! [`reference`]: self::reference

-
pub mod ancestry;
+
pub mod antecedent;
pub mod object;
pub mod reference;
pub mod revwalk;
@@ -19,8 +19,8 @@ pub mod types;

mod adapter;

-
pub use ancestry::{AheadBehind, Ancestry};
-
pub use object::{ObjectReader, ObjectWriter};
+
pub use antecedent::{AheadBehind, Ancestry};
+
pub use object::{Reader as ObjectReader, Writer as ObjectWriter};
pub use reference::{RefReader, RefTarget, RefWriter, SymbolicRefTarget, SymbolicRefWriter};
pub use revwalk::{Revwalk, RevwalkPlan, SortOrder};
pub use types::{Blob, Commit, ObjectKind, TreeEntry};
modified crates/radicle/src/git/repository/adapter/git2/ancestry.rs
@@ -1,62 +1,62 @@
use radicle_oid::Oid;

use crate::git::raw;
-
use crate::git::repository::ancestry;
-
use crate::git::repository::ancestry::{AheadBehind, Ancestry};
+
use crate::git::repository::antecedent;
+
use crate::git::repository::antecedent::{AheadBehind, Ancestry};

use super::NotFound as _;

impl Ancestry for raw::Repository {
-
    fn merge_base(&self, a: Oid, b: Oid) -> Result<Option<Oid>, ancestry::MergeBaseError> {
-
        let odb = self.odb().map_err(ancestry::MergeBaseError::backend)?;
+
    fn merge_base(&self, a: Oid, b: Oid) -> Result<Option<Oid>, antecedent::MergeBaseError> {
+
        let odb = self.odb().map_err(antecedent::MergeBaseError::backend)?;

        if !odb.exists(a.into()) {
-
            return Err(ancestry::MergeBaseError::CommitNotFound { oid: a });
+
            return Err(antecedent::MergeBaseError::CommitNotFound { oid: a });
        }

        if !odb.exists(b.into()) {
-
            return Err(ancestry::MergeBaseError::CommitNotFound { oid: b });
+
            return Err(antecedent::MergeBaseError::CommitNotFound { oid: b });
        }

        self.merge_base(a.into(), b.into())
            .map(Oid::from)
            .or_is_not_found()
-
            .map_err(ancestry::MergeBaseError::backend)
+
            .map_err(antecedent::MergeBaseError::backend)
    }

-
    fn is_ancestor(&self, ancestor: Oid, head: Oid) -> Result<bool, ancestry::IsAncestorError> {
-
        let odb = self.odb().map_err(ancestry::IsAncestorError::backend)?;
+
    fn is_ancestor(&self, ancestor: Oid, head: Oid) -> Result<bool, antecedent::IsAncestorError> {
+
        let odb = self.odb().map_err(antecedent::IsAncestorError::backend)?;

        if !odb.exists(ancestor.into()) {
-
            return Err(ancestry::IsAncestorError::CommitNotFound { oid: ancestor });
+
            return Err(antecedent::IsAncestorError::CommitNotFound { oid: ancestor });
        }

        if !odb.exists(head.into()) {
-
            return Err(ancestry::IsAncestorError::CommitNotFound { oid: head });
+
            return Err(antecedent::IsAncestorError::CommitNotFound { oid: head });
        }

        self.graph_descendant_of(head.into(), ancestor.into())
-
            .map_err(ancestry::IsAncestorError::backend)
+
            .map_err(antecedent::IsAncestorError::backend)
    }

    fn ahead_behind(
        &self,
        commit: Oid,
        upstream: Oid,
-
    ) -> Result<AheadBehind, ancestry::AheadBehindError> {
-
        let odb = self.odb().map_err(ancestry::AheadBehindError::backend)?;
+
    ) -> Result<AheadBehind, antecedent::AheadBehindError> {
+
        let odb = self.odb().map_err(antecedent::AheadBehindError::backend)?;

        if !odb.exists(commit.into()) {
-
            return Err(ancestry::AheadBehindError::CommitNotFound { oid: commit });
+
            return Err(antecedent::AheadBehindError::CommitNotFound { oid: commit });
        }

        if !odb.exists(upstream.into()) {
-
            return Err(ancestry::AheadBehindError::CommitNotFound { oid: upstream });
+
            return Err(antecedent::AheadBehindError::CommitNotFound { oid: upstream });
        }

        let (ahead, behind) = self
            .graph_ahead_behind(commit.into(), upstream.into())
-
            .map_err(ancestry::AheadBehindError::backend)?;
+
            .map_err(antecedent::AheadBehindError::backend)?;
        Ok(AheadBehind { ahead, behind })
    }
}
modified crates/radicle/src/git/repository/adapter/git2/object.rs
@@ -5,7 +5,7 @@ use radicle_oid::Oid;
use crate::git;
use crate::git::raw;
use crate::git::repository::object::error::{read, write};
-
use crate::git::repository::object::{ObjectReader, ObjectWriter};
+
use crate::git::repository::object::{Reader as ObjectReader, Writer as ObjectWriter};
use crate::git::repository::types::{Blob, Commit, ObjectKind, TreeEntry};

use super::NotFound as _;
deleted crates/radicle/src/git/repository/ancestry.rs
@@ -1,56 +0,0 @@
-
//! Git commit graph ancestry trait.
-
//!
-
//! [`Ancestry`] provides merge-base, ancestor checks, and ahead/behind counts.
-

-
pub mod error;
-
pub use error::{AheadBehindError, IsAncestorError, MergeBaseError};
-

-
use radicle_oid::Oid;
-

-
/// The result of [`Ancestry::ahead_behind`].
-
pub struct AheadBehind {
-
    /// The given commit was ahead of the upstream by this many commits.
-
    pub ahead: usize,
-
    /// The given commit was behind the upstream by this many commits.
-
    pub behind: usize,
-
}
-

-
/// Git commit graph operations.
-
///
-
/// Provides merge-base computation and ancestor checks.
-
pub trait Ancestry {
-
    /// Find the merge base (common ancestor) of two commits.
-
    ///
-
    /// Returns `Ok(None)` if there is no common ancestor.
-
    ///
-
    /// # Errors
-
    ///
-
    /// - [`CommitNotFound`]: One of the commits was not found.
-
    /// - [`Backend`]: An unexpected error from the underlying git library.
-
    ///
-
    /// [`CommitNotFound`]: MergeBaseError::CommitNotFound
-
    /// [`Backend`]: MergeBaseError::Backend
-
    fn merge_base(&self, a: Oid, b: Oid) -> Result<Option<Oid>, MergeBaseError>;
-

-
    /// Check whether `ancestor` is an ancestor of `head`.
-
    ///
-
    /// # Errors
-
    ///
-
    /// - [`CommitNotFound`]: One of the commits was not found.
-
    /// - [`Backend`]: An unexpected error from the underlying git library.
-
    ///
-
    /// [`CommitNotFound`]: IsAncestorError::CommitNotFound
-
    /// [`Backend`]: IsAncestorError::Backend
-
    fn is_ancestor(&self, ancestor: Oid, head: Oid) -> Result<bool, IsAncestorError>;
-

-
    /// Count how many commits `commit` is ahead of and behind `upstream`.
-
    ///
-
    /// # Errors
-
    ///
-
    /// - [`CommitNotFound`]: One of the commits was not found.
-
    /// - [`Backend`]: An unexpected error from the underlying git library.
-
    ///
-
    /// [`CommitNotFound`]: AheadBehindError::CommitNotFound
-
    /// [`Backend`]: AheadBehindError::Backend
-
    fn ahead_behind(&self, commit: Oid, upstream: Oid) -> Result<AheadBehind, AheadBehindError>;
-
}
deleted crates/radicle/src/git/repository/ancestry/error.rs
@@ -1,75 +0,0 @@
-
//! Errors returned by [`Ancestry`] methods.
-
//!
-
//! [`Ancestry`]: super::Ancestry
-

-
use radicle_oid::Oid;
-
use thiserror::Error;
-

-
/// Error returned by [`Ancestry::merge_base`].
-
///
-
/// [`Ancestry::merge_base`]: super::Ancestry::merge_base
-
#[derive(Debug, Error)]
-
#[non_exhaustive]
-
pub enum MergeBaseError {
-
    /// One of the commits could not be found
-
    #[error("failed to find commit '{oid}' during merge base calculation")]
-
    CommitNotFound { oid: Oid },
-
    /// An error from the underlying git library.
-
    #[error(transparent)]
-
    Backend(Box<dyn std::error::Error + Send + Sync + 'static>),
-
}
-

-
impl MergeBaseError {
-
    pub fn backend<E>(err: E) -> Self
-
    where
-
        E: std::error::Error + Send + Sync + 'static,
-
    {
-
        Self::Backend(Box::new(err))
-
    }
-
}
-

-
/// Error returned by [`Ancestry::is_ancestor`].
-
///
-
/// [`Ancestry::is_ancestor`]: super::Ancestry::is_ancestor
-
#[derive(Debug, Error)]
-
#[non_exhaustive]
-
pub enum IsAncestorError {
-
    /// One of the commits could not be found.
-
    #[error("failed to find commit '{oid}'")]
-
    CommitNotFound { oid: Oid },
-
    /// An error from the underlying git library.
-
    #[error(transparent)]
-
    Backend(Box<dyn std::error::Error + Send + Sync + 'static>),
-
}
-

-
impl IsAncestorError {
-
    pub fn backend<E>(err: E) -> Self
-
    where
-
        E: std::error::Error + Send + Sync + 'static,
-
    {
-
        Self::Backend(Box::new(err))
-
    }
-
}
-

-
/// Error returned by [`Ancestry::ahead_behind`].
-
///
-
/// [`Ancestry::ahead_behind`]: super::Ancestry::ahead_behind
-
#[derive(Debug, Error)]
-
#[non_exhaustive]
-
pub enum AheadBehindError {
-
    /// One of the commits was not found.
-
    #[error("commit '{oid}' was not found")]
-
    CommitNotFound { oid: Oid },
-
    /// An error from the underlying git library.
-
    #[error(transparent)]
-
    Backend(Box<dyn std::error::Error + Send + Sync + 'static>),
-
}
-

-
impl AheadBehindError {
-
    pub fn backend<E>(err: E) -> Self
-
    where
-
        E: std::error::Error + Send + Sync + 'static,
-
    {
-
        Self::Backend(Box::new(err))
-
    }
-
}
added crates/radicle/src/git/repository/antecedent.rs
@@ -0,0 +1,56 @@
+
//! Git commit graph ancestry trait.
+
//!
+
//! [`Ancestry`] provides merge-base, ancestor checks, and ahead/behind counts.
+

+
pub mod error;
+
pub use error::{AheadBehindError, IsAncestorError, MergeBaseError};
+

+
use radicle_oid::Oid;
+

+
/// The result of [`Ancestry::ahead_behind`].
+
pub struct AheadBehind {
+
    /// The given commit was ahead of the upstream by this many commits.
+
    pub ahead: usize,
+
    /// The given commit was behind the upstream by this many commits.
+
    pub behind: usize,
+
}
+

+
/// Git commit graph operations.
+
///
+
/// Provides merge-base computation and ancestor checks.
+
pub trait Ancestry {
+
    /// Find the merge base (common ancestor) of two commits.
+
    ///
+
    /// Returns `Ok(None)` if there is no common ancestor.
+
    ///
+
    /// # Errors
+
    ///
+
    /// - [`CommitNotFound`]: One of the commits was not found.
+
    /// - [`Backend`]: An unexpected error from the underlying git library.
+
    ///
+
    /// [`CommitNotFound`]: MergeBaseError::CommitNotFound
+
    /// [`Backend`]: MergeBaseError::Backend
+
    fn merge_base(&self, a: Oid, b: Oid) -> Result<Option<Oid>, MergeBaseError>;
+

+
    /// Check whether `ancestor` is an ancestor of `head`.
+
    ///
+
    /// # Errors
+
    ///
+
    /// - [`CommitNotFound`]: One of the commits was not found.
+
    /// - [`Backend`]: An unexpected error from the underlying git library.
+
    ///
+
    /// [`CommitNotFound`]: IsAncestorError::CommitNotFound
+
    /// [`Backend`]: IsAncestorError::Backend
+
    fn is_ancestor(&self, ancestor: Oid, head: Oid) -> Result<bool, IsAncestorError>;
+

+
    /// Count how many commits `commit` is ahead of and behind `upstream`.
+
    ///
+
    /// # Errors
+
    ///
+
    /// - [`CommitNotFound`]: One of the commits was not found.
+
    /// - [`Backend`]: An unexpected error from the underlying git library.
+
    ///
+
    /// [`CommitNotFound`]: AheadBehindError::CommitNotFound
+
    /// [`Backend`]: AheadBehindError::Backend
+
    fn ahead_behind(&self, commit: Oid, upstream: Oid) -> Result<AheadBehind, AheadBehindError>;
+
}
added crates/radicle/src/git/repository/antecedent/error.rs
@@ -0,0 +1,75 @@
+
//! Errors returned by [`Ancestry`] methods.
+
//!
+
//! [`Ancestry`]: super::Ancestry
+

+
use radicle_oid::Oid;
+
use thiserror::Error;
+

+
/// Error returned by [`Ancestry::merge_base`].
+
///
+
/// [`Ancestry::merge_base`]: super::Ancestry::merge_base
+
#[derive(Debug, Error)]
+
#[non_exhaustive]
+
pub enum MergeBaseError {
+
    /// One of the commits could not be found
+
    #[error("failed to find commit '{oid}' during merge base calculation")]
+
    CommitNotFound { oid: Oid },
+
    /// An error from the underlying git library.
+
    #[error(transparent)]
+
    Backend(Box<dyn std::error::Error + Send + Sync + 'static>),
+
}
+

+
impl MergeBaseError {
+
    pub fn backend<E>(err: E) -> Self
+
    where
+
        E: std::error::Error + Send + Sync + 'static,
+
    {
+
        Self::Backend(Box::new(err))
+
    }
+
}
+

+
/// Error returned by [`Ancestry::is_ancestor`].
+
///
+
/// [`Ancestry::is_ancestor`]: super::Ancestry::is_ancestor
+
#[derive(Debug, Error)]
+
#[non_exhaustive]
+
pub enum IsAncestorError {
+
    /// One of the commits could not be found.
+
    #[error("failed to find commit '{oid}'")]
+
    CommitNotFound { oid: Oid },
+
    /// An error from the underlying git library.
+
    #[error(transparent)]
+
    Backend(Box<dyn std::error::Error + Send + Sync + 'static>),
+
}
+

+
impl IsAncestorError {
+
    pub fn backend<E>(err: E) -> Self
+
    where
+
        E: std::error::Error + Send + Sync + 'static,
+
    {
+
        Self::Backend(Box::new(err))
+
    }
+
}
+

+
/// Error returned by [`Ancestry::ahead_behind`].
+
///
+
/// [`Ancestry::ahead_behind`]: super::Ancestry::ahead_behind
+
#[derive(Debug, Error)]
+
#[non_exhaustive]
+
pub enum AheadBehindError {
+
    /// One of the commits was not found.
+
    #[error("commit '{oid}' was not found")]
+
    CommitNotFound { oid: Oid },
+
    /// An error from the underlying git library.
+
    #[error(transparent)]
+
    Backend(Box<dyn std::error::Error + Send + Sync + 'static>),
+
}
+

+
impl AheadBehindError {
+
    pub fn backend<E>(err: E) -> Self
+
    where
+
        E: std::error::Error + Send + Sync + 'static,
+
    {
+
        Self::Backend(Box::new(err))
+
    }
+
}
modified crates/radicle/src/git/repository/object.rs
@@ -1,8 +1,8 @@
//! Git object database abstraction.
//!
//! The module provides two traits:
-
//! - [`ObjectReader`] for reading objects, and
-
//! - [`ObjectWriter`] for writing objects
+
//! - [`Reader`] for reading objects, and
+
//! - [`Writer`] for writing objects

pub mod error;

@@ -13,7 +13,7 @@ use radicle_oid::Oid;
use super::types::{Blob, Commit, TreeEntry};

/// A handle for reading Git objects from the Git object database.
-
pub trait ObjectReader {
+
pub trait Reader {
    /// Find a blob by its [`Oid`].
    ///
    /// Returns `None` if the blob does not exist.
@@ -135,7 +135,7 @@ pub trait ObjectReader {
/// Write Git objects to the Git object database.
///
/// Every method returns the content-addressed [`Oid`] of the written object.
-
pub trait ObjectWriter {
+
pub trait Writer {
    /// Write a blob given its raw bytes content.
    ///
    /// # Errors
modified crates/radicle/src/git/repository/object/error/read.rs
@@ -1,6 +1,6 @@
-
//! Errors returned by [`ObjectReader`] methods.
+
//! Errors returned by [`Reader`] methods.
//!
-
//! [`ObjectReader`]: super::super::ObjectReader
+
//! [`Reader`]: super::super::Reader

use std::path::PathBuf;

@@ -9,9 +9,9 @@ use thiserror::Error;

use crate::git::repository::types::ObjectKind;

-
/// Error returned by [`ObjectReader::blob`].
+
/// Error returned by [`Reader::blob`].
///
-
/// [`ObjectReader::blob`]: super::super::ObjectReader::blob
+
/// [`Reader::blob`]: super::super::Reader::blob
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum BlobError {
@@ -29,9 +29,9 @@ impl BlobError {
    }
}

-
/// Error returned by [`ObjectReader::blob_at`].
+
/// Error returned by [`Reader::blob_at`].
///
-
/// [`ObjectReader::blob_at`]: super::super::ObjectReader::blob_at
+
/// [`Reader::blob_at`]: super::super::Reader::blob_at
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum BlobAtError {
@@ -79,9 +79,9 @@ impl BlobAtError {
    }
}

-
/// Error returned by [`ObjectReader::commit`].
+
/// Error returned by [`Reader::commit`].
///
-
/// [`ObjectReader::commit`]: super::super::ObjectReader::commit
+
/// [`Reader::commit`]: super::super::Reader::commit
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CommitError {
@@ -105,9 +105,9 @@ impl CommitError {
    }
}

-
/// Error returned by [`ObjectReader::exists`].
+
/// Error returned by [`Reader::exists`].
///
-
/// [`ObjectReader::exists`]: super::super::ObjectReader::exists
+
/// [`Reader::exists`]: super::super::Reader::exists
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ExistsError {
modified crates/radicle/src/git/repository/object/error/write.rs
@@ -1,15 +1,15 @@
-
//! Errors returned by [`ObjectWriter`] methods.
+
//! Errors returned by [`Writer`] methods.
//!
-
//! [`ObjectWriter`]: super::super::ObjectWriter
+
//! [`Writer`]: super::super::Writer

use std::path::PathBuf;

use radicle_oid::Oid;
use thiserror::Error;

-
/// Error returned by [`ObjectWriter::write_blob`].
+
/// Error returned by [`Writer::write_blob`].
///
-
/// [`ObjectWriter::write_blob`]: super::super::ObjectWriter::write_blob
+
/// [`Writer::write_blob`]: super::super::Writer::write_blob
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum BlobError {
@@ -24,9 +24,9 @@ impl BlobError {
    }
}

-
/// Error returned by [`ObjectWriter::write_tree`].
+
/// Error returned by [`Writer::write_tree`].
///
-
/// [`ObjectWriter::write_tree`]: super::super::ObjectWriter::write_tree
+
/// [`Writer::write_tree`]: super::super::Writer::write_tree
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum TreeError {
@@ -52,9 +52,9 @@ impl TreeError {
    }
}

-
/// Error returned by [`ObjectWriter::write_commit`].
+
/// Error returned by [`Writer::write_commit`].
///
-
/// [`ObjectWriter::write_commit`]: super::super::ObjectWriter::write_commit
+
/// [`Writer::write_commit`]: super::super::Writer::write_commit
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CommitError {