-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdiff_normalizer.py
43 lines (34 loc) · 982 Bytes
/
diff_normalizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
########
# Parse raw diff
########
sections = []
currentSection = None
currentChangeLines = None
for line in sys.stdin:
if (line.startswith("###")):
currentSection = {}
currentSection["headline"] = line
currentSection["changes"] = []
sections.append(currentSection)
continue
if (line.startswith("---")):
continue
if (line.startswith("*")):
currentChangeLines = []
currentChangeLines.append(line)
currentSection["changes"].append(currentChangeLines)
continue
if (currentChangeLines):
currentChangeLines.append(line)
########
# Print normalized diff
########
for section in sections:
print(section["headline"])
for changeLines in section["changes"]:
changeText = ""
for line in changeLines:
changeText += line
if (not (("Add _links" in changeText) or ("Delete _links" in changeText))):
print(changeText)