# HG changeset patch
# User Mads Kiilerich
# Date 1476021282 -7200
# Sun Oct 09 15:54:42 2016 +0200
# Node ID 5240a8c9b6289838592f24f4e41a1158a48b951a
# Parent 408ddba4689de432fe77e0ba8d27765b63719180
eol: store and reuse pattern matchers instead of creating in tight loop
More "right" and more efficient.
diff --git a/hgext/eol.py b/hgext/eol.py
--- a/hgext/eol.py
+++ b/hgext/eol.py
@@ -175,25 +175,27 @@ class eolfile(object):
include = []
exclude = []
+self.patterns = []
for pattern, style in self.cfg.items('patterns'):
key = style.upper()
if key == 'BIN':
exclude.append(pattern)
else:
include.append(pattern)
+m = match.match(root, '', [pattern])
+self.patterns.append((pattern, key, m))
# This will match the files for which we need to care
# about inconsistent newlines.
self.match = match.match(root, '', [], include, exclude)
def copytoui(self, ui):
-for pattern, style in self.cfg.items('patterns'):
-key = style.upper()
+for pattern, key, m in self.patterns:
try:
ui.setconfig('decode', pattern, self._decode[key], 'eol')
ui.setconfig('encode', pattern, self._encode[key], 'eol')
except KeyError:
ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
-% (style, self.cfg.source('patterns', pattern)))
+% (key, self.cfg.source('patterns', pattern)))
# eol.only-consistent can be specified in ~/.hgrc or .hgeol
for k, v in self.cfg.items('eol'):
ui.setconfig('eol', k, v, 'eol')
@@ -203,10 +205,10 @@ class eolfile(object):
for f in (files or ctx.files()):
if f not in ctx:
continue
-for pattern, style in self.cfg.items('patterns'):
-if not match.match(repo.root, '', [pattern])(f):
+for pattern, key, m in self.patterns:
+if not m(f):
continue
-target = self._encode[style.upper()]
+target = self._encode[key]
data = ctx[f].data()
if (target == "to-lf" and "\r\n" in data
or target == "to-crlf" and singlelf.search(data)):
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel