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,
)
| 63 | /// Returns `LocalApplyError::DependencyMissing` if the referenced change |
| 64 | /// is not registered in the repository. |
| 65 | pub 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 | /// |
no test coverage detected