MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / select_linear_successor

Function select_linear_successor

atomic-repository/src/repository/content.rs:1396–1449  ·  view source on GitHub ↗

Choose the single live successor of `current` for a linear content walk. In the additive graph model a deleted destination can still lead to live descendants. Even when there is exactly one direct live successor, walking only that successor may skip an insertion reachable through the dead chain. Any visible deletion therefore requires the full graph traversal, which contracts dead chains and pres

(
    txn: &T,
    inode: Inode,
    adj: &mut atomic_core::pristine::InodeAdjState,
    options: &atomic_core::output::alive::RetrieveOptions,
)

Source from the content-addressed store, hash-verified

1394/// Any visible deletion therefore requires the full graph traversal, which
1395/// contracts dead chains and preserves their ordering and concurrent branches.
1396fn select_linear_successor<T>(
1397 txn: &T,
1398 inode: Inode,
1399 adj: &mut atomic_core::pristine::InodeAdjState,
1400 options: &atomic_core::output::alive::RetrieveOptions,
1401) -> atomic_core::record::RecordResult<LinearStep>
1402where
1403 T: atomic_core::pristine::GraphTxnT
1404 + atomic_core::pristine::InodeGraphOps<InodeError = atomic_core::pristine::PristineError>,
1405{
1406 use atomic_core::types::EdgeFlags;
1407
1408 let mut alive: Vec<atomic_core::types::GraphNode<NodeId>> = Vec::new();
1409 let mut has_deleted_successor = false;
1410
1411 while let Some(edge_result) = txn.next_inode_adj(adj) {
1412 let edge = edge_result?;
1413 let flags = edge.flag();
1414 if flags.contains(EdgeFlags::PARENT)
1415 || flags.contains(EdgeFlags::PSEUDO)
1416 || flags.contains(EdgeFlags::FOLDER)
1417 {
1418 continue;
1419 }
1420 if !options.passes_filter(edge.introduced_by()) {
1421 continue;
1422 }
1423 let edge_dest = edge.dest();
1424 let dest = txn.find_block_in_inode(inode, edge_dest)?.ok_or_else(|| {
1425 atomic_core::pristine::PristineError::BlockNotFound {
1426 change: edge_dest.change.get(),
1427 pos: edge_dest.pos.get(),
1428 }
1429 })?;
1430 if !options.passes_filter(dest.change) {
1431 continue;
1432 }
1433 if flags.contains(EdgeFlags::DELETED) {
1434 has_deleted_successor = true;
1435 } else if !alive.contains(&dest) {
1436 alive.push(dest);
1437 }
1438 }
1439
1440 if has_deleted_successor {
1441 return Ok(LinearStep::Bail);
1442 }
1443
1444 match alive.len() {
1445 0 => Ok(LinearStep::End),
1446 1 => Ok(LinearStep::Follow(alive[0])),
1447 _ => Ok(LinearStep::Bail),
1448 }
1449}
1450
1451fn try_retrieve_linear_content_with_filter<T, C>(
1452 txn: &T,

Callers 1

Calls 10

flagMethod · 0.80
passes_filterMethod · 0.80
getMethod · 0.65
next_inode_adjMethod · 0.45
containsMethod · 0.45
introduced_byMethod · 0.45
destMethod · 0.45
find_block_in_inodeMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected