##// END OF EJS Templates
eol: store and reuse pattern matchers instead of creating in tight loop...
Mads Kiilerich -
r30114:ad43458d default
parent child Browse files
Show More
@@ -175,25 +175,27 b' class eolfile(object):'
175
175
176 include = []
176 include = []
177 exclude = []
177 exclude = []
178 self.patterns = []
178 for pattern, style in self.cfg.items('patterns'):
179 for pattern, style in self.cfg.items('patterns'):
179 key = style.upper()
180 key = style.upper()
180 if key == 'BIN':
181 if key == 'BIN':
181 exclude.append(pattern)
182 exclude.append(pattern)
182 else:
183 else:
183 include.append(pattern)
184 include.append(pattern)
185 m = match.match(root, '', [pattern])
186 self.patterns.append((pattern, key, m))
184 # This will match the files for which we need to care
187 # This will match the files for which we need to care
185 # about inconsistent newlines.
188 # about inconsistent newlines.
186 self.match = match.match(root, '', [], include, exclude)
189 self.match = match.match(root, '', [], include, exclude)
187
190
188 def copytoui(self, ui):
191 def copytoui(self, ui):
189 for pattern, style in self.cfg.items('patterns'):
192 for pattern, key, m in self.patterns:
190 key = style.upper()
191 try:
193 try:
192 ui.setconfig('decode', pattern, self._decode[key], 'eol')
194 ui.setconfig('decode', pattern, self._decode[key], 'eol')
193 ui.setconfig('encode', pattern, self._encode[key], 'eol')
195 ui.setconfig('encode', pattern, self._encode[key], 'eol')
194 except KeyError:
196 except KeyError:
195 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
197 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
196 % (style, self.cfg.source('patterns', pattern)))
198 % (key, self.cfg.source('patterns', pattern)))
197 # eol.only-consistent can be specified in ~/.hgrc or .hgeol
199 # eol.only-consistent can be specified in ~/.hgrc or .hgeol
198 for k, v in self.cfg.items('eol'):
200 for k, v in self.cfg.items('eol'):
199 ui.setconfig('eol', k, v, 'eol')
201 ui.setconfig('eol', k, v, 'eol')
@@ -203,10 +205,10 b' class eolfile(object):'
203 for f in (files or ctx.files()):
205 for f in (files or ctx.files()):
204 if f not in ctx:
206 if f not in ctx:
205 continue
207 continue
206 for pattern, style in self.cfg.items('patterns'):
208 for pattern, key, m in self.patterns:
207 if not match.match(repo.root, '', [pattern])(f):
209 if not m(f):
208 continue
210 continue
209 target = self._encode[style.upper()]
211 target = self._encode[key]
210 data = ctx[f].data()
212 data = ctx[f].data()
211 if (target == "to-lf" and "\r\n" in data
213 if (target == "to-lf" and "\r\n" in data
212 or target == "to-crlf" and singlelf.search(data)):
214 or target == "to-crlf" and singlelf.search(data)):
General Comments 0
You need to be logged in to leave comments. Login now