MCPcopy Index your code
hub / github.com/python/cpython / get_diff_lines

Function get_diff_lines

Doc/tools/check-warnings.py:68–100  ·  view source on GitHub ↗

List the lines changed between two Git refs for a specific file.

(ref_a: str, ref_b: str, file: Path)

Source from the content-addressed store, hash-verified

66
67
68def get_diff_lines(ref_a: str, ref_b: str, file: Path) -> list[int]:
69 """List the lines changed between two Git refs for a specific file."""
70 diff_output = subprocess.run(
71 [
72 "git",
73 "diff",
74 "--unified=0",
75 f"{ref_a}...{ref_b}",
76 "--",
77 str(file),
78 ],
79 stdout=subprocess.PIPE,
80 check=True,
81 text=True,
82 encoding="UTF-8",
83 )
84
85 # Scrape line offsets + lengths from diff and convert to line numbers
86 line_matches = DIFF_PATTERN.finditer(diff_output.stdout)
87 # Removed and added line counts are 1 if not printed
88 line_match_values = [
89 line_match.groupdict(default=1) for line_match in line_matches
90 ]
91 line_ints = [
92 (int(match_value["lineb"]), int(match_value["added"]))
93 for match_value in line_match_values
94 ]
95 line_ranges = [
96 range(line_b, line_b + added) for line_b, added in line_ints
97 ]
98 line_numbers = list(itertools.chain(*line_ranges))
99
100 return line_numbers
101
102
103def get_para_line_numbers(file_obj: TextIO) -> list[list[int]]:

Callers 1

filter_warnings_by_diffFunction · 0.85

Calls 4

strFunction · 0.85
listClass · 0.85
chainMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…