equal
deleted
inserted
replaced
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 from __future__ import absolute_import |
8 from __future__ import absolute_import |
9 |
9 |
10 def addlines(fp, hunk, lena, lenb, a, b): |
10 def addlines(fp, hunk, lena, lenb, a, b): |
|
11 """Read lines from fp into the hunk |
|
12 |
|
13 The hunk is parsed into two arrays, a and b. a gets the old state of |
|
14 the text, b gets the new state. The control char from the hunk is saved |
|
15 when inserting into a, but not b (for performance while deleting files.) |
|
16 """ |
11 while True: |
17 while True: |
12 todoa = lena - len(a) |
18 todoa = lena - len(a) |
13 todob = lenb - len(b) |
19 todob = lenb - len(b) |
14 num = max(todoa, todob) |
20 num = max(todoa, todob) |
15 if num == 0: |
21 if num == 0: |
32 b.append(s[1:]) |
38 b.append(s[1:]) |
33 a.append(s) |
39 a.append(s) |
34 return 0 |
40 return 0 |
35 |
41 |
36 def fix_newline(hunk, a, b): |
42 def fix_newline(hunk, a, b): |
|
43 """Fix up the last lines of a and b when the patch has no newline at EOF""" |
37 l = hunk[-1] |
44 l = hunk[-1] |
38 # tolerate CRLF in last line |
45 # tolerate CRLF in last line |
39 if l.endswith('\r\n'): |
46 if l.endswith('\r\n'): |
40 hline = l[:-2] |
47 hline = l[:-2] |
41 else: |
48 else: |
48 hunk[-1] = hline |
55 hunk[-1] = hline |
49 return 0 |
56 return 0 |
50 |
57 |
51 |
58 |
52 def testhunk(a, b, bstart): |
59 def testhunk(a, b, bstart): |
|
60 """Compare the lines in a with the lines in b |
|
61 |
|
62 a is assumed to have a control char at the start of each line, this char |
|
63 is ignored in the compare. |
|
64 """ |
53 alen = len(a) |
65 alen = len(a) |
54 blen = len(b) |
66 blen = len(b) |
55 if alen > blen - bstart: |
67 if alen > blen - bstart: |
56 return -1 |
68 return -1 |
57 for i in xrange(alen): |
69 for i in xrange(alen): |