(diff_lines: Iterable[str])
| 9 | |
| 10 | |
| 11 | def unified_diff_hunks(diff_lines: Iterable[str]) -> list[dict]: |
| 12 | hunks: list[dict] = [] |
| 13 | current: dict | None = None |
| 14 | for line in diff_lines: |
| 15 | m = _HUNK_RE.match(line) |
| 16 | if m: |
| 17 | if current is not None: |
| 18 | hunks.append(current) |
| 19 | old_start = int(m.group(1)) |
| 20 | old_lines = int(m.group(2) or "1") |
| 21 | new_start = int(m.group(3)) |
| 22 | new_lines = int(m.group(4) or "1") |
| 23 | current = { |
| 24 | "oldStart": old_start, |
| 25 | "oldLines": old_lines, |
| 26 | "newStart": new_start, |
| 27 | "newLines": new_lines, |
| 28 | "lines": [], |
| 29 | } |
| 30 | continue |
| 31 | if current is None: |
| 32 | continue |
| 33 | if line.startswith("---") or line.startswith("+++") or line.startswith("\\ No newline"): |
| 34 | continue |
| 35 | current["lines"].append(line) |
| 36 | if current is not None: |
| 37 | hunks.append(current) |
| 38 | return hunks |
| 39 |
no test coverage detected