The CRDT rows for `inode` that `visible` can see. Every row here is keyed by a trunk/branch/leaf id, and every such id carries the change that created it. A view shares one ambient graph with every other view, so a trunk inherited from a parent has branches attached to it by changes belonging to *other* views — a sibling draft editing the same file adds branches to the same trunk. Sending those w
(
&self,
inode: u64,
visible: &BTreeSet<u64>,
out: &mut CrdtRows,
)
| 389 | /// this are filtered. Without it a sandbox only works while it is the only |
| 390 | /// writer of the file. |
| 391 | fn export_crdt( |
| 392 | &self, |
| 393 | inode: u64, |
| 394 | visible: &BTreeSet<u64>, |
| 395 | out: &mut CrdtRows, |
| 396 | ) -> PristineResult<()> { |
| 397 | let on_view = |change_id: NodeId| change_id.is_root() || visible.contains(&change_id.get()); |
| 398 | let inode_trunk = self.txn.open_table(INODE_TRUNK)?; |
| 399 | let Some(trunk) = inode_trunk.get(inode)? else { |
| 400 | return Ok(()); |
| 401 | }; |
| 402 | let trunk = *trunk.value(); |
| 403 | if !on_view(TrunkId::from_bytes(&trunk).change_id()) { |
| 404 | return Ok(()); |
| 405 | } |
| 406 | out.inode_trunk.push((inode, trunk)); |
| 407 | if let Some(t) = self.txn.open_table(TRUNKS)?.get(&trunk)? { |
| 408 | out.trunks.push((trunk, t.value().to_vec())); |
| 409 | } |
| 410 | for row in self.txn.open_table(PATH_TRUNK)?.iter()? { |
| 411 | let (k, v) = row?; |
| 412 | if *v.value() == trunk { |
| 413 | out.path_trunk.push((k.value().to_string(), trunk)); |
| 414 | } |
| 415 | } |
| 416 | let trunk_branches = self.txn.open_multimap_table(TRUNK_BRANCHES)?; |
| 417 | let branches = self.txn.open_table(BRANCHES)?; |
| 418 | let branch_after = self.txn.open_table(BRANCH_AFTER)?; |
| 419 | let branch_vertex = self.txn.open_table(BRANCH_VERTEX)?; |
| 420 | let vertex_branch = self.txn.open_table(VERTEX_BRANCH)?; |
| 421 | let branch_leaves = self.txn.open_multimap_table(BRANCH_LEAVES)?; |
| 422 | let leaves = self.txn.open_table(LEAVES)?; |
| 423 | let mut ids = Vec::new(); |
| 424 | for b in trunk_branches.get(&trunk)? { |
| 425 | let b = *b?.value(); |
| 426 | // A branch from another view's change is not this view's line. |
| 427 | if on_view(BranchId::from_bytes(&b).change_id()) { |
| 428 | ids.push(b); |
| 429 | } |
| 430 | } |
| 431 | for b in &ids { |
| 432 | if let Some(v) = branches.get(b)? { |
| 433 | out.branches.push((*b, *v.value())); |
| 434 | } |
| 435 | if let Some(v) = branch_after.get(b)? { |
| 436 | // `after` may name a branch from another view; shipping it |
| 437 | // would dangle, so it is only kept when it is on this view. |
| 438 | let after = *v.value(); |
| 439 | if on_view(BranchId::from_bytes(&after).change_id()) { |
| 440 | out.branch_after.push((*b, after)); |
| 441 | } |
| 442 | } |
| 443 | if let Some(v) = branch_vertex.get(b)? { |
| 444 | let vertex = *v.value(); |
| 445 | out.branch_vertex.push((*b, vertex)); |
| 446 | if let Some(back) = vertex_branch.get(&vertex)? { |
| 447 | out.vertex_branch.push((vertex, *back.value())); |
| 448 | } |