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

Function resolve_position

atomic-core/src/apply/position.rs:65–95  ·  view source on GitHub ↗

Convert an external position (with Hash) to an internal position (with NodeId). This is the bridge between the serialized change format (using hashes) and the internal graph format (using NodeIds). # Arguments `txn` - Transaction for looking up internal IDs `pos` - External position with optional hash `current_change` - NodeId of the change being applied (used for self-references) # Returns T

(
    txn: &T,
    pos: &Position<Option<Hash>>,
    current_change: NodeId,
)

Source from the content-addressed store, hash-verified

63/// Returns `LocalApplyError::DependencyMissing` if the referenced change
64/// is not registered in the repository.
65pub fn resolve_position<T: GraphTxnT>(
66 txn: &T,
67 pos: &Position<Option<Hash>>,
68 current_change: NodeId,
69) -> Result<Position<NodeId>, LocalApplyError> {
70 let change_id = match pos.change {
71 Some(hash) if hash.is_none() => {
72 // Hash::NONE (all zeros) represents the ROOT position.
73 // This is a virtual span that doesn't exist in the database
74 // but serves as the parent for all top-level files.
75 NodeId::ROOT
76 }
77 Some(hash) => {
78 // External reference - look up the internal ID
79 txn.get_internal(&hash)
80 .map_err(|e| LocalApplyError::Internal {
81 message: format!("Failed to resolve position: {}", e),
82 })?
83 .ok_or(LocalApplyError::DependencyMissing { hash })?
84 }
85 None => {
86 // Self-reference - use the current change ID
87 current_change
88 }
89 };
90
91 Ok(Position {
92 change: change_id,
93 pos: pos.pos,
94 })
95}
96
97/// Convert an external span (with Hash) to an internal span (with NodeId).
98///

Callers 4

write_new_edgeFunction · 0.85
collect_zombie_contextFunction · 0.85
resolve_inodeFunction · 0.85
write_new_vertexFunction · 0.85

Calls 2

is_noneMethod · 0.80
get_internalMethod · 0.45

Tested by

no test coverage detected