Mercurial > public > mercurial-scm > hg
diff 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 |
line wrap: on
line diff
--- a/contrib/check-commit Tue Jan 12 08:50:15 2016 +0000 +++ b/contrib/check-commit Tue Jan 12 08:34:38 2016 +0000 @@ -48,28 +48,35 @@ def checkcommit(commit, node = None): exitcode = 0 printed = node is None + hits = [] for exp, msg in errors: m = re.search(exp, commit) if m: - pos = 0 end = m.end() trailing = re.search(r'(\\n)+$', exp) if trailing: end -= len(trailing.group()) / 2 - last = '' - for n, l in enumerate(commit.splitlines(True)): - pos += len(l) + hits.append((end, exp, msg)) + if hits: + hits.sort() + pos = 0 + last = '' + for n, l in enumerate(commit.splitlines(True)): + pos += len(l) + while len(hits): + end, exp, msg = hits[0] if pos < end: - last = nonempty(l, last) - else: - if not printed: - printed = True - print "node: %s" % node - print "%d: %s" % (n, msg) - print " %s" % nonempty(l, last)[:-1] - if "BYPASS" not in os.environ: - exitcode = 1 break + if not printed: + printed = True + print "node: %s" % node + print "%d: %s" % (n, msg) + print " %s" % nonempty(l, last)[:-1] + if "BYPASS" not in os.environ: + exitcode = 1 + del hits[0] + last = nonempty(l, last) + return exitcode def readcommit(node):