Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Move `is_linear` to `GraphAheadBehind`
Lorenz Leutgeb committed 9 months ago
commit bf0630bf6bbc9745e50c5d37a0603b63414394c6
parent 6510d0865df63311f19fd0c4a7e3449fcfbb0a2c
2 files changed +15 -11
modified crates/radicle/src/git/canonical.rs
@@ -431,6 +431,19 @@ pub struct GraphAheadBehind {
    pub behind: usize,
}

+
impl GraphAheadBehind {
+
    /// Whether self represents a linear history between two commits.
+
    ///
+
    /// The following three conditions are equivalent characterizations of
+
    /// a linear history:
+
    ///  1. One commit is ahead and not behind of the other.
+
    ///  2. One commit is behind and not ahead of the other.
+
    ///  3. One commit can be "fast-forwarded" to the other.
+
    pub fn is_linear(&self) -> bool {
+
        self.ahead * self.behind == 0
+
    }
+
}
+

/// The result of finding a set of objects in a Git repository.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FoundObjects {
modified crates/radicle/src/git/canonical/convergence.rs
@@ -3,7 +3,7 @@ use std::{fmt, ops::ControlFlow};
use crate::git::Oid;
use crate::prelude::Did;

-
use super::{effects, error, GraphAheadBehind, Object};
+
use super::{effects, error, Object};

/// Checks for convergence and ensures that compared objects are of the same
/// type, i.e. commit or tag, to the [`Candidate`].
@@ -50,10 +50,7 @@ where
            match self.checker.compare_to_candidate(did, *object) {
                ControlFlow::Continue(c) => match c {
                    Effect::GraphCheck { commit, upstream } => {
-
                        converges = converges
-
                            || self
-
                                .checker
-
                                .is_linear(self.repo.graph_ahead_behind(commit, upstream)?);
+
                        converges |= self.repo.graph_ahead_behind(commit, upstream)?.is_linear();
                    }
                    Effect::TagConverges => {
                        converges = true;
@@ -131,10 +128,4 @@ impl Candidate {
            (Object::Tag { .. }, Object::Tag { .. }) => ControlFlow::Continue(Effect::TagConverges),
        }
    }
-

-
    /// If any of `ahead` or `behind` is `0` then one of the commits is in the
-
    /// lineage.
-
    fn is_linear(&self, GraphAheadBehind { ahead, behind }: GraphAheadBehind) -> bool {
-
        ahead * behind == 0
-
    }
}