Compare two content blobs and produce a diff. This is the main entry point for content comparison. It handles: - Encoding detection for both contents - Binary file detection (skips diffing) - Diff generation for text files # Arguments `old_content` - Content from pristine (empty for new files) `new_content` - Content from working copy `algorithm` - Diff algorithm to use # Returns A `CompareRe
(
old_content: &[u8],
new_content: &[u8],
algorithm: Algorithm,
)
| 335 | /// assert!(!result.is_binary); |
| 336 | /// ``` |
| 337 | pub fn compare_content( |
| 338 | old_content: &[u8], |
| 339 | new_content: &[u8], |
| 340 | algorithm: Algorithm, |
| 341 | ) -> CompareResult { |
| 342 | // Detect encodings |
| 343 | let old_encoding = detect_encoding(old_content); |
| 344 | let new_encoding = detect_encoding(new_content); |
| 345 | |
| 346 | // Quick check: if bytes are identical, no changes |
| 347 | if old_content == new_content { |
| 348 | return CompareResult::identical(old_encoding); |
| 349 | } |
| 350 | |
| 351 | // Check if either is binary |
| 352 | if is_binary(old_content) || is_binary(new_content) { |
| 353 | return CompareResult::binary(old_encoding, new_encoding); |
| 354 | } |
| 355 | |
| 356 | // Generate diff for text content |
| 357 | let diff_ops = generate_diff(old_content, new_content, algorithm); |
| 358 | |
| 359 | CompareResult::with_diff(old_encoding, new_encoding, diff_ops) |
| 360 | } |
| 361 | |
| 362 | /// Compare content with size limit check. |
| 363 | /// |