changeset 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 432242f41d9f
files contrib/check-commit tests/test-contrib-check-commit.t
diffstat 2 files changed, 29 insertions(+), 22 deletions(-) [+]
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):
--- a/tests/test-contrib-check-commit.t	Tue Jan 12 08:50:15 2016 +0000
+++ b/tests/test-contrib-check-commit.t	Tue Jan 12 08:34:38 2016 +0000
@@ -55,15 +55,15 @@
   >          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 @@
   $ 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]