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

Function process_added_file

atomic-repository/src/parallel_record/worker.rs:44–107  ·  view source on GitHub ↗

Process an added file: read content, detect encoding, create hunks, tokenize.

(
    input: &FileRecordInput,
    options: &RecordingOptions,
)

Source from the content-addressed store, hash-verified

42
43/// Process an added file: read content, detect encoding, create hunks, tokenize.
44fn process_added_file(
45 input: &FileRecordInput,
46 options: &RecordingOptions,
47) -> Result<FileRecordOutput, String> {
48 // Read the file content from disk
49 let content = std::fs::read(&input.full_path)
50 .map_err(|e| format!("Failed to read {}: {}", input.path, e))?;
51
52 // Check size limits
53 if options.exceeds_max_size(content.len()) {
54 if options.get_skip_binary() {
55 return Ok(FileRecordOutput::skipped(
56 input.path.clone(),
57 FileRecordKind::Added,
58 ));
59 } else {
60 return Err(format!(
61 "File {} exceeds maximum size ({} bytes)",
62 input.path,
63 content.len(),
64 ));
65 }
66 }
67
68 // Create a per-file memory working copy (no shared state)
69 let memory_wc = Memory::new();
70 memory_wc.add_file(&input.path, &content);
71
72 let detected = DetectedFile::added(&input.path);
73
74 match record_added_file(&memory_wc, &detected, options) {
75 Ok(recorded) => {
76 if recorded.is_empty() {
77 return Ok(FileRecordOutput::skipped(
78 input.path.clone(),
79 FileRecordKind::Added,
80 ));
81 }
82
83 let crdt_stats = recorded.crdt_stats();
84 let file_stats = FileRecordStats {
85 hunks_created: recorded.hunk_count(),
86 content_bytes: recorded.content_len() as u64,
87 vertices_added: 3, // name + inode + content
88 lines_added: crdt_stats.map_or(0, |s| s.lines_added),
89 lines_deleted: crdt_stats.map_or(0, |s| s.lines_deleted),
90 lines_modified: crdt_stats.map_or(0, |s| s.lines_modified),
91 tokens_added: crdt_stats.map_or(0, |s| s.tokens_added),
92 tokens_deleted: crdt_stats.map_or(0, |s| s.tokens_deleted),
93 tokens_replaced: crdt_stats.map_or(0, |s| s.tokens_replaced),
94 ..FileRecordStats::default()
95 };
96
97 Ok(FileRecordOutput {
98 path: input.path.clone(),
99 kind: FileRecordKind::Added,
100 recorded: Some(recorded),
101 skipped: false,

Callers 1

process_single_fileFunction · 0.85

Calls 11

addedFunction · 0.85
record_added_fileFunction · 0.85
get_skip_binaryMethod · 0.80
crdt_statsMethod · 0.80
exceeds_max_sizeMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
add_fileMethod · 0.45
is_emptyMethod · 0.45
hunk_countMethod · 0.45
content_lenMethod · 0.45

Tested by

no test coverage detected