Patchwork [3,of,5,v2] check-commit: support REVs as commandline arguments

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 12, 2016, 8:56 a.m.
Message ID <0c92ea1a5f27ee095e09.1452588995@waste.org>
Download mbox | patch
Permalink /patch/12690/
State Accepted
Commit 2af351bd289c9b2fdf2d852715ab4ed4213e900b
Headers show

Comments

timeless@mozdev.org - Jan. 12, 2016, 8:56 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1452130139 0
#      Thu Jan 07 01:28:59 2016 +0000
# Node ID 0c92ea1a5f27ee095e09e52321d3cef9269bd220
# Parent  a5652300012404f634f56b38df51dc5218f571c0
check-commit: support REVs as commandline arguments

usage:
* HG_NODE=REV check-commit
* hg export REV | check-commit
* check-commit REV ...

Patch

diff --git a/contrib/check-commit b/contrib/check-commit
--- a/contrib/check-commit
+++ b/contrib/check-commit
@@ -35,8 +35,9 @@ 
     (r"^\+[ \t]+def [a-z]+_[a-z]", "adds a function with foo_bar naming"),
 ]
 
-def checkcommit(commit):
+def checkcommit(commit, node = None):
     exitcode = 0
+    printed = node is None
     for exp, msg in errors:
         m = re.search(exp, commit, re.MULTILINE)
         if m:
@@ -44,6 +45,9 @@ 
             for n, l in enumerate(commit.splitlines(True)):
                 pos += len(l)
                 if pos >= m.end():
+                    if not printed:
+                        printed = True
+                        print "node: %s" % node
                     print "%d: %s" % (n, msg)
                     print " %s" % l[:-1]
                     if "BYPASS" not in os.environ:
@@ -55,12 +59,16 @@ 
     return os.popen("hg export %s" % node).read()
 
 if __name__ == "__main__":
+    exitcode = 0
     node = os.environ.get("HG_NODE")
 
     if node:
         commit = readcommit(node)
+        exitcode = checkcommit(commit)
+    elif sys.argv[1:]:
+        for node in sys.argv[1:]:
+            exitcode |= checkcommit(readcommit(node), node)
     else:
         commit = sys.stdin.read()
-
-    exitcode = checkcommit(commit)
+        exitcode = checkcommit(commit)
     sys.exit(exitcode)