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 <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-12-11 14:23:13 +01:00
parent bdbf111163
commit 335fcbca89
No known key found for this signature in database
2 changed files with 11 additions and 2 deletions

View File

@ -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();

View File

@ -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()
}