MCPcopy Create free account
hub / github.com/Persper/code-analytics / parse_patch

Function parse_patch

persper/graphs/parse_patch.py:25–41  ·  view source on GitHub ↗

Parse the content of a patch string and return a list of modified intervals >>> parse_patch(example_patch) [[2, 8], [13, 21]]

(text)

Source from the content-addressed store, hash-verified

23 platforms darwin"""
24
25def parse_patch(text):
26 """Parse the content of a patch string and return a list of modified intervals
27
28 >>> parse_patch(example_patch)
29 [[2, 8], [13, 21]]
30 """
31 re_chunk_header = re.compile("""\@\@\s*
32 \-(?P<old_start_line>\d+),(?P<old_num_lines>\d+)\s*
33 \+(?P<new_start_line>\d+),(?P<new_num_lines>\d+)\s*
34 \@\@
35 """, re.VERBOSE)
36 modified_intervals = []
37 for m in re_chunk_header.finditer(text):
38 old_start_line, old_num_lines, _, _ = m.groups()
39 modified_intervals.append([int(old_start_line), int(old_start_line) + int(old_num_lines) - 1])
40
41 return modified_intervals
42
43if __name__ == "__main__":
44 import doctest

Callers 2

on_renameMethod · 0.90
on_modifyMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected