INNER CODE UNIT · Python
parse_diff
alibaba/loongcollector · tools/coverage-diff/main.py:18
def parse_diff(diff_output):
changes = {}
current_file = None
for line in diff_output.split('\n'):
# 识别文件名
file_match = re.match(r'^diff --git a/(.*) b/(.*)$', line)
if file_match:
current_file = file_match.group(2)
changes[current_file] = []
continue
# 识别文件中的行变化
hunk_match = re.match(r'^@@ -\d+(,\d+)? \+(\d+)(,(\d+))? @@', line)
if hunk_match and current_file:
start_line = int(hunk_match.group(2))
line_count = int(hunk_match.group(4) if hunk_match.group(4) else 1)
for i in range(start_line, start_line + line_count):