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

Function resolve_exact_source_edge

atomic-core/src/apply/edge.rs:280–346  ·  view source on GitHub ↗

Resolve the source vertex of an edge update: the vertex at `position` that holds exactly the `previous` edge into `target`. Candidates come from the file's own vertex index first (a zero-length vertex of a neighbouring file can sit at the same position; see `CachedWriteGraphTxn::find_block_end_in_inode`), then from the global span lookups; only candidates carrying the exact prior edge qualify.

(
    txn: &CachedWriteGraphTxn<'_, '_>,
    inode: Option<Inode>,
    position: Position<NodeId>,
    target: GraphNode<NodeId>,
    previous: crate::types::EdgeFlags,
    introduced_by: NodeId,
)

Source from the content-addressed store, hash-verified

278/// `CachedWriteGraphTxn::find_block_end_in_inode`), then from the global
279/// span lookups; only candidates carrying the exact prior edge qualify.
280fn resolve_exact_source_edge(
281 txn: &CachedWriteGraphTxn<'_, '_>,
282 inode: Option<Inode>,
283 position: Position<NodeId>,
284 target: GraphNode<NodeId>,
285 previous: crate::types::EdgeFlags,
286 introduced_by: NodeId,
287) -> Result<GraphNode<NodeId>, LocalApplyError> {
288 if position.change.is_root() {
289 let root = GraphNode::root();
290 if source_has_exact_edge(txn, root, target, previous, introduced_by)? {
291 return Ok(root);
292 }
293 return Err(LocalApplyError::Internal {
294 message: format!(
295 "ROOT has no {:?} edge to {} introduced by {}",
296 previous, target, introduced_by
297 ),
298 });
299 }
300
301 let mut candidates = Vec::with_capacity(4);
302 let mut consider = |candidate: Option<GraphNode<NodeId>>| {
303 if let Some(candidate) = candidate.filter(|candidate| !candidates.contains(candidate)) {
304 candidates.push(candidate);
305 }
306 };
307 if let Some(inode) = inode {
308 consider(txn.find_block_end_in_inode(inode, position).ok().flatten());
309 consider(txn.find_block_in_inode(inode, position).ok().flatten());
310 }
311 consider(txn.find_block_end(position).ok());
312 consider(txn.find_block(position).ok());
313
314 let mut matching = Vec::new();
315 for candidate in candidates {
316 if source_has_exact_edge(txn, candidate, target, previous, introduced_by)? {
317 matching.push(candidate);
318 }
319 }
320 if matching.len() > 1 && previous.contains(crate::types::EdgeFlags::FOLDER) {
321 let fitting: Vec<GraphNode<NodeId>> = matching
322 .iter()
323 .copied()
324 .filter(|candidate| folder_edge_source_fits(*candidate, target))
325 .collect();
326 // Keep the ambiguity visible when the alternation does not settle it.
327 if fitting.len() == 1 {
328 matching = fitting;
329 }
330 }
331 match matching.as_slice() {
332 [source] => Ok(*source),
333 [] => Err(LocalApplyError::Internal {
334 message: format!(
335 "no source at {} has prior {:?} edge to {} introduced by {}",
336 position, previous, target, introduced_by
337 ),

Callers 1

write_new_edgeFunction · 0.85

Calls 15

rootFunction · 0.85
source_has_exact_edgeFunction · 0.85
folder_edge_source_fitsFunction · 0.85
is_rootMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45
okMethod · 0.45
find_block_in_inodeMethod · 0.45
find_block_endMethod · 0.45
find_blockMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected