(
detected: &atomic_core::record::workflow::DetectedFile,
state: &atomic_core::pristine::span_patch_storage::SpanRecordState,
namespace_dependencies: Vec<Hash>,
new: &[u8],
trunk:
| 594 | } |
| 595 | |
| 596 | fn record_binary_span_edit( |
| 597 | detected: &atomic_core::record::workflow::DetectedFile, |
| 598 | state: &atomic_core::pristine::span_patch_storage::SpanRecordState, |
| 599 | namespace_dependencies: Vec<Hash>, |
| 600 | new: &[u8], |
| 601 | trunk: Option<atomic_core::crdt::TrunkId>, |
| 602 | branches: &[atomic_core::crdt::BranchId], |
| 603 | algorithm: atomic_core::diff::Algorithm, |
| 604 | ) -> Result<atomic_core::record::workflow::RecordedFile, String> { |
| 605 | use atomic_core::change::span_patch::SpanOp; |
| 606 | use atomic_core::change::{Encoding, FileOps, LineOps}; |
| 607 | use atomic_core::crdt::BranchOp; |
| 608 | use atomic_core::diff::Line; |
| 609 | use atomic_core::record::workflow::recipes::{Recipe, RecipeContext}; |
| 610 | use atomic_core::record::workflow::{DetectionKind, RecordedFile}; |
| 611 | use atomic_core::types::ChangePosition; |
| 612 | if trunk.is_none() && cfg!(not(unix)) { |
| 613 | return Err("projected semantic recording is not supported on this platform".into()); |
| 614 | } |
| 615 | let inode = detected |
| 616 | .inode |
| 617 | .ok_or_else(|| "span edit has no inode".to_string())?; |
| 618 | let position = detected |
| 619 | .position |
| 620 | .ok_or_else(|| "span edit has no position".to_string())?; |
| 621 | let mut edits = Vec::new(); |
| 622 | let mut cursor = 0usize; |
| 623 | for segment in state |
| 624 | .authored_ranges(0..state.content.len()) |
| 625 | .map_err(|error| error.to_string())? |
| 626 | { |
| 627 | let length = segment.output.end - segment.output.start; |
| 628 | edits.push(SpanOp::Edit { |
| 629 | file: state.file.clone(), |
| 630 | target: segment.target, |
| 631 | start: segment.target_start, |
| 632 | end: segment.target_start + length as u64, |
| 633 | insert_start: if cursor == 0 { 0 } else { new.len() as u64 }, |
| 634 | insert_end: new.len() as u64, |
| 635 | }); |
| 636 | cursor = segment.output.end; |
| 637 | } |
| 638 | if edits.is_empty() { |
| 639 | edits.push(SpanOp::Edit { |
| 640 | file: state.file.clone(), |
| 641 | target: state.root.clone(), |
| 642 | start: 0, |
| 643 | end: 0, |
| 644 | insert_start: 0, |
| 645 | insert_end: new.len() as u64, |
| 646 | }); |
| 647 | } |
| 648 | let mut recorded = RecordedFile::new(detected.path.as_str()); |
| 649 | recorded.set_kind(DetectionKind::Modified); |
| 650 | recorded.set_inode(inode); |
| 651 | recorded.set_position(position); |
| 652 | let encoding = atomic_core::record::workflow::compare::detect_encoding(new); |
| 653 | recorded.set_encoding(encoding); |
no test coverage detected