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 9 months ago
commit e935b6b7dd30c4cf2ed7ccd79c991c6e8d808bc5
parent b03c0d5d0cfe2e803a2e93b305bbb72724aed6fe
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;
@@ -370,14 +372,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
@@ -392,6 +396,7 @@ fn set_canonical_refs(
            _ => None,
        })
        .collect::<BTreeSet<_>>();
+

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