Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: More convenience methods to get default branch
Lorenz Leutgeb committed 7 months ago
commit 14c7559de499278793eeb7331f3e1b891989e0fc
parent 86472fdccbf95d08d0184776ee1ca75d01caf2c8
4 files changed +15 -6
modified crates/radicle-remote-helper/src/push.rs
@@ -285,8 +285,7 @@ pub fn run(
    }
    let delegates = stored.delegates()?;
    let identity = stored.identity()?;
-
    let project = identity.project()?;
-
    let canonical_ref = git::refs::branch(project.default_branch());
+
    let canonical_ref = identity.default_branch()?;
    let mut set_canonical_refs: Vec<(git::Qualified, git::canonical::Object)> =
        Vec::with_capacity(specs.len());

modified crates/radicle/src/identity/doc.rs
@@ -742,12 +742,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::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
@@ -522,6 +522,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
@@ -786,7 +786,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