mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 13:58:14 +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 email
|
||||||
import getopt
|
import getopt
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -387,21 +388,23 @@ def ovs_checkpatch_parse(text, filename):
|
|||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print("Open vSwitch checkpatch.py")
|
print("""\
|
||||||
print("Checks a patch for trivial mistakes.")
|
Open vSwitch checkpatch.py
|
||||||
print("usage:")
|
Checks a patch for trivial mistakes.
|
||||||
print("%s [options] [patch file]" % sys.argv[0])
|
usage:
|
||||||
print("options:")
|
%s [options] [PATCH | -f SOURCE | -1 | -2 | ...]
|
||||||
print("-h|--help\t\t\t\tThis help message")
|
|
||||||
print("-b|--skip-block-whitespace\t"
|
Input options:
|
||||||
"Skips the if/while/for whitespace tests")
|
-f|--check-file Arguments are source files, not patches.
|
||||||
print("-f|--check-file\t\t\tCheck a file instead of a patchfile.")
|
-1, -2, ... Check recent commits in this repo.
|
||||||
print("-l|--skip-leading-whitespace\t"
|
|
||||||
"Skips the leading whitespace test")
|
Check options:
|
||||||
print("-s|--skip-signoff-lines\t"
|
-h|--help This help message
|
||||||
"Do not emit an error if no Signed-off-by line is present")
|
-b|--skip-block-whitespace Skips the if/while/for whitespace tests
|
||||||
print("-t|--skip-trailing-whitespace\t"
|
-l|--skip-leading-whitespace Skips the leading whitespace test
|
||||||
"Skips the trailing 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):
|
def ovs_checkpatch_file(filename):
|
||||||
@@ -424,9 +427,26 @@ def ovs_checkpatch_file(filename):
|
|||||||
return result
|
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__':
|
if __name__ == '__main__':
|
||||||
try:
|
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",
|
["check-file",
|
||||||
"help",
|
"help",
|
||||||
"skip-block-whitespace",
|
"skip-block-whitespace",
|
||||||
@@ -458,6 +478,19 @@ if __name__ == '__main__':
|
|||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
colors = True
|
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:
|
try:
|
||||||
filename = args[0]
|
filename = args[0]
|
||||||
except:
|
except:
|
||||||
|
Reference in New Issue
Block a user