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.
This commit is contained in:
Alexis Sellier
2023-05-26 10:31:00 +02:00
parent cd07a1d0e0
commit 7e15b273a0
2 changed files with 3 additions and 5 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ pub fn load_proposed(repository: &Repository) -> Result<Vec<(PatchId, Patch)>> {
}
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()
+2 -4
View File
@@ -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}")
}