Parse unified diff output into a list of (file_path, diff_content) tuples. Only includes files with source code extensions.
(diff_output)
| 613 | |
| 614 | |
| 615 | def parse_diff_into_files(diff_output): |
| 616 | """ |
| 617 | Parse unified diff output into a list of (file_path, diff_content) tuples. |
| 618 | Only includes files with source code extensions. |
| 619 | """ |
| 620 | if not diff_output or not diff_output.strip(): |
| 621 | return [] |
| 622 | |
| 623 | files = [] |
| 624 | file_diffs = diff_output.split("diff --git ") |
| 625 | |
| 626 | for file_diff in file_diffs: |
| 627 | if not file_diff.strip(): |
| 628 | continue |
| 629 | |
| 630 | # Extract filename from first line: "a/path/to/file b/path/to/file" |
| 631 | lines = file_diff.split('\n') |
| 632 | header_match = re.match(r'^a/(.+?) b/(.+)$', lines[0]) |
| 633 | if not header_match: |
| 634 | continue |
| 635 | |
| 636 | file_path = header_match.group(2) or header_match.group(1) or '' |
| 637 | |
| 638 | # Filter to source code files only |
| 639 | if not _is_reviewable_source(file_path): |
| 640 | continue |
| 641 | |
| 642 | # Extract the diff content (from first @@ onwards) |
| 643 | diff_lines = [] |
| 644 | in_hunks = False |
| 645 | for line in lines[1:]: |
| 646 | if line.startswith('@@'): |
| 647 | in_hunks = True |
| 648 | if in_hunks: |
| 649 | diff_lines.append(line) |
| 650 | |
| 651 | if diff_lines: |
| 652 | files.append((file_path, '\n'.join(diff_lines))) |
| 653 | |
| 654 | return files |
| 655 | |
| 656 | |
| 657 | def filter_preexisting_from_diff(diff_files, cwd, baseline_sha): |
no test coverage detected