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

Function generate_diff

atomic-core/src/record/workflow/compare.rs:405–421  ·  view source on GitHub ↗

Generate diff operations between two content blobs. Converts content to lines and runs the specified diff algorithm. # Arguments `old_content` - Old content bytes `new_content` - New content bytes `algorithm` - Diff algorithm to use # Returns Vector of diff operations.

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

Source from the content-addressed store, hash-verified

403///
404/// Vector of diff operations.
405pub fn generate_diff(old_content: &[u8], new_content: &[u8], algorithm: Algorithm) -> Vec<DiffOp> {
406 // Convert to lines for diffing
407 let old_lines: Vec<Line> = Line::from_bytes(old_content);
408 let new_lines: Vec<Line> = Line::from_bytes(new_content);
409
410 // Use `diff_raw` instead of `diff` to skip the
411 // `rewrite_positional_shifts` heuristic. That heuristic is helpful
412 // for **displaying** diffs to users but corrupts patch-theory graph
413 // semantics: it rewrites pure insertions into Replace+Insert pairs,
414 // which causes `globalize_replace` to delete unchanged vertices.
415 // Records and graph operations need the algorithmically minimal
416 // diff, not the user-friendly one.
417 let result = diff_raw(&old_lines, &new_lines, algorithm);
418
419 // Return operations
420 result.ops().to_vec()
421}
422
423/// Check if content is identical (byte-for-byte).
424///

Callers 5

compare_contentFunction · 0.85
test_generate_diff_emptyFunction · 0.85

Calls 2

diff_rawFunction · 0.85
opsMethod · 0.45

Tested by 4

test_generate_diff_emptyFunction · 0.68