Add main implementation with a placeholder for should_include_hunk
This commit is contained in:
parent
4234866a38
commit
8b45ac3d87
1 changed files with 54 additions and 3 deletions
|
|
@ -3,9 +3,60 @@
|
|||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
data = sys.stdin.read()
|
||||
sys.stdout.write(data)
|
||||
def should_include_hunk(hunk_text: str) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def main() -> None:
|
||||
lines = sys.stdin.read().splitlines(keepends=True)
|
||||
preamble_lines = []
|
||||
sections = []
|
||||
current = None
|
||||
|
||||
for line in lines:
|
||||
if line.startswith("diff --git "):
|
||||
if current is not None:
|
||||
sections.append(current)
|
||||
current = {"header": [line], "hunks": []}
|
||||
continue
|
||||
|
||||
if current is None:
|
||||
preamble_lines.append(line)
|
||||
continue
|
||||
|
||||
if line.startswith("@@ "):
|
||||
current["hunks"].append([line])
|
||||
else:
|
||||
if current["hunks"]:
|
||||
current["hunks"][-1].append(line)
|
||||
else:
|
||||
current["header"].append(line)
|
||||
|
||||
if current is not None:
|
||||
sections.append(current)
|
||||
|
||||
output_lines = []
|
||||
output_lines.extend(preamble_lines)
|
||||
|
||||
for section in sections:
|
||||
if not section["hunks"]:
|
||||
output_lines.extend(section["header"])
|
||||
continue
|
||||
|
||||
kept_hunks = []
|
||||
for hunk_lines in section["hunks"]:
|
||||
hunk_text = "".join(hunk_lines)
|
||||
if should_include_hunk(hunk_text):
|
||||
kept_hunks.append(hunk_lines)
|
||||
|
||||
if not kept_hunks:
|
||||
continue
|
||||
|
||||
output_lines.extend(section["header"])
|
||||
for hunk_lines in kept_hunks:
|
||||
output_lines.extend(hunk_lines)
|
||||
|
||||
sys.stdout.write("".join(output_lines))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue