[PATCH 5 of 5 v2] check-commit: sort errors by line number

timeless timeless at mozdev.org
Tue Jan 12 02:56:37 CST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1452587678 0
#      Tue Jan 12 08:34:38 2016 +0000
# Node ID 4afc76115625c832e62aea33341bffeb83c566ab
# Parent  cc73958b28c58766d93a6b94d4af52bb2bf14aa9
check-commit: sort errors by line number

diff --git a/contrib/check-commit b/contrib/check-commit
--- a/contrib/check-commit
+++ b/contrib/check-commit
@@ -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):
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 @@
   >          if opts.get('all'):
   > EOF
   $ cat patch-with-long-header.diff | $TESTDIR/../contrib/check-commit
+  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: (BC) needs to be uppercase
    transplant/foo: this summary is way too long use Oxford comma (bc) (bug123) (issue 244)
-  7: no space allowed between issue and number
-   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: don't capitalize summary lines
+   This has no topic and ends with a period.
   7: summary line doesn't start with 'topic: '
    This has no topic and ends with a period.
-  7: don't capitalize summary lines
-   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]


More information about the Mercurial-devel mailing list