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

Function record_moved_file

atomic-core/src/record/workflow/record/mod.rs:856–920  ·  view source on GitHub ↗
(
    working_copy: &W,
    detected: &DetectedFile,
    old_content: &[u8],
    crdt_old_content: Option<&[u8]>,
    options: &RecordingOptions,
    existing_inode: Inode,
    existing_position: Posi

Source from the content-addressed store, hash-verified

854/// are still required, but no historical semantic identity is fabricated.
855#[allow(clippy::too_many_arguments)]
856pub fn record_moved_file<W>(
857 working_copy: &W,
858 detected: &DetectedFile,
859 old_content: &[u8],
860 crdt_old_content: Option<&[u8]>,
861 options: &RecordingOptions,
862 existing_inode: Inode,
863 existing_position: Position<NodeId>,
864 exact_source_claim: PathClaimId,
865 existing_trunk_id: Option<TrunkId>,
866 existing_branches: Option<&[BranchId]>,
867) -> Result<RecordedFile, String>
868where
869 W: WorkingCopyRead,
870{
871 let old_path = detected
872 .old_path
873 .clone()
874 .ok_or_else(|| format!("Move {} is missing its old path", detected.path))?;
875
876 // Reuse the normal edit pipeline for destination content, while forcing it
877 // to target the authoritative existing file identity supplied by the
878 // caller rather than any incidental identity on `detected`.
879 let mut modified = detected.clone();
880 modified.kind = DetectionKind::Modified;
881 modified.inode = Some(existing_inode);
882 modified.position = Some(existing_position);
883 let mut recorded = record_modified_file_with_semantics(
884 working_copy,
885 &modified,
886 old_content,
887 crdt_old_content,
888 options,
889 existing_trunk_id,
890 existing_branches,
891 existing_trunk_id.is_some(),
892 )?;
893
894 recorded.set_kind(DetectionKind::Moved);
895 recorded.set_old_path(old_path.clone());
896 recorded.set_inode(existing_inode);
897 recorded.set_position(existing_position);
898 recorded.set_exact_source_claim(exact_source_claim);
899
900 let Some(existing_trunk_id) = existing_trunk_id else {
901 return Ok(recorded);
902 };
903 // A pure move may produce no edit FileOps, while opaque/binary replacement
904 // paths intentionally skip semantic tokenization. Always emit the semantic
905 // move, then retain any line/token operations generated by the edit path.
906 let generated_ops = recorded.crdt_ops().cloned();
907 let mut move_ops = FileOps::move_file(existing_trunk_id, old_path, detected.path.clone());
908 if let Some(generated_ops) = generated_ops {
909 move_ops
910 .line_ops_mut()
911 .extend(generated_ops.line_ops().iter().cloned());
912 }
913 recorded.set_crdt_ops(move_ops);

Calls 15

set_old_pathMethod · 0.80
set_positionMethod · 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
cloneMethod · 0.45
set_kindMethod · 0.45