From 7e15b273a0f8ef51c306bbd9f47b202df5089254 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 25 May 2023 13:20:50 +0200 Subject: [PATCH] cob: Guarantee there is always a latest revision We change `Patch::latest` to always return something, because a patch is malformed if it doesn't have at least one revision, and thus would not load in the first place. This also implies that there is a latest revision in the face of concurrent updates. Note that currently, traversal order for concurrent updates is still random. This will be fixed in another patch. --- radicle-tui/src/cob/patch.rs | 2 +- radicle-tui/src/ui/cob/patch.rs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/radicle-tui/src/cob/patch.rs b/radicle-tui/src/cob/patch.rs index a9ae07bd..dab7ae11 100644 --- a/radicle-tui/src/cob/patch.rs +++ b/radicle-tui/src/cob/patch.rs @@ -26,7 +26,7 @@ pub fn load_proposed(repository: &Repository) -> Result> { } pub fn sync_status(repository: &Repository, patch: &Patch) -> Result<(usize, usize)> { - let (_, revision) = patch.latest().unwrap(); + let (_, revision) = patch.latest(); let target_oid = merge_target_oid(patch.target(), repository)?; let (ahead, behind) = repository .raw() diff --git a/radicle-tui/src/ui/cob/patch.rs b/radicle-tui/src/ui/cob/patch.rs index 6a174be7..c9c348e9 100644 --- a/radicle-tui/src/ui/cob/patch.rs +++ b/radicle-tui/src/ui/cob/patch.rs @@ -49,10 +49,8 @@ pub fn format_timestamp(patch: &Patch) -> String { } pub fn format_comments(patch: &Patch) -> String { - let count = match patch.latest() { - Some((_, rev)) => rev.discussion().len(), - None => 0, - }; + let count: usize = patch.revisions().map(|(_, r)| r.discussion().len()).sum(); + format!("{count}") }