r"""Parse unified diff with 0 lines of context. Hunk range info format: @@ -3,2 +4,0 @@ Hunk originally starting at line 3, and occupying 2 lines, now starts at line 4, and occupies 0 lines, i.e. it was deleted. @@ -9 +10,2 @@ Hunk siz
(diff_str)
| 423 | |
| 424 | @staticmethod |
| 425 | def process_diff(diff_str): |
| 426 | r"""Parse unified diff with 0 lines of context. |
| 427 | |
| 428 | Hunk range info format: |
| 429 | @@ -3,2 +4,0 @@ |
| 430 | Hunk originally starting at line 3, and occupying 2 lines, now |
| 431 | starts at line 4, and occupies 0 lines, i.e. it was deleted. |
| 432 | @@ -9 +10,2 @@ |
| 433 | Hunk size can be omitted, and defaults to one line. |
| 434 | |
| 435 | Dealing with ambiguous hunks: |
| 436 | "A\nB\n" -> "C\n" |
| 437 | Was 'A' modified, and 'B' deleted? Or 'B' modified, 'A' deleted? |
| 438 | Or both deleted? To minimize confusion, let's simply mark the |
| 439 | hunk as modified. |
| 440 | |
| 441 | Arguments: |
| 442 | diff_str (string): The unified diff string to parse. |
| 443 | |
| 444 | Returns: |
| 445 | tuple: (first, last, [inserted], [modified], [deleted]) |
| 446 | A tuple with meta information of the diff result. |
| 447 | """ |
| 448 | # first and last changed line in the view |
| 449 | first, last = 0, 0 |
| 450 | # lists with inserted, modified and deleted lines |
| 451 | inserted, modified, deleted = [], [], [] |
| 452 | hunk_re = r'^@@ \-(\d+),?(\d*) \+(\d+),?(\d*) @@' |
| 453 | for hunk in re.finditer(hunk_re, diff_str, re.MULTILINE): |
| 454 | _, old_size, start, new_size = hunk.groups() |
| 455 | start = int(start) |
| 456 | old_size = int(old_size or 1) |
| 457 | new_size = int(new_size or 1) |
| 458 | if first == 0: |
| 459 | first = max(1, start) |
| 460 | if not old_size: |
| 461 | last = start + new_size |
| 462 | inserted += range(start, last) |
| 463 | elif not new_size: |
| 464 | last = start + 1 |
| 465 | deleted.append(last) |
| 466 | else: |
| 467 | last = start + new_size |
| 468 | modified += range(start, last) |
| 469 | return (first, last, inserted, modified, deleted) |
| 470 | |
| 471 | def diff_changed_blocks(self): |
| 472 | """Create a list of all changed code blocks from cached diff result. |
no outgoing calls
no test coverage detected