File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 4
4
from whatthepatch .patch import Change , diffobj , header as headerobj
5
5
6
6
7
+ import time
7
8
import unittest
8
9
import os
9
10
@@ -1420,6 +1421,27 @@ def test_svn_mixed_line_ends(self):
1420
1421
results = list (wtp .patch .parse_patch (text ))
1421
1422
self .assertEqual (results [0 ].header , expected_header )
1422
1423
1424
+ def test_huge_path (self ):
1425
+ start_time = time .time ()
1426
+ text = """diff --git a/huge.file b/huge.file
1427
+ index 0000000..1111111 100644
1428
+ --- a/huge.file
1429
+ +++ a/huge.file
1430
+ @@ -3,13 +3,1000007 @@
1431
+ 00000000
1432
+ 11111111
1433
+ 22222222
1434
+ -33333333
1435
+ -44444444
1436
+ +55555555
1437
+ +66666666
1438
+ """
1439
+ for n in range (0 , 1000000 ):
1440
+ text += "+" + hex (n ) + "\n "
1441
+ result = list (wtp .patch .parse_patch (text ))
1442
+ self .assertEqual (1 , len (result ))
1443
+ self .assertEqual (1000007 , len (result [0 ].changes ))
1444
+ self .assertGreater (10 , time .time () - start_time )
1423
1445
1424
1446
if __name__ == "__main__" :
1425
1447
unittest .main ()
Original file line number Diff line number Diff line change @@ -582,6 +582,8 @@ def parse_unified_diff(text):
582
582
new = 0
583
583
r = 0
584
584
i = 0
585
+ old_len = 0
586
+ new_len = 0
585
587
586
588
changes = list ()
587
589
@@ -609,12 +611,11 @@ def parse_unified_diff(text):
609
611
h = None
610
612
break
611
613
612
- while len ( hunk ) > 0 :
613
- c = unified_change .match (hunk [ 0 ] )
614
+ for n in hunk :
615
+ c = unified_change .match (n )
614
616
if c :
615
617
kind = c .group (1 )
616
618
line = c .group (2 )
617
- c = None
618
619
619
620
if kind == "-" and (r != old_len or r == 0 ):
620
621
changes .append (Change (old + r , None , line , hunk_n ))
@@ -628,8 +629,6 @@ def parse_unified_diff(text):
628
629
r += 1
629
630
i += 1
630
631
631
- del hunk [0 ]
632
-
633
632
if len (changes ) > 0 :
634
633
return changes
635
634
You can’t perform that action at this time.
0 commit comments