diff --git a/contrib/check-commit b/contrib/check-commit --- a/contrib/check-commit +++ b/contrib/check-commit @@ -48,28 +48,35 @@ def nonempty(first, second): 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): diff --git a/tests/test-contrib-check-commit.t b/tests/test-contrib-check-commit.t --- a/tests/test-contrib-check-commit.t +++ b/tests/test-contrib-check-commit.t @@ -55,15 +55,15 @@ A patch with lots of errors: > if opts.get('all'): > EOF $ cat patch-with-long-header.diff | $TESTDIR/../contrib/check-commit - 7: (BC) needs to be uppercase + 1: username is not an email address + # User timeless + 7: summary keyword should be most user-relevant one-word command or topic transplant/foo: this summary is way too long use Oxford comma (bc) (bug123) (issue 244) - 7: no space allowed between issue and number + 7: (BC) needs to be uppercase transplant/foo: this summary is way too long use Oxford comma (bc) (bug123) (issue 244) 7: use (issueDDDD) instead of bug transplant/foo: this summary is way too long use Oxford comma (bc) (bug123) (issue 244) - 1: username is not an email address - # User timeless - 7: summary keyword should be most user-relevant one-word command or topic + 7: no space allowed between issue and number transplant/foo: this summary is way too long use Oxford comma (bc) (bug123) (issue 244) 7: summary line too long (limit is 78) transplant/foo: this summary is way too long use Oxford comma (bc) (bug123) (issue 244) @@ -96,16 +96,16 @@ A patch with other errors: $ cat patch-with-long-header.diff | $TESTDIR/../contrib/check-commit 1: username is not an email address # User timeless - 7: summary line doesn't start with 'topic: ' + 7: don't capitalize summary lines This has no topic and ends with a period. - 7: don't capitalize summary lines + 7: summary line doesn't start with 'topic: ' This has no topic and ends with a period. 7: don't add trailing period on summary line This has no topic and ends with a period. - 19: adds double empty line - + 15: adds double empty line + 16: adds a function with foo_bar naming + def blah_blah(x): + 19: adds double empty line + + [1]