Transport a copy into a receiver's numeric encoding frame, using only hash owners visible through the explicit patch dependency closure. ROOT names remain self-relative; the input is unchanged on every error.
(
&self,
txn: &T,
dependencies: &[Hash],
ops: &[FileOps],
)
| 124 | /// hash owners visible through the explicit patch dependency closure. |
| 125 | /// ROOT names remain self-relative; the input is unchanged on every error. |
| 126 | pub fn localize<T: GraphTxnT>( |
| 127 | &self, |
| 128 | txn: &T, |
| 129 | dependencies: &[Hash], |
| 130 | ops: &[FileOps], |
| 131 | ) -> Result<Vec<FileOps>, SemanticContextError> { |
| 132 | self.validate_for(ops)?; |
| 133 | let roots = dependencies |
| 134 | .iter() |
| 135 | .map(|hash| { |
| 136 | txn.get_internal(hash)? |
| 137 | .ok_or(SemanticContextError::MissingDependency(*hash)) |
| 138 | }) |
| 139 | .collect::<Result<Vec<_>, SemanticContextError>>()?; |
| 140 | let closure = EffectiveProjectionClosure::try_from_membership( |
| 141 | txn, |
| 142 | &ViewMembershipSet::from_ordered(roots), |
| 143 | )?; |
| 144 | let mut mapping = BTreeMap::new(); |
| 145 | for entry in &self.owners { |
| 146 | let id = txn |
| 147 | .get_internal(&entry.owner)? |
| 148 | .ok_or(SemanticContextError::MissingOwner(entry.owner))?; |
| 149 | if id.is_root() || txn.get_external(id)? != Some(entry.owner) { |
| 150 | return Err(SemanticContextError::InconsistentReceiverIdentity { |
| 151 | owner: entry.owner, |
| 152 | local_id: id, |
| 153 | }); |
| 154 | } |
| 155 | if !closure.contains(id) { |
| 156 | return Err(SemanticContextError::OutsideDependencyClosure(entry.owner)); |
| 157 | } |
| 158 | mapping.insert(NodeId::new(entry.authored_id), id); |
| 159 | } |
| 160 | let mut transported = ops.to_vec(); |
| 161 | for file in &mut transported { |
| 162 | file.remap_referenced_node_ids(|id| { |
| 163 | mapping |
| 164 | .get(&id) |
| 165 | .copied() |
| 166 | .ok_or_else(|| SemanticContextError::IncompleteMapping { |
| 167 | missing: vec![id], |
| 168 | unused: vec![], |
| 169 | }) |
| 170 | })?; |
| 171 | } |
| 172 | Ok(transported) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | #[cfg(test)] |