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