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

Function record_added_file

atomic-core/src/record/workflow/record/mod.rs:247–305  ·  view source on GitHub ↗

Record a single added file from the working copy. Reads the file content and creates appropriate hunks for a new file. # Arguments `working_copy` - Working copy interface `detected` - The detected file `options` - Recording options # Returns A `RecordedFile` with the file's hunks and content. # Example ```rust,ignore use atomic_core::record::workflow::record::{record_added_file, RecordingOp

(
    working_copy: &W,
    detected: &DetectedFile,
    options: &RecordingOptions,
)

Source from the content-addressed store, hash-verified

245/// let recorded = record_added_file(&working_copy, &detected_file, &options)?;
246/// ```
247pub fn record_added_file<W>(
248 working_copy: &W,
249 detected: &DetectedFile,
250 options: &RecordingOptions,
251) -> Result<RecordedFile, String>
252where
253 W: WorkingCopyRead,
254{
255 let mut recorded = RecordedFile::new(&detected.path);
256 recorded.set_kind(DetectionKind::Added);
257
258 // Read content from working copy
259 let mut content = Vec::new();
260 if let Err(e) = working_copy.read_file(&detected.path, &mut content) {
261 return Err(format!("Failed to read file {}: {}", detected.path, e));
262 }
263
264 // Check size limits
265 if options.exceeds_max_size(content.len()) {
266 return Err(format!(
267 "File {} exceeds maximum size ({} bytes)",
268 detected.path,
269 content.len()
270 ));
271 }
272
273 // Skip empty files if configured
274 if content.is_empty() && !options.get_record_empty_files() {
275 return Err(format!("Skipping empty file {}", detected.path));
276 }
277
278 // Detect encoding
279 let encoding = detect_encoding(&content);
280 recorded.set_encoding(encoding);
281
282 // Skip binary files if configured
283 if encoding == Encoding::Binary && options.get_skip_binary() {
284 return Err(format!("Skipping binary file {}", detected.path));
285 }
286
287 // Create an edit graph_op for the new content
288 let local = Local::new(&detected.path, 1);
289 let content_len = content.len() as u64;
290 let graph_op = BuiltHunk::new_edit(local, Some(encoding), 0, content_len);
291 recorded.add_hunk(graph_op);
292
293 // Build the CRDT (Trunk → Branch → Leaf) operations for the new file so
294 // the semantic layer (token-level diff / blame) is populated, matching
295 // the modified-file path.
296 let (crdt_ops, crdt_stats) =
297 crdt::build_crdt_ops_for_added_file(&detected.path, &content, encoding);
298 recorded.set_crdt_ops(crdt_ops);
299 recorded.set_crdt_stats(crdt_stats);
300
301 // Store the content
302 recorded.set_content(content);
303
304 Ok(recorded)

Calls 14

get_skip_binaryMethod · 0.80
set_crdt_opsMethod · 0.80
set_crdt_statsMethod · 0.80
set_contentMethod · 0.80
detect_encodingFunction · 0.50
set_kindMethod · 0.45
read_fileMethod · 0.45
exceeds_max_sizeMethod · 0.45
lenMethod · 0.45
is_emptyMethod · 0.45