Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: update default branch for canonical refs
Fintan Halpenny committed 8 months ago
commit 0d96af5d07de3fe52c6d70203f77176aa4f4cecb
parent c38b9d9e1eef6b9572cd75fc131c9afb18bf6df6
1 file changed +13 -8
modified crates/radicle-node/src/worker/fetch.rs
@@ -1,3 +1,5 @@
+
use radicle::identity::doc::CanonicalRefsError;
+
use radicle::identity::CanonicalRefs;
pub(crate) use radicle_protocol::worker::fetch::error;

use std::collections::BTreeSet;
@@ -367,14 +369,16 @@ fn set_canonical_refs(
    applied: &Applied,
) -> Result<Option<UpdatedCanonicalRefs>, error::Canonical> {
    let identity = repo.identity()?;
-
    let rules = match identity
-
        .canonical_refs()?
-
        .map(|crefs| crefs.rules().clone())
-
        .filter(|rules| !rules.is_empty())
-
    {
-
        None => return Ok(None),
-
        Some(rules) => rules,
-
    };
+
    // TODO(finto): it's unfortunate that we may end up computing the default
+
    // branch again after `set_head` is called after the fetch. This is due to
+
    // the storage capabilities being leaked to this part of the code base.
+
    let rules = identity
+
        .canonical_refs_or_default(|| {
+
            let rule = identity.doc().default_branch_rule()?;
+
            Ok::<_, CanonicalRefsError>(CanonicalRefs::from_iter([rule]))
+
        })?
+
        .rules()
+
        .clone();

    let mut updated_refs = UpdatedCanonicalRefs::default();
    let refnames = applied
@@ -389,6 +393,7 @@ fn set_canonical_refs(
            _ => None,
        })
        .collect::<BTreeSet<_>>();
+

    for name in refnames {
        let canonical = match rules.canonical(name.clone(), repo) {
            Some(canonical) => canonical,