@@ -620,11 +620,13 @@ def parse_context_diff(text):
620
620
del old_hunk [0 ]
621
621
if o :
622
622
old = int (o .group (1 ))
623
+ old_len = int (o .group (2 )) + 1 - old
623
624
while len (new_hunk ) > 0 :
624
625
n = context_hunk_new .match (new_hunk [0 ])
625
626
del new_hunk [0 ]
626
627
if n :
627
628
new = int (n .group (1 ))
629
+ new_len = int (n .group (2 )) + 1 - new
628
630
break
629
631
break
630
632
@@ -638,15 +640,16 @@ def parse_context_diff(text):
638
640
kind = c .group (1 )
639
641
line = c .group (2 )
640
642
641
- if kind == '-' :
643
+ if kind == '-' and ( j != old_len or j == 0 ) :
642
644
changes .append ((old + j , None , line ))
643
645
j += 1
644
- elif kind == ' ' :
646
+ elif kind == ' ' and ((j != old_len and k != new_len )
647
+ or (j == 0 or k == 0 )):
645
648
changes .append ((old + j , new + k , line ))
646
649
j += 1
647
650
k += 1
648
651
elif kind == '+' or kind == '!' :
649
- raise ValueError ("Wat1 " + kind )
652
+ raise ValueError ("Got unexpected change in removal hunk: " + kind )
650
653
651
654
elif len (old_hunk ) == 0 and len (new_hunk ) > 0 :
652
655
# only insertions left?
@@ -657,15 +660,16 @@ def parse_context_diff(text):
657
660
kind = c .group (1 )
658
661
line = c .group (2 )
659
662
660
- if kind == '+' :
663
+ if kind == '+' and ( k != new_len or k == 0 ) :
661
664
changes .append ((None , new + k , line ))
662
665
k += 1
663
- elif kind == ' ' :
666
+ elif kind == ' ' and ((j != old_len and k != new_len )
667
+ or (j == 0 or k == 0 )):
664
668
changes .append ((old + j , new + k , line ))
665
669
j += 1
666
670
k += 1
667
671
elif kind == '-' or kind == '!' :
668
- raise ValueError ("Wat2 " + kind )
672
+ raise ValueError ("Got unexpected change in insertion hunk: " + kind )
669
673
else :
670
674
# both
671
675
while len (old_hunk ) > 0 and len (new_hunk ) > 0 :
@@ -691,11 +695,11 @@ def parse_context_diff(text):
691
695
k += 1
692
696
del old_hunk [0 ]
693
697
del new_hunk [0 ]
694
- elif okind == '-' or okind == '!' :
698
+ elif okind == '-' or okind == '!' and ( j != old_len or j == 0 ) :
695
699
changes .append ((old + j , None , oline ))
696
700
j += 1
697
701
del old_hunk [0 ]
698
- elif nkind == '+' or nkind == '!' :
702
+ elif nkind == '+' or nkind == '!' and ( k != old_len or k == 0 ) :
699
703
changes .append ((None , new + k , nline ))
700
704
k += 1
701
705
del new_hunk [0 ]
0 commit comments