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

Function compare_content

atomic-core/src/record/detect.rs:721–733  ·  view source on GitHub ↗

Compare two byte slices and produce diff operations. This function handles the actual diffing of file content. # Arguments `old_content` - Content from pristine `new_content` - Content from working copy `algorithm` - Diff algorithm to use # Returns A vector of diff operations describing the changes. # Example ```rust use atomic_core::record::compare_content; use atomic_core::diff::Algorithm

(
    old_content: &[u8],
    new_content: &[u8],
    algorithm: Algorithm,
)

Source from the content-addressed store, hash-verified

719/// assert!(!ops.is_empty());
720/// ```
721pub fn compare_content(
722 old_content: &[u8],
723 new_content: &[u8],
724 algorithm: Algorithm,
725) -> Vec<DiffOp> {
726 // Convert to lines
727 let old_lines: Vec<Line> = Line::from_bytes(old_content);
728 let new_lines: Vec<Line> = Line::from_bytes(new_content);
729
730 // Perform diff and extract operations
731 let result = diff(&old_lines, &new_lines, algorithm);
732 result.ops().to_vec()
733}
734
735/// Detect the encoding of content.
736///

Calls 2

diffFunction · 0.50
opsMethod · 0.45