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

Method add_file_ops

atomic-core/src/record/workflow/assembly/mod.rs:212–253  ·  view source on GitHub ↗

Add a file operation to the context (semantic layer). The entry's ROOT-placeholder identities are renumbered into a per-change unique namespace (CB-9B review F4): the trunk's file index becomes this entry's position, and branch/leaf placeholders shift by the running bases so two recorded files can never collide in the CRDT tables at apply time. # Errors Returns [`AssemblyError::PlaceholderNames

(&mut self, ops: FileOps)

Source from the content-addressed store, hash-verified

210 /// running placeholder namespace cannot advance: either the FileOps
211 /// entry count or the accumulated placeholder span would exceed `u32`.
212 pub fn add_file_ops(&mut self, ops: FileOps) -> AssemblyResult<()> {
213 let mut ops = ops;
214 // CB-9B review B1: the entry's local placeholder span must be
215 // measured BEFORE renumbering. After `renumber_placeholder_ids` the
216 // ops carry the shifted indices, so measuring them afterwards
217 // double-counts the running base and grows it geometrically
218 // (2·base + span) instead of linearly — a 34-entry one-line import
219 // overflowed u32 and panicked.
220 let branch_span = checked_placeholder_span(max_placeholder_branch_index(&ops))?;
221 let leaf_span = checked_placeholder_span(max_placeholder_leaf_index(&ops))?;
222 let trunk_file_idx = u32::try_from(self.file_ops.len()).map_err(|_| {
223 AssemblyError::PlaceholderNamespaceExhausted {
224 namespace: "trunk-file",
225 next_index: self.file_ops.len() as u64,
226 limit: u32::MAX as u64,
227 }
228 })?;
229 let branch_base = self.placeholder_branch_base;
230 let leaf_base = self.placeholder_leaf_base;
231 // Checked before the shifts so every individual `base + local`
232 // substitution inside renumber_placeholder_ids stays in range: each
233 // local index is < span, so base + span is the upper bound.
234 let next_branch_base = branch_base.checked_add(branch_span).ok_or(
235 AssemblyError::PlaceholderNamespaceExhausted {
236 namespace: "branch",
237 next_index: branch_base as u64 + branch_span as u64,
238 limit: u32::MAX as u64,
239 },
240 )?;
241 let next_leaf_base = leaf_base.checked_add(leaf_span).ok_or(
242 AssemblyError::PlaceholderNamespaceExhausted {
243 namespace: "leaf",
244 next_index: leaf_base as u64 + leaf_span as u64,
245 limit: u32::MAX as u64,
246 },
247 )?;
248 ops.renumber_placeholder_ids(trunk_file_idx, branch_base, leaf_base);
249 self.placeholder_branch_base = next_branch_base;
250 self.placeholder_leaf_base = next_leaf_base;
251 self.file_ops.push(ops);
252 Ok(())
253 }
254
255 /// Add a dependency.
256 ///

Calls 6

checked_placeholder_spanFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45