Resolve a context position through the file's own vertex index first. A zero-length vertex (an empty file, or a file truncated to nothing) shares its position with the end of the content serialized before it and with the start of what follows. The position-only lookups preferred that empty marker, so appending to a file whose last line was recorded in the same change as another file's truncation
(
txn: &CachedWriteGraphTxn<'_, '_>,
inode: Option<Inode>,
pos: Position<NodeId>,
is_predecessor: bool,
)
| 336 | /// the chain's terminal rows separately, so every applied vertex is |
| 337 | /// indexed under its inode). |
| 338 | fn resolve_context_vertex_in_inode( |
| 339 | txn: &CachedWriteGraphTxn<'_, '_>, |
| 340 | inode: Option<Inode>, |
| 341 | pos: Position<NodeId>, |
| 342 | is_predecessor: bool, |
| 343 | ) -> Result<GraphNode<NodeId>, LocalApplyError> { |
| 344 | if let Some(inode) = inode.filter(|_| !pos.change.is_root()) { |
| 345 | let found = if is_predecessor { |
| 346 | txn.find_block_end_in_inode(inode, pos) |
| 347 | } else { |
| 348 | txn.find_block_in_inode(inode, pos) |
| 349 | } |
| 350 | .map_err(|error| LocalApplyError::Internal { |
| 351 | message: format!( |
| 352 | "failed to resolve context {} in inode {}: {}", |
| 353 | pos, |
| 354 | inode.get(), |
| 355 | error |
| 356 | ), |
| 357 | })?; |
| 358 | if let Some(vertex) = found { |
| 359 | return Ok(adjust_for_mid_span(vertex, pos, is_predecessor)); |
| 360 | } |
| 361 | } |
| 362 | resolve_context_vertex(txn, pos, is_predecessor) |
| 363 | } |
| 364 | |
| 365 | #[cfg(test)] |
| 366 | mod tests { |
no test coverage detected