From 335fcbca89e4ffe0bd2c63690814429ab6ad9915 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Sun, 11 Dec 2022 14:23:13 +0100 Subject: [PATCH] cob: Return correct clock value for multi-ops We weren't accounting for batches ops in an entry. This change should account for it by adding N-1 to the clock value of an entry, where N is the number of entries. Signed-off-by: Alexis Sellier --- radicle-cob/src/change_graph/evaluation.rs | 8 +++++++- radicle-cob/src/history.rs | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/radicle-cob/src/change_graph/evaluation.rs b/radicle-cob/src/change_graph/evaluation.rs index 1597f0fe..ad96d3c8 100644 --- a/radicle-cob/src/change_graph/evaluation.rs +++ b/radicle-cob/src/change_graph/evaluation.rs @@ -9,6 +9,7 @@ use git_ext::Oid; use petgraph::{visit::EdgeRef, EdgeDirection}; use crate::history::entry::{EntryId, EntryWithClock}; +use crate::history::Clock; use crate::{change::Change, history, pruning_fold}; /// # Panics @@ -39,7 +40,12 @@ pub fn evaluate<'b>( let incoming = graph.edges_directed(c.idx, EdgeDirection::Incoming); let clock = incoming .into_iter() - .map(|e| entries[&graph[e.source()].id.into()].clock()) + .map(|e| { + let entry = &entries[&graph[e.source()].id.into()]; + let clock = entry.clock(); + + clock + entry.contents().len() as Clock - 1 + }) .max() .map(|n| n + 1) .unwrap_or_default(); diff --git a/radicle-cob/src/history.rs b/radicle-cob/src/history.rs index cf6444c2..b7bcd331 100644 --- a/radicle-cob/src/history.rs +++ b/radicle-cob/src/history.rs @@ -82,7 +82,10 @@ impl History { pub fn clock(&self) -> Clock { self.graph .externals(petgraph::Direction::Outgoing) - .map(|n| self.graph[n].clock) + .map(|n| { + let node = &self.graph[n]; + node.clock + node.entry.contents.len() as Clock - 1 + }) .max() .unwrap_or_default() }