Split up a change in removed lines and in added lines

This commit is contained in:
Sven van Heugten 2026-03-05 17:44:45 +01:00
parent 4715d9d858
commit 0aee4d44a5
No known key found for this signature in database
GPG key ID: D612F88666F4F660

View file

@ -4,6 +4,20 @@ import sys
def should_include_change(change_lines: list[str], search: str, replace: str) -> bool: def should_include_change(change_lines: list[str], search: str, replace: str) -> bool:
removed_lines = []
added_lines = []
phase = "minus"
for line in change_lines:
if line.startswith("-"):
if phase != "minus":
raise ValueError("Non-consecutive '-' and '+' lines in change block.")
removed_lines.append(line[1:])
continue
if line.startswith("+"):
phase = "plus"
added_lines.append(line[1:])
continue
raise ValueError("Unexpected non-change line in change block.")
return True return True