Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle: More convenience methods to get default branch
Lorenz Leutgeb committed 22 days ago
commit 0eba6caf9f09cc0186ecf9ba0520664766a3b7d4
parent 22b2871
3 files changed +14 -4
modified crates/radicle/src/identity/doc.rs
@@ -737,12 +737,16 @@ impl Doc {
        Ok(proj)
    }

+
    /// Gets the qualified reference name of the default branch,
+
    /// according to the project payload in this document.
+
    pub fn default_branch(&self) -> Result<git::fmt::Qualified<'_>, PayloadError> {
+
        Ok(git::refs::branch(self.project()?.default_branch()))
+
    }
+

    pub fn default_branch_rule(
        &self,
    ) -> Result<(rules::Pattern, rules::ValidRule), DefaultBranchRuleError> {
-
        let proj = self.project()?;
-
        let refname = proj.default_branch();
-
        let pattern = rules::Pattern::try_from(git::refs::branch(refname).to_owned())?;
+
        let pattern = rules::Pattern::try_from(self.default_branch()?.to_owned())?;
        let rule = rules::Rule::new(
            rules::ResolvedDelegates::Delegates(self.delegates.clone()),
            self.threshold,
modified crates/radicle/src/storage.rs
@@ -520,6 +520,12 @@ pub trait ReadRepository: Sized + ValidateRepository {
    /// Returns the [`Oid`] as well as the qualified reference name.
    fn head(&self) -> Result<(Qualified<'_>, Oid), RepositoryError>;

+
    /// Gets the qualified reference name of the default branch of self,
+
    /// according to the project payload in the identity document.
+
    fn default_branch(&self) -> Result<Qualified<'_>, RepositoryError> {
+
        Ok(self.identity_doc()?.default_branch()?.to_owned())
+
    }
+

    /// Compute the canonical head of this repository.
    ///
    /// Ignores any existing `HEAD` reference.
modified crates/radicle/src/storage/git.rs
@@ -853,7 +853,7 @@ impl ReadRepository for Repository {

    fn canonical_head(&self) -> Result<(Qualified<'_>, Oid), RepositoryError> {
        let doc = self.identity_doc()?;
-
        let refname = git::refs::branch(doc.project()?.default_branch());
+
        let refname = doc.default_branch()?.to_owned();
        let crefs = match doc.canonical_refs()? {
            Some(crefs) => crefs,
            // Fallback to constructing the default branch via the project