Show More
@@ -1,45 +1,45 b'' | |||||
1 | from mercurial import util, ui |
|
1 | from mercurial import util, ui | |
2 | from mercurial.i18n import gettext as _ |
|
2 | from mercurial.i18n import gettext as _ | |
3 | import re |
|
3 | import re | |
4 |
|
4 | |||
5 | # regexp for single LF without CR preceding. |
|
5 | # regexp for single LF without CR preceding. | |
6 | re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE) |
|
6 | re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE) | |
7 |
|
7 | |||
8 | def dumbdecode(s, cmd): |
|
8 | def dumbdecode(s, cmd): | |
9 | # warn if already has CRLF in repository. |
|
9 | # warn if already has CRLF in repository. | |
10 | # it might cause unexpected eol conversion. |
|
10 | # it might cause unexpected eol conversion. | |
11 | # see issue 302: |
|
11 | # see issue 302: | |
12 | # http://www.selenic.com/mercurial/bts/issue302 |
|
12 | # http://www.selenic.com/mercurial/bts/issue302 | |
13 | if '\r\n' in s: |
|
13 | if '\r\n' in s: | |
14 | u = ui.ui() |
|
14 | u = ui.ui() | |
15 | u.warn(_('WARNING: file in repository already has CRLF line ending \n' |
|
15 | u.warn(_('WARNING: file in repository already has CRLF line ending \n' | |
16 | ' which does not need eol conversion by win32text plugin.\n' |
|
16 | ' which does not need eol conversion by win32text plugin.\n' | |
17 | ' Please reconsider encode/decode setting in' |
|
17 | ' Please reconsider encode/decode setting in' | |
18 | ' mercurial.ini or .hg/hgrc\n' |
|
18 | ' mercurial.ini or .hg/hgrc\n' | |
19 | ' before next commit.\n')) |
|
19 | ' before next commit.\n')) | |
20 | # replace single LF to CRLF |
|
20 | # replace single LF to CRLF | |
21 | return re_single_lf.sub('\\1\r\n', s) |
|
21 | return re_single_lf.sub('\\1\r\n', s) | |
22 |
|
22 | |||
23 | def dumbencode(s, cmd): |
|
23 | def dumbencode(s, cmd): | |
24 | return s.replace('\r\n', '\n') |
|
24 | return s.replace('\r\n', '\n') | |
25 |
|
25 | |||
26 | def clevertest(s, cmd): |
|
26 | def clevertest(s, cmd): | |
27 | if '\0' in s: return False |
|
27 | if '\0' in s: return False | |
28 | return True |
|
28 | return True | |
29 |
|
29 | |||
30 | def cleverdecode(s, cmd): |
|
30 | def cleverdecode(s, cmd): | |
31 | if clevertest(s, cmd): |
|
31 | if clevertest(s, cmd): | |
32 | return dumbdecode(s, cmd) |
|
32 | return dumbdecode(s, cmd) | |
33 | return s |
|
33 | return s | |
34 |
|
34 | |||
35 | def cleverencode(s, cmd): |
|
35 | def cleverencode(s, cmd): | |
36 | if clevertest(s, cmd): |
|
36 | if clevertest(s, cmd): | |
37 | return dumbencode(s, cmd) |
|
37 | return dumbencode(s, cmd) | |
38 | return s |
|
38 | return s | |
39 |
|
39 | |||
40 | util.filtertable.update({ |
|
40 | util.filtertable.update({ | |
41 | 'dumbdecode:': dumbdecode, |
|
41 | 'dumbdecode:': dumbdecode, | |
42 | 'dumbencode:': dumbencode, |
|
42 | 'dumbencode:': dumbencode, | |
43 | 'cleverdecode:': cleverdecode, |
|
43 | 'cleverdecode:': cleverdecode, | |
44 | 'cleverencode:': cleverencode, |
|
44 | 'cleverencode:': cleverencode, | |
45 | }) |
|
45 | }) |
General Comments 0
You need to be logged in to leave comments.
Login now