[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openvswitch-dev
Subject:    [ovs-dev] [PATCH v4] checkpatch.py: A simple script for finding patch issues
From:       blp () ovn ! org (Ben Pfaff)
Date:       2016-03-31 15:29:42
Message-ID: 20160331152942.GY28186 () ovn ! org
[Download RAW message or body]

On Thu, Mar 31, 2016 at 10:45:35AM -0400, Aaron Conole wrote:
> Most projects have a checkpatch facility, which can be used as a pre-commit
> sanity check. This introduces such a mechanism to the Open vSwitch project
> to catch some of the more silly formatting mistakes which can occur. It is
> not meant to replace good code review practices, but it can help eliminate
> the silly code review issues which get added.
> 
> Suggested-by: Mauricio Vásquez <mauricio.vasquezbernal at studenti.polito.it>
> Signed-off-by: Aaron Conole <aconole at redhat.com>

Thanks.

When I ran this without arguments, I got a hang.  It was waiting for a
patch, of course.  That's not entirely friendly, so I changed it to give
the usage message when run without arguments with stdin as a terminal.

I also changed the threshold to complain about long lines from 80
characters to 79, because that's what CodingStyle.md says.

Then I applied this to master.  Thank you!

Here's what I squashed in:

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index de6a5a7..5301c6b 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -154,9 +154,9 @@ def ovs_checkpatch_parse(text):
             if trailing_whitespace_or_crlf(line[1:]):
                 print_line = True
                 print_warning("Line has trailing whitespace", lineno)
-            if len(line[1:]) > 80:
+            if len(line[1:]) > 79:
                 print_line = True
-                print_warning("Line is greater than 80-characters long",
+                print_warning("Line is greater than 79-characters long",
                               lineno)
             if not if_and_for_whitespace_checks(line[1:]):
                 print_line = True
@@ -169,6 +169,22 @@ def ovs_checkpatch_parse(text):
     return 0
 
 
+def usage():
+    print("Open vSwitch checkpatch.py")
+    print("Checks a patch for trivial mistakes.")
+    print("usage:")
+    print("%s [options] [patch file]" % sys.argv[0])
+    print("options:")
+    print("-h|--help\t\t\t\tThis help message")
+    print("-b|--skip-block-whitespace\t"
+          "Skips the if/while/for whitespace tests")
+    print("-l|--skip-leading-whitespace\t"
+          "Skips the leading whitespace test")
+    print("-s|--skip-signoff-lines\t"
+          "Do not emit an error if no Signed-off-by line is present")
+    print("-t|--skip-trailing-whitespace\t"
+          "Skips the trailing whitespace test")
+
 def ovs_checkpatch_file(filename):
     try:
         mail = email.message_from_file(open(filename, 'r'))
@@ -195,20 +211,7 @@ if __name__ == '__main__':
 
     for o, a in optlist:
         if o in ("-h", "--help"):
-            print("Open vSwitch checkpatch.py")
-            print("Checks a patch for trivial mistakes.")
-            print("usage:")
-            print("%s [options] [patch file]" % sys.argv[0])
-            print("options:")
-            print("-h|--help\t\t\t\tThis help message")
-            print("-b|--skip-block-whitespace\t"
-                  "Skips the if/while/for whitespace tests")
-            print("-l|--skip-leading-whitespace\t"
-                  "Skips the leading whitespace test")
-            print("-s|--skip-signoff-lines\t"
-                  "Do not emit an error if no Signed-off-by line is present")
-            print("-t|--skip-trailing-whitespace\t"
-                  "Skips the trailing whitespace test")
+            usage()
             sys.exit(0)
         elif o in ("-b", "--skip-block-whitespace"):
             skip_block_whitespace_check = True
@@ -224,5 +227,8 @@ if __name__ == '__main__':
     try:
         filename = args[0]
     except:
+        if sys.stdin.isatty():
+            usage()
+            sys.exit(-1)
         sys.exit(ovs_checkpatch_parse(sys.stdin.read()))
     sys.exit(ovs_checkpatch_file(filename))

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic