Get rid of the left_out variable
This commit is contained in:
parent
c103d70078
commit
3d814b5b15
1 changed files with 5 additions and 8 deletions
|
|
@ -85,7 +85,8 @@ def main() -> None:
|
||||||
search = sys.argv[1]
|
search = sys.argv[1]
|
||||||
replace = sys.argv[2]
|
replace = sys.argv[2]
|
||||||
|
|
||||||
lines = sys.stdin.read().splitlines(keepends=True)
|
input_data = sys.stdin.read()
|
||||||
|
lines = input_data.splitlines(keepends=True)
|
||||||
preamble_lines = []
|
preamble_lines = []
|
||||||
sections = []
|
sections = []
|
||||||
current = None
|
current = None
|
||||||
|
|
@ -114,27 +115,23 @@ def main() -> None:
|
||||||
|
|
||||||
output_lines = []
|
output_lines = []
|
||||||
output_lines.extend(preamble_lines)
|
output_lines.extend(preamble_lines)
|
||||||
left_out = False
|
|
||||||
|
|
||||||
for section in sections:
|
for section in sections:
|
||||||
kept_hunks = []
|
kept_hunks = []
|
||||||
for hunk_lines in section["hunks"]:
|
for hunk_lines in section["hunks"]:
|
||||||
filtered = filter_hunk(hunk_lines, search, replace)
|
filtered = filter_hunk(hunk_lines, search, replace)
|
||||||
if filtered != hunk_lines:
|
|
||||||
left_out = True
|
|
||||||
if filtered:
|
if filtered:
|
||||||
kept_hunks.append(filtered)
|
kept_hunks.append(filtered)
|
||||||
|
|
||||||
if not kept_hunks:
|
if not kept_hunks:
|
||||||
left_out = True
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
output_lines.extend(section["header"])
|
output_lines.extend(section["header"])
|
||||||
for hunk_lines in kept_hunks:
|
for hunk_lines in kept_hunks:
|
||||||
output_lines.extend(hunk_lines)
|
output_lines.extend(hunk_lines)
|
||||||
|
|
||||||
sys.stdout.write("".join(output_lines))
|
output_data = "".join(output_lines)
|
||||||
if left_out:
|
sys.stdout.write(output_data)
|
||||||
|
if output_data != input_data:
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue