(lines: list[str], input: str)
| 124 | |
| 125 | |
| 126 | def _parse_update_diff(lines: list[str], input: str) -> ParsedUpdateDiff: |
| 127 | parser = ParserState(lines=[*lines, END_PATCH]) |
| 128 | input_lines = input.split("\n") |
| 129 | chunks: list[Chunk] = [] |
| 130 | cursor = 0 |
| 131 | |
| 132 | while not _is_done(parser, END_SECTION_MARKERS): |
| 133 | anchor = _read_str(parser, "@@ ") |
| 134 | has_bare_anchor = ( |
| 135 | anchor == "" and parser.index < len(parser.lines) and parser.lines[parser.index] == "@@" |
| 136 | ) |
| 137 | if has_bare_anchor: |
| 138 | parser.index += 1 |
| 139 | |
| 140 | if not (anchor or has_bare_anchor or cursor == 0): |
| 141 | current_line = parser.lines[parser.index] if parser.index < len(parser.lines) else "" |
| 142 | raise ValueError(f"Invalid Line:\n{current_line}") |
| 143 | |
| 144 | if anchor.strip(): |
| 145 | cursor = _advance_cursor_to_anchor(anchor, input_lines, cursor, parser) |
| 146 | |
| 147 | section = _read_section(parser.lines, parser.index) |
| 148 | find_result = _find_context(input_lines, section.next_context, cursor, section.eof) |
| 149 | if find_result.new_index == -1: |
| 150 | ctx_text = "\n".join(section.next_context) |
| 151 | if section.eof: |
| 152 | raise ValueError(f"Invalid EOF Context {cursor}:\n{ctx_text}") |
| 153 | raise ValueError(f"Invalid Context {cursor}:\n{ctx_text}") |
| 154 | |
| 155 | cursor = find_result.new_index + len(section.next_context) |
| 156 | parser.fuzz += find_result.fuzz |
| 157 | parser.index = section.end_index |
| 158 | |
| 159 | for ch in section.section_chunks: |
| 160 | chunks.append( |
| 161 | Chunk( |
| 162 | orig_index=ch.orig_index + find_result.new_index, |
| 163 | del_lines=list(ch.del_lines), |
| 164 | ins_lines=list(ch.ins_lines), |
| 165 | ) |
| 166 | ) |
| 167 | |
| 168 | return ParsedUpdateDiff(chunks=chunks, fuzz=parser.fuzz) |
| 169 | |
| 170 | |
| 171 | def _advance_cursor_to_anchor( |
no test coverage detected