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)
| 403 | /// |
| 404 | /// Vector of diff operations. |
| 405 | pub 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 | /// |