comparison mercurial/pure/diffhelpers.py @ 37570:c4c8d0d1267f

diffhelpers: naming and whitespace cleanup
author Yuya Nishihara <yuya@tcha.org>
date Mon, 09 Apr 2018 20:52:54 +0900
parents 53021c4ef0b2
children
comparison
equal deleted inserted replaced
37569:2025bf60adb2 37570:c4c8d0d1267f
21 if num == 0: 21 if num == 0:
22 break 22 break
23 for i in xrange(num): 23 for i in xrange(num):
24 s = fp.readline() 24 s = fp.readline()
25 if s == "\\ No newline at end of file\n": 25 if s == "\\ No newline at end of file\n":
26 fix_newline(hunk, a, b) 26 fixnewline(hunk, a, b)
27 continue 27 continue
28 if s == "\n": 28 if s == "\n":
29 # Some patches may be missing the control char 29 # Some patches may be missing the control char
30 # on empty lines. Supply a leading space. 30 # on empty lines. Supply a leading space.
31 s = " \n" 31 s = " \n"
37 else: 37 else:
38 b.append(s[1:]) 38 b.append(s[1:])
39 a.append(s) 39 a.append(s)
40 return 0 40 return 0
41 41
42 def fix_newline(hunk, a, b): 42 def fixnewline(hunk, a, b):
43 """Fix up the last lines of a and b when the patch has no newline at EOF""" 43 """Fix up the last lines of a and b when the patch has no newline at EOF"""
44 l = hunk[-1] 44 l = hunk[-1]
45 # tolerate CRLF in last line 45 # tolerate CRLF in last line
46 if l.endswith('\r\n'): 46 if l.endswith('\r\n'):
47 hline = l[:-2] 47 hline = l[:-2]
53 if hline.startswith((' ', '-')): 53 if hline.startswith((' ', '-')):
54 a[-1] = hline 54 a[-1] = hline
55 hunk[-1] = hline 55 hunk[-1] = hline
56 return 0 56 return 0
57 57
58
59 def testhunk(a, b, bstart): 58 def testhunk(a, b, bstart):
60 """Compare the lines in a with the lines in b 59 """Compare the lines in a with the lines in b
61 60
62 a is assumed to have a control char at the start of each line, this char 61 a is assumed to have a control char at the start of each line, this char
63 is ignored in the compare. 62 is ignored in the compare.