MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _original_lines

Function _original_lines

pre_commit/commands/autoupdate.py:119–137  ·  view source on GitHub ↗

detect `rev:` lines or reformat the file

(
        path: str,
        rev_infos: list[RevInfo | None],
        retry: bool = False,
)

Source from the content-addressed store, hash-verified

117
118
119def _original_lines(
120 path: str,
121 rev_infos: list[RevInfo | None],
122 retry: bool = False,
123) -> tuple[list[str], list[int]]:
124 """detect `rev:` lines or reformat the file"""
125 with open(path, newline='') as f:
126 original = f.read()
127
128 lines = original.splitlines(True)
129 idxs = [i for i, line in enumerate(lines) if REV_LINE_RE.match(line)]
130 if len(idxs) == len(rev_infos):
131 return lines, idxs
132 elif retry:
133 raise AssertionError('could not find rev lines')
134 else:
135 with open(path, 'w') as f:
136 f.write(yaml_dump(yaml_load(original)))
137 return _original_lines(path, rev_infos, retry=True)
138
139
140def _write_new_config(path: str, rev_infos: list[RevInfo | None]) -> None:

Callers 1

_write_new_configFunction · 0.85

Calls 2

yaml_dumpFunction · 0.90
matchMethod · 0.45

Tested by

no test coverage detected