Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/diffhelper.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 57875cf423c9 |
children | 10f48720ef95 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
29 if num == 0: | 29 if num == 0: |
30 break | 30 break |
31 for i in pycompat.xrange(num): | 31 for i in pycompat.xrange(num): |
32 s = fp.readline() | 32 s = fp.readline() |
33 if not s: | 33 if not s: |
34 raise error.ParseError(_('incomplete hunk')) | 34 raise error.ParseError(_(b'incomplete hunk')) |
35 if s == "\\ No newline at end of file\n": | 35 if s == b"\\ No newline at end of file\n": |
36 fixnewline(hunk, a, b) | 36 fixnewline(hunk, a, b) |
37 continue | 37 continue |
38 if s == '\n' or s == '\r\n': | 38 if s == b'\n' or s == b'\r\n': |
39 # Some patches may be missing the control char | 39 # Some patches may be missing the control char |
40 # on empty lines. Supply a leading space. | 40 # on empty lines. Supply a leading space. |
41 s = ' ' + s | 41 s = b' ' + s |
42 hunk.append(s) | 42 hunk.append(s) |
43 if s.startswith('+'): | 43 if s.startswith(b'+'): |
44 b.append(s[1:]) | 44 b.append(s[1:]) |
45 elif s.startswith('-'): | 45 elif s.startswith(b'-'): |
46 a.append(s) | 46 a.append(s) |
47 else: | 47 else: |
48 b.append(s[1:]) | 48 b.append(s[1:]) |
49 a.append(s) | 49 a.append(s) |
50 | 50 |
51 | 51 |
52 def fixnewline(hunk, a, b): | 52 def fixnewline(hunk, a, b): |
53 """Fix up the last lines of a and b when the patch has no newline at EOF""" | 53 """Fix up the last lines of a and b when the patch has no newline at EOF""" |
54 l = hunk[-1] | 54 l = hunk[-1] |
55 # tolerate CRLF in last line | 55 # tolerate CRLF in last line |
56 if l.endswith('\r\n'): | 56 if l.endswith(b'\r\n'): |
57 hline = l[:-2] | 57 hline = l[:-2] |
58 else: | 58 else: |
59 hline = l[:-1] | 59 hline = l[:-1] |
60 | 60 |
61 if hline.startswith((' ', '+')): | 61 if hline.startswith((b' ', b'+')): |
62 b[-1] = hline[1:] | 62 b[-1] = hline[1:] |
63 if hline.startswith((' ', '-')): | 63 if hline.startswith((b' ', b'-')): |
64 a[-1] = hline | 64 a[-1] = hline |
65 hunk[-1] = hline | 65 hunk[-1] = hline |
66 | 66 |
67 | 67 |
68 def testhunk(a, b, bstart): | 68 def testhunk(a, b, bstart): |