(patch_text: &str)
| 454 | } |
| 455 | |
| 456 | fn parse_model_patch(patch_text: &str) -> Result<Vec<FilePatch>, ToolError> { |
| 457 | let mut file_patches = Vec::new(); |
| 458 | let begin_file = Regex::new(r"^\*\*\*\s+Begin\s+File:\s+(.+)$").unwrap(); |
| 459 | let delete_file = Regex::new(r"^\*\*\*\s+Delete\s+File:\s+(.+)$").unwrap(); |
| 460 | let end_patch = Regex::new(r"^\*\*\*\s+End\s+Patch$").unwrap(); |
| 461 | let move_to = Regex::new(r"^\*\*\*\s+Move\s+To:\s+(.+)$").unwrap(); |
| 462 | |
| 463 | let mut current_file: Option<FilePatch> = None; |
| 464 | let mut content_lines: Vec<String> = Vec::new(); |
| 465 | let mut in_content = false; |
| 466 | |
| 467 | for line in patch_text.lines() { |
| 468 | if line == "*** Begin Patch" { |
| 469 | continue; |
| 470 | } |
| 471 | |
| 472 | // Detect delete file directive |
| 473 | if let Some(caps) = delete_file.captures(line) { |
| 474 | if let Some(file) = current_file.take() { |
| 475 | if !content_lines.is_empty() { |
| 476 | file_patches.push(file); |
| 477 | } |
| 478 | } |
| 479 | let path = caps[1].trim().to_string(); |
| 480 | file_patches.push(FilePatch { |
| 481 | path, |
| 482 | operation: PatchOperation::Delete, |
| 483 | hunks: Vec::new(), |
| 484 | }); |
| 485 | content_lines = Vec::new(); |
| 486 | in_content = false; |
| 487 | continue; |
| 488 | } |
| 489 | |
| 490 | // Detect move-to directive (applies to current file) |
| 491 | if let Some(caps) = move_to.captures(line) { |
| 492 | if let Some(ref mut file) = current_file { |
| 493 | let target = caps[1].trim().to_string(); |
| 494 | file.operation = PatchOperation::Move { |
| 495 | move_path: target, |
| 496 | }; |
| 497 | } |
| 498 | continue; |
| 499 | } |
| 500 | |
| 501 | if let Some(caps) = begin_file.captures(line) { |
| 502 | if let Some(file) = current_file.take() { |
| 503 | if !content_lines.is_empty() { |
| 504 | file_patches.push(file); |
| 505 | } |
| 506 | } |
| 507 | let path = caps[1].trim().to_string(); |
| 508 | current_file = Some(FilePatch { |
| 509 | path: path.clone(), |
| 510 | operation: PatchOperation::Add, |
| 511 | hunks: Vec::new(), |
| 512 | }); |
| 513 | content_lines = Vec::new(); |
no test coverage detected