diff --git a/crates/radicle/src/git/canonical.rs b/crates/radicle/src/git/canonical.rs index 706eec21..08417f3e 100644 --- a/crates/radicle/src/git/canonical.rs +++ b/crates/radicle/src/git/canonical.rs @@ -99,8 +99,8 @@ impl Canonical { { Self::reference( repo, - delegates, &lit::refs_heads(project.default_branch()).into(), + delegates, threshold, ) } @@ -109,8 +109,8 @@ impl Canonical { /// the reference `name`. pub fn reference( repo: &S, + refname: &Qualified, delegates: &NonEmpty, - name: &Qualified, threshold: usize, ) -> Result where @@ -118,14 +118,14 @@ impl Canonical { { let mut tips = BTreeMap::new(); for delegate in delegates.iter() { - match repo.reference_oid(delegate, name) { + match repo.reference_oid(delegate, refname) { Ok(tip) => { tips.insert(*delegate, tip); } Err(e) if super::ext::is_not_found_err(&e) => { log::warn!( target: "radicle", - "Missing `refs/namespaces/{}/{name}` while calculating the canonical reference", + "Missing `refs/namespaces/{}/{refname}` while calculating the canonical reference", delegate.as_key() ); } @@ -139,6 +139,14 @@ impl Canonical { pub fn tips(&self) -> impl Iterator { self.tips.iter() } + + /// Returns `true` is there were no tips found for any of the delegates for + /// the given reference. + /// + /// N.b. this may be the case when a new reference is being created. + pub fn is_empty(&self) -> bool { + self.tips.is_empty() + } } /// Check that a given `target` converges with any of the provided `tips`. @@ -176,7 +184,7 @@ impl Canonical { /// /// Also returns an error if `heads` is empty or `threshold` cannot be /// satisified with the number of heads given. - pub fn quorum(&self, repo: &raw::Repository) -> Result { + pub fn quorum(self, repo: &raw::Repository) -> Result { let mut candidates = BTreeMap::<_, usize>::new(); // Build a list of candidate commits and count how many "votes" each of them has.