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

Function record_undeleted_file

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

Source from the content-addressed store, hash-verified

312/// Pass `None` for graph-only files; their restoration emits no semantic ops.
313#[allow(clippy::too_many_arguments)]
314pub fn record_undeleted_file<W>(
315 working_copy: &W,
316 detected: &DetectedFile,
317 deleted_by: &[Hash],
318 old_content: &[u8],
319 crdt_old_content: Option<&[u8]>,
320 options: &RecordingOptions,
321 existing_trunk_id: Option<TrunkId>,
322 existing_branches: Option<&[BranchId]>,
323) -> Result<RecordedFile, String>
324where
325 W: WorkingCopyRead,
326{
327 let inode = detected
328 .inode
329 .ok_or_else(|| format!("Undelete {} is missing its inode", detected.path))?;
330 let position = detected
331 .position
332 .ok_or_else(|| format!("Undelete {} is missing its graph position", detected.path))?;
333 if deleted_by.is_empty() {
334 return Err(format!(
335 "Undelete {} has no causally maximal deletion",
336 detected.path
337 ));
338 }
339
340 let mut current_content = Vec::new();
341 working_copy
342 .read_file(&detected.path, &mut current_content)
343 .map_err(|error| format!("Failed to read file {}: {}", detected.path, error))?;
344 if options.exceeds_max_size(current_content.len()) {
345 return Err(format!(
346 "File {} exceeds maximum size ({} bytes)",
347 detected.path,
348 current_content.len()
349 ));
350 }
351 let encoding = detect_encoding(&current_content);
352 if encoding == Encoding::Binary && options.get_skip_binary() {
353 return Err(format!("Skipping binary file {}", detected.path));
354 }
355
356 let mut recorded = if current_content == old_content {
357 let mut recorded = RecordedFile::new(&detected.path);
358 recorded.set_kind(DetectionKind::Modified);
359 recorded.set_content(current_content);
360 recorded.set_encoding(encoding);
361 recorded
362 } else {
363 let mut modified = detected.clone();
364 modified.kind = DetectionKind::Modified;
365 record_modified_file_with_semantics(
366 working_copy,
367 &modified,
368 old_content,
369 crdt_old_content,
370 options,
371 existing_trunk_id,

Calls 15

get_skip_binaryMethod · 0.80
set_contentMethod · 0.80
set_positionMethod · 0.80
set_undelete_changesMethod · 0.80
crdt_opsMethod · 0.80
extendMethod · 0.80
line_ops_mutMethod · 0.80
set_crdt_opsMethod · 0.80
crdt_statsMethod · 0.80
set_crdt_statsMethod · 0.80
detect_encodingFunction · 0.50