[PATCH 3 of 4] check-commit: support nodes as arguments

timeless timeless at mozdev.org
Thu Jan 7 16:13:19 CST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1452130139 0
#      Thu Jan 07 01:28:59 2016 +0000
# Node ID 666391b22d67439f2dee4761fa42775fc3c4e2ef
# Parent  409a03fdf519243fe530f52a68f7804977dcd0e9
check-commit: support nodes as arguments

diff --git a/contrib/check-commit b/contrib/check-commit
--- a/contrib/check-commit
+++ b/contrib/check-commit
@@ -33,8 +33,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:
@@ -42,6 +43,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:
@@ -53,12 +57,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)


More information about the Mercurial-devel mailing list