##// END OF EJS Templates
win32text: use util.binary to detect \0
Christian Ebert -
r6247:7f4257b5 default
parent child Browse files
Show More
@@ -22,6 +22,7 b''
22 # [hooks]
22 # [hooks]
23 # pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
23 # pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
24
24
25 from mercurial import util
25 from mercurial.i18n import gettext as _
26 from mercurial.i18n import gettext as _
26 from mercurial.node import bin, short
27 from mercurial.node import bin, short
27 import re
28 import re
@@ -46,19 +47,15 b' def dumbdecode(s, cmd, ui=None, repo=Non'
46 def dumbencode(s, cmd):
47 def dumbencode(s, cmd):
47 return s.replace('\r\n', '\n')
48 return s.replace('\r\n', '\n')
48
49
49 def clevertest(s, cmd):
50 if '\0' in s: return False
51 return True
52
53 def cleverdecode(s, cmd, **kwargs):
50 def cleverdecode(s, cmd, **kwargs):
54 if clevertest(s, cmd):
51 if util.binary(s):
55 return dumbdecode(s, cmd, **kwargs)
52 return s
56 return s
53 return dumbdecode(s, cmd, **kwargs)
57
54
58 def cleverencode(s, cmd):
55 def cleverencode(s, cmd):
59 if clevertest(s, cmd):
56 if util.binary(s):
60 return dumbencode(s, cmd)
57 return s
61 return s
58 return dumbencode(s, cmd)
62
59
63 _filters = {
60 _filters = {
64 'dumbdecode:': dumbdecode,
61 'dumbdecode:': dumbdecode,
@@ -75,7 +72,7 b' def forbidcrlf(ui, repo, hooktype, node,'
75 if f not in c:
72 if f not in c:
76 continue
73 continue
77 data = c[f].data()
74 data = c[f].data()
78 if '\0' not in data and '\r\n' in data:
75 if not util.binary(data) and '\r\n' in data:
79 if not halt:
76 if not halt:
80 ui.warn(_('Attempt to commit or push text file(s) '
77 ui.warn(_('Attempt to commit or push text file(s) '
81 'using CRLF line endings\n'))
78 'using CRLF line endings\n'))
General Comments 0
You need to be logged in to leave comments. Login now