MCPcopy Create free account
hub / github.com/danvk/webdiff / parse_raw_diff

Function parse_raw_diff

webdiff/unified_diff.py:194–218  ·  view source on GitHub ↗
(diff: str)

Source from the content-addressed store, hash-verified

192
193
194def parse_raw_diff(diff: str) -> List[RawDiffLine]:
195 # each diff line can be two or three parts. The parts and lines are both null-delimited.
196 # The "lines" start with ":".
197 parts = diff.strip('\0').split('\0')
198 lines = []
199 numstats = []
200 curline = None
201 for part in parts:
202 if part.startswith(':'):
203 curline = [part]
204 lines.append(curline)
205 elif m := re.match(r'(\d+|-)\t(\d+|-)\t', part):
206 # numstat line
207 add, drop = m.group(1), m.group(2)
208 curline = [int(add) if add != '-' else None, int(drop) if drop != '-' else None]
209 numstats.append(curline)
210 else:
211 curline.append(part)
212 diff_lines = []
213 for line, stats in zip(lines, numstats):
214 diff = parse_raw_diff_line(line)
215 diff.num_add = stats[0]
216 diff.num_delete = stats[1]
217 diff_lines.append(diff)
218 return diff_lines

Callers 3

gitdiffFunction · 0.90
test_parse_raw_diff_manyFunction · 0.90

Calls 1

parse_raw_diff_lineFunction · 0.85

Tested by 2

test_parse_raw_diff_manyFunction · 0.72