Mercurial > hg
comparison contrib/check-commit @ 27783:1d095371de47
check-commit: sort errors by line number
author | timeless <timeless@mozdev.org> |
---|---|
date | Tue, 12 Jan 2016 08:34:38 +0000 |
parents | 7291c8165e33 |
children | 897b2fcf079f |
comparison
equal
deleted
inserted
replaced
27782:7291c8165e33 | 27783:1d095371de47 |
---|---|
46 return second | 46 return second |
47 | 47 |
48 def checkcommit(commit, node = None): | 48 def checkcommit(commit, node = None): |
49 exitcode = 0 | 49 exitcode = 0 |
50 printed = node is None | 50 printed = node is None |
51 hits = [] | |
51 for exp, msg in errors: | 52 for exp, msg in errors: |
52 m = re.search(exp, commit) | 53 m = re.search(exp, commit) |
53 if m: | 54 if m: |
54 pos = 0 | |
55 end = m.end() | 55 end = m.end() |
56 trailing = re.search(r'(\\n)+$', exp) | 56 trailing = re.search(r'(\\n)+$', exp) |
57 if trailing: | 57 if trailing: |
58 end -= len(trailing.group()) / 2 | 58 end -= len(trailing.group()) / 2 |
59 last = '' | 59 hits.append((end, exp, msg)) |
60 for n, l in enumerate(commit.splitlines(True)): | 60 if hits: |
61 pos += len(l) | 61 hits.sort() |
62 pos = 0 | |
63 last = '' | |
64 for n, l in enumerate(commit.splitlines(True)): | |
65 pos += len(l) | |
66 while len(hits): | |
67 end, exp, msg = hits[0] | |
62 if pos < end: | 68 if pos < end: |
63 last = nonempty(l, last) | |
64 else: | |
65 if not printed: | |
66 printed = True | |
67 print "node: %s" % node | |
68 print "%d: %s" % (n, msg) | |
69 print " %s" % nonempty(l, last)[:-1] | |
70 if "BYPASS" not in os.environ: | |
71 exitcode = 1 | |
72 break | 69 break |
70 if not printed: | |
71 printed = True | |
72 print "node: %s" % node | |
73 print "%d: %s" % (n, msg) | |
74 print " %s" % nonempty(l, last)[:-1] | |
75 if "BYPASS" not in os.environ: | |
76 exitcode = 1 | |
77 del hits[0] | |
78 last = nonempty(l, last) | |
79 | |
73 return exitcode | 80 return exitcode |
74 | 81 |
75 def readcommit(node): | 82 def readcommit(node): |
76 return os.popen("hg export %s" % node).read() | 83 return os.popen("hg export %s" % node).read() |
77 | 84 |