aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/changes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/document/changes.rs')
-rw-r--r--src/document/changes.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/document/changes.rs b/src/document/changes.rs
index 800ea19..e1cbe21 100644
--- a/src/document/changes.rs
+++ b/src/document/changes.rs
@@ -28,6 +28,18 @@ pub(crate) fn holds_all(doc: &impl ReadDoc, heads: &[ChangeHash]) -> bool {
heads.iter().all(|head| holds(doc, head))
}
+/// Whether `hash` is in the history of `heads`, which `doc` holds: one of them, or one
+/// they build on.
+pub(crate) fn in_history(doc: &Document, hash: &ChangeHash, heads: &[ChangeHash]) -> bool {
+ heads.contains(hash)
+ || (holds(doc, hash)
+ && holds_all(doc, heads)
+ && !doc
+ .get_changes(heads)
+ .iter()
+ .any(|later| later.hash() == *hash))
+}
+
/// Whether the history of `theirs` (of them, those `doc` has) holds all of `ours`
/// (heads of `doc`): a peer at `theirs` has every change we have.
pub(crate) fn covers(doc: &Document, theirs: &[ChangeHash], ours: &[ChangeHash]) -> bool {