##// END OF EJS Templates
Get rid of reimplementations of util.binary
Bryan O'Sullivan -
r6508:4b2c266b default
parent child Browse files
Show More
@@ -100,11 +100,6 b' def utcdate(date):'
100 '''Returns hgdate in cvs-like UTC format.'''
100 '''Returns hgdate in cvs-like UTC format.'''
101 return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
101 return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
102
102
103 def textsafe(s):
104 '''Safe version of util.binary with reversed logic.
105 Note: argument may not be None, which is allowed for util.binary.'''
106 return '\0' not in s
107
108 # make keyword tools accessible
103 # make keyword tools accessible
109 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
104 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
110
105
@@ -163,7 +158,7 b' class kwtemplater(object):'
163
158
164 def expand(self, path, node, data):
159 def expand(self, path, node, data):
165 '''Returns data with keywords expanded.'''
160 '''Returns data with keywords expanded.'''
166 if not self.restrict and self.matcher(path) and textsafe(data):
161 if not self.restrict and self.matcher(path) and not util.binary(data):
167 changenode = self.getnode(path, node)
162 changenode = self.getnode(path, node)
168 return self.substitute(data, path, changenode, self.re_kw.sub)
163 return self.substitute(data, path, changenode, self.re_kw.sub)
169 return data
164 return data
@@ -191,7 +186,7 b' class kwtemplater(object):'
191 for f in candidates:
186 for f in candidates:
192 fp = self.repo.file(f)
187 fp = self.repo.file(f)
193 data = fp.read(mf[f])
188 data = fp.read(mf[f])
194 if not textsafe(data):
189 if util.binary(data):
195 continue
190 continue
196 if expand:
191 if expand:
197 changenode = node or self.getnode(f, mf[f])
192 changenode = node or self.getnode(f, mf[f])
@@ -211,7 +206,7 b' class kwtemplater(object):'
211
206
212 def shrink(self, fname, text):
207 def shrink(self, fname, text):
213 '''Returns text with all keyword substitutions removed.'''
208 '''Returns text with all keyword substitutions removed.'''
214 if self.matcher(fname) and textsafe(text):
209 if self.matcher(fname) and not util.binary(text):
215 return self.shrinktext(text)
210 return self.shrinktext(text)
216 return text
211 return text
217
212
@@ -219,7 +214,7 b' class kwtemplater(object):'
219 '''Returns lines with keyword substitutions removed.'''
214 '''Returns lines with keyword substitutions removed.'''
220 if self.matcher(fname):
215 if self.matcher(fname):
221 text = ''.join(lines)
216 text = ''.join(lines)
222 if textsafe(text):
217 if not util.binary(text):
223 return self.shrinktext(text).splitlines(True)
218 return self.shrinktext(text).splitlines(True)
224 return lines
219 return lines
225
220
@@ -64,27 +64,23 b' def macdumbdecode(s, cmd, **kwargs):'
64 def macdumbencode(s, cmd):
64 def macdumbencode(s, cmd):
65 return s.replace('\r', '\n')
65 return s.replace('\r', '\n')
66
66
67 def clevertest(s, cmd):
68 if '\0' in s: return False
69 return True
70
71 def cleverdecode(s, cmd, **kwargs):
67 def cleverdecode(s, cmd, **kwargs):
72 if clevertest(s, cmd):
68 if not util.binary(s):
73 return dumbdecode(s, cmd, **kwargs)
69 return dumbdecode(s, cmd, **kwargs)
74 return s
70 return s
75
71
76 def cleverencode(s, cmd):
72 def cleverencode(s, cmd):
77 if clevertest(s, cmd):
73 if not util.binary(s):
78 return dumbencode(s, cmd)
74 return dumbencode(s, cmd)
79 return s
75 return s
80
76
81 def macdecode(s, cmd, **kwargs):
77 def macdecode(s, cmd, **kwargs):
82 if clevertest(s, cmd):
78 if not util.binary(s):
83 return macdumbdecode(s, cmd, **kwargs)
79 return macdumbdecode(s, cmd, **kwargs)
84 return s
80 return s
85
81
86 def macencode(s, cmd):
82 def macencode(s, cmd):
87 if clevertest(s, cmd):
83 if not util.binary(s):
88 return macdumbencode(s, cmd)
84 return macdumbencode(s, cmd)
89 return s
85 return s
90
86
@@ -107,7 +103,7 b' def forbidnewline(ui, repo, hooktype, no'
107 if f not in c:
103 if f not in c:
108 continue
104 continue
109 data = c[f].data()
105 data = c[f].data()
110 if '\0' not in data and newline in data:
106 if not util.binary(data) and newline in data:
111 if not halt:
107 if not halt:
112 ui.warn(_('Attempt to commit or push text file(s) '
108 ui.warn(_('Attempt to commit or push text file(s) '
113 'using %s line endings\n') %
109 'using %s line endings\n') %
General Comments 0
You need to be logged in to leave comments. Login now