From 52e307d7b95dda735d1afbc4fe2dcffaa87512a4 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Nov 2026 00:29:56 +0100 Subject: delta from held heads --- src/document/changes.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/document/changes.rs') diff --git a/src/document/changes.rs b/src/document/changes.rs index 345f151..0409c50 100644 --- a/src/document/changes.rs +++ b/src/document/changes.rs @@ -67,24 +67,20 @@ pub(crate) fn change_from_bytes(bytes: Vec, hash: ChangeHash) -> Result Option> { - if !missing(doc, to).is_empty() { + if !missing(doc, to).is_empty() || !missing(doc, from).is_empty() { return None; } - // Heads of `from` we don't have can't hide anything we have. - let from: Vec = from - .iter() - .copied() - .filter(|head| doc.get_change_by_hash(head).is_some()) - .collect(); let since: HashMap, Vec)> = doc - .get_changes(&from) + .get_changes(from) .iter() .map(|change| { ( @@ -181,7 +177,12 @@ mod tests { fn no_delta_without_its_heads() { let mut doc = Document::new(); change(&mut doc, |doc| doc.put(ROOT, "k", 1_i64).unwrap()); + let heads = doc.get_heads(); assert!(delta_bytes(&doc, &[], &[ChangeHash([7; 32])]).is_none()); + assert!( + delta_bytes(&doc, &[ChangeHash([7; 32])], &heads).is_none(), + "nor without where it starts" + ); } /// A change loads from its bytes only as the change it was asked for. -- cgit v1.3.1