Mercurial > public > mercurial-scm > hg-stable
comparison contrib/check-code.py @ 19307:5443d40d524b
check-code: only fix patterns once
The patterns were fixed once for every file. Now only do it once when loading
the file.
author | Simon Heimberg <simohe@besonet.ch> |
---|---|
date | Sat, 08 Jun 2013 20:20:14 +0200 |
parents | 60b63216997c |
children | 84faaacbd3fa |
comparison
equal
deleted
inserted
replaced
19306:59cdd3a7e281 | 19307:5443d40d524b |
---|---|
315 ('layering violation ui in util', r'mercurial/util\.py', pyfilters, | 315 ('layering violation ui in util', r'mercurial/util\.py', pyfilters, |
316 inutilpats), | 316 inutilpats), |
317 ('txt', r'.*\.txt$', txtfilters, txtpats), | 317 ('txt', r'.*\.txt$', txtfilters, txtpats), |
318 ] | 318 ] |
319 | 319 |
320 def _preparepats(): | |
321 for c in checks: | |
322 failandwarn = c[-1] | |
323 for pats in failandwarn: | |
324 for i, pseq in enumerate(pats): | |
325 # fix-up regexes for multi-line searches | |
326 po = p = pseq[0] | |
327 # \s doesn't match \n | |
328 p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p) | |
329 # [^...] doesn't match newline | |
330 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p) | |
331 | |
332 #print po, '=>', p | |
333 pats[i] = (p,) + pseq[1:] | |
334 _preparepats() | |
335 | |
320 class norepeatlogger(object): | 336 class norepeatlogger(object): |
321 def __init__(self): | 337 def __init__(self): |
322 self._lastseen = None | 338 self._lastseen = None |
323 | 339 |
324 def log(self, fname, lineno, line, msg, blame): | 340 def log(self, fname, lineno, line, msg, blame): |
401 p, msg, ignore = pat | 417 p, msg, ignore = pat |
402 else: | 418 else: |
403 p, msg = pat | 419 p, msg = pat |
404 ignore = None | 420 ignore = None |
405 | 421 |
406 # fix-up regexes for multi-line searches | |
407 po = p | |
408 # \s doesn't match \n | |
409 p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p) | |
410 # [^...] doesn't match newline | |
411 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p) | |
412 | |
413 #print po, '=>', p | |
414 | |
415 pos = 0 | 422 pos = 0 |
416 n = 0 | 423 n = 0 |
417 for m in re.finditer(p, post, re.MULTILINE): | 424 for m in re.finditer(p, post, re.MULTILINE): |
418 if prelines is None: | 425 if prelines is None: |
419 prelines = pre.splitlines() | 426 prelines = pre.splitlines() |