Parse ``@@``-delimited change chunks for an Update File hunk.
(
lines: List[str], start_idx: int,
)
| 580 | return content, i |
| 581 | |
| 582 | def _parse_update_chunks( |
| 583 | lines: List[str], start_idx: int, |
| 584 | ) -> Tuple[List[UpdateChunk], int]: |
| 585 | """Parse ``@@``-delimited change chunks for an Update File hunk.""" |
| 586 | chunks: List[UpdateChunk] = [] |
| 587 | i = start_idx |
| 588 | while i < len(lines) and not lines[i].startswith("***"): |
| 589 | if lines[i].startswith("@@"): |
| 590 | context_line = lines[i][2:].strip() |
| 591 | i += 1 |
| 592 | old_lines: List[str] = [] |
| 593 | new_lines: List[str] = [] |
| 594 | is_end_of_file = False |
| 595 | |
| 596 | while i < len(lines): |
| 597 | cl = lines[i] |
| 598 | if cl.startswith("@@"): |
| 599 | break |
| 600 | if cl.startswith("***") and cl != "*** End of File": |
| 601 | break |
| 602 | if cl == "*** End of File": |
| 603 | is_end_of_file = True |
| 604 | i += 1 |
| 605 | break |
| 606 | if cl.startswith(" "): |
| 607 | old_lines.append(cl[1:]) |
| 608 | new_lines.append(cl[1:]) |
| 609 | elif cl.startswith("-"): |
| 610 | old_lines.append(cl[1:]) |
| 611 | elif cl.startswith("+"): |
| 612 | new_lines.append(cl[1:]) |
| 613 | i += 1 |
| 614 | |
| 615 | chunks.append(UpdateChunk( |
| 616 | old_lines=old_lines, |
| 617 | new_lines=new_lines, |
| 618 | change_context=context_line or None, |
| 619 | is_end_of_file=is_end_of_file, |
| 620 | )) |
| 621 | else: |
| 622 | i += 1 |
| 623 | |
| 624 | return chunks, i |
| 625 | |
| 626 | def parse_patch(patch_text: str) -> PatchResult: |
| 627 | """Parse a ``*** Begin Patch`` / ``*** End Patch`` block. |
no test coverage detected