comparison contrib/check-code.py @ 20012:a1d88278beff

merge with stable
author Matt Mackall <mpm@selenic.com>
date Sat, 16 Nov 2013 12:44:28 -0500
parents e1317d3e59e1 22154ec6fb8b
children 38acecdd016c
comparison
equal deleted inserted replaced
20010:34d720b3b33e 20012:a1d88278beff
24 except re2.error: 24 except re2.error:
25 pass 25 pass
26 return re.compile(pat) 26 return re.compile(pat)
27 27
28 def repquote(m): 28 def repquote(m):
29 t = re.sub(r"\w", "x", m.group('text')) 29 fromc = '.:'
30 t = re.sub(r"[^\s\nx]", "o", t) 30 tochr = 'pq'
31 def encodechr(i):
32 if i > 255:
33 return 'u'
34 c = chr(i)
35 if c in ' \n':
36 return c
37 if c.isalpha():
38 return 'x'
39 if c.isdigit():
40 return 'n'
41 try:
42 return tochr[fromc.find(c)]
43 except (ValueError, IndexError):
44 return 'o'
45 t = m.group('text')
46 tt = ''.join(encodechr(i) for i in xrange(256))
47 t = t.translate(tt)
31 return m.group('quote') + t + m.group('quote') 48 return m.group('quote') + t + m.group('quote')
32 49
33 def reppython(m): 50 def reppython(m):
34 comment = m.group('comment') 51 comment = m.group('comment')
35 if comment: 52 if comment:
261 "missing _() in ui message (use () to hide false-positives)"), 278 "missing _() in ui message (use () to hide false-positives)"),
262 (r'release\(.*wlock, .*lock\)', "wrong lock release order"), 279 (r'release\(.*wlock, .*lock\)', "wrong lock release order"),
263 ], 280 ],
264 # warnings 281 # warnings
265 [ 282 [
283 (r'(^| )pp +xxxxqq[ \n][^\n]', "add two newlines after '.. note::'"),
266 ] 284 ]
267 ] 285 ]
268 286
269 pyfilters = [ 287 pyfilters = [
270 (r"""(?msx)(?P<comment>\#.*?$)| 288 (r"""(?msx)(?P<comment>\#.*?$)|
447 if len(pat) == 3: 465 if len(pat) == 3:
448 p, msg, ignore = pat 466 p, msg, ignore = pat
449 else: 467 else:
450 p, msg = pat 468 p, msg = pat
451 ignore = None 469 ignore = None
470 if i >= nerrs:
471 msg = "warning: " + msg
452 472
453 pos = 0 473 pos = 0
454 n = 0 474 n = 0
455 for m in p.finditer(post): 475 for m in p.finditer(post):
456 if prelines is None: 476 if prelines is None:
457 prelines = pre.splitlines() 477 prelines = pre.splitlines()
458 postlines = post.splitlines(True) 478 postlines = post.splitlines(True)
459 if i >= nerrs:
460 msg = "warning: " + msg
461 479
462 start = m.start() 480 start = m.start()
463 while n < len(postlines): 481 while n < len(postlines):
464 step = len(postlines[n]) 482 step = len(postlines[n])
465 if pos + step > start: 483 if pos + step > start:
482 blamecache = getblame(f) 500 blamecache = getblame(f)
483 if n < len(blamecache): 501 if n < len(blamecache):
484 bl, bu, br = blamecache[n] 502 bl, bu, br = blamecache[n]
485 if bl == l: 503 if bl == l:
486 bd = '%s@%s' % (bu, br) 504 bd = '%s@%s' % (bu, br)
505
487 errors.append((f, lineno and n + 1, l, msg, bd)) 506 errors.append((f, lineno and n + 1, l, msg, bd))
488 result = False 507 result = False
489 508
490 errors.sort() 509 errors.sort()
491 for e in errors: 510 for e in errors: