mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +00:00
checkpatch: Support checking recent commits in the current repo.
Requested-by: Miguel Angel Ajo <majopela@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -16,6 +16,7 @@ from __future__ import print_function
|
||||
|
||||
import email
|
||||
import getopt
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
@@ -387,21 +388,23 @@ def ovs_checkpatch_parse(text, filename):
|
||||
|
||||
|
||||
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("-f|--check-file\t\t\tCheck a file instead of a patchfile.")
|
||||
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")
|
||||
print("""\
|
||||
Open vSwitch checkpatch.py
|
||||
Checks a patch for trivial mistakes.
|
||||
usage:
|
||||
%s [options] [PATCH | -f SOURCE | -1 | -2 | ...]
|
||||
|
||||
Input options:
|
||||
-f|--check-file Arguments are source files, not patches.
|
||||
-1, -2, ... Check recent commits in this repo.
|
||||
|
||||
Check options:
|
||||
-h|--help This help message
|
||||
-b|--skip-block-whitespace Skips the if/while/for whitespace tests
|
||||
-l|--skip-leading-whitespace Skips the leading whitespace test
|
||||
-s|--skip-signoff-lines Tolerate missing Signed-off-by line
|
||||
-t|--skip-trailing-whitespace Skips the trailing whitespace test"""
|
||||
% sys.argv[0])
|
||||
|
||||
|
||||
def ovs_checkpatch_file(filename):
|
||||
@@ -424,9 +427,26 @@ def ovs_checkpatch_file(filename):
|
||||
return result
|
||||
|
||||
|
||||
def partition(pred, iterable):
|
||||
"""Returns [[trues], [falses]], where [trues] is the items in
|
||||
'iterable' that satisfy 'pred' and [falses] is all the rest."""
|
||||
trues = []
|
||||
falses = []
|
||||
for item in iterable:
|
||||
if pred(item):
|
||||
trues.append(item)
|
||||
else:
|
||||
falses.append(item)
|
||||
return trues, falses
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
optlist, args = getopt.getopt(sys.argv[1:], 'bhlstf',
|
||||
numeric_options, args = partition(lambda s: re.match('-[0-9]+$', s),
|
||||
sys.argv[1:])
|
||||
n_patches = int(numeric_options[-1][1:]) if numeric_options else 0
|
||||
|
||||
optlist, args = getopt.getopt(args, 'bhlstf',
|
||||
["check-file",
|
||||
"help",
|
||||
"skip-block-whitespace",
|
||||
@@ -458,6 +478,19 @@ if __name__ == '__main__':
|
||||
if sys.stdout.isatty():
|
||||
colors = True
|
||||
|
||||
if n_patches:
|
||||
status = 0
|
||||
for i in range(n_patches, 0, -1):
|
||||
revision = 'HEAD~%d' % i
|
||||
f = os.popen('git format-patch -1 --stdout %s' % revision, 'r')
|
||||
patch = f.read()
|
||||
f.close()
|
||||
|
||||
print('== Checking %s ==' % revision)
|
||||
if ovs_checkpatch_parse(patch, revision):
|
||||
status = -1
|
||||
sys.exit(status)
|
||||
|
||||
try:
|
||||
filename = args[0]
|
||||
except:
|
||||
|
Reference in New Issue
Block a user