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

Function record_modified_file

atomic-core/src/record/workflow/record/mod.rs:368–595  ·  view source on GitHub ↗
(
    working_copy: &W,
    detected: &DetectedFile,
    old_content: &[u8],
    crdt_old_content: Option<&[u8]>,
    options: &RecordingOptions,
    existing_trunk_id: Option<TrunkId>,
    existing_b

Source from the content-addressed store, hash-verified

366/// placeholders and the CRDT layer is effectively insert-only.
367#[allow(clippy::type_complexity)]
368pub fn record_modified_file<W>(
369 working_copy: &W,
370 detected: &DetectedFile,
371 old_content: &[u8],
372 crdt_old_content: Option<&[u8]>,
373 options: &RecordingOptions,
374 existing_trunk_id: Option<TrunkId>,
375 existing_branches: Option<&[BranchId]>,
376) -> Result<RecordedFile, String>
377where
378 W: WorkingCopyRead,
379{
380 let mut recorded = RecordedFile::new(&detected.path);
381 recorded.set_kind(DetectionKind::Modified);
382
383 // Count lines in old content for precise insertion point detection
384 let old_line_count = old_content.iter().filter(|&&b| b == b'\n').count();
385 recorded.set_old_line_count(old_line_count);
386
387 // Copy inode and position if available
388 if let Some(inode) = detected.inode {
389 recorded.set_inode(inode);
390 }
391 if let Some(position) = detected.position {
392 recorded.set_position(position);
393 }
394
395 // Read new content from working copy
396 let mut new_content = Vec::new();
397 if let Err(e) = working_copy.read_file(&detected.path, &mut new_content) {
398 return Err(format!("Failed to read file {}: {}", detected.path, e));
399 }
400
401 // Check size limits
402 if options.exceeds_max_size(new_content.len()) {
403 return Err(format!(
404 "File {} exceeds maximum size ({} bytes)",
405 detected.path,
406 new_content.len()
407 ));
408 }
409
410 // Detect encoding
411 let encoding = detect_encoding(&new_content);
412 recorded.set_encoding(encoding);
413
414 // Skip binary files if configured
415 if encoding == Encoding::Binary && options.get_skip_binary() {
416 return Err(format!("Skipping binary file {}", detected.path));
417 }
418
419 // Fast path: machine-generated files (lockfiles, bundled output) skip
420 // both the expensive diff computation AND CRDT tokenization. We treat
421 // them as a whole-file replace — one vertex in, one vertex out.
422 if super::globalize::should_use_opaque_generated_vertices(&detected.path) {
423 let mut replace_hunk = BuiltHunk::new_replace_with_lines(
424 Local::new(&detected.path, 1),
425 Some(encoding),

Calls 15

calculate_line_offsetsFunction · 0.85
set_old_line_countMethod · 0.80
set_positionMethod · 0.80
get_skip_binaryMethod · 0.80
set_contentMethod · 0.80
set_opaque_generatedMethod · 0.80
to_hunk_optionsMethod · 0.80
process_diff_opMethod · 0.80
build_opsMethod · 0.80
set_crdt_opsMethod · 0.80