summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-12-24 12:34:55 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-12-29 16:45:35 +0200
commitbf7981f2bc1bf7c91b916554981c8fb4d5aa9877 (patch)
treea7cbbae7f69999fb909f430428960dee80ee0df5
parentba3278a749c0e003c708e7ffc25a3af040c26690 (diff)
utils: checkstyle.py: Add commit checkers
Add a new category of checkers that operate on a whole commit. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
-rwxr-xr-xutils/checkstyle.py42
1 files changed, 35 insertions, 7 deletions
diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 9c2a1837..c0a6b7ab 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -297,6 +297,30 @@ class ClassRegistry(type):
# ------------------------------------------------------------------------------
+# Commit Checkers
+#
+
+class CommitChecker(metaclass=ClassRegistry):
+ subclasses = []
+
+ def __init__(self):
+ pass
+
+ #
+ # Class methods
+ #
+ @classmethod
+ def checkers(cls):
+ for checker in cls.subclasses:
+ yield checker
+
+
+class CommitIssue(object):
+ def __init__(self, msg):
+ self.msg = msg
+
+
+# ------------------------------------------------------------------------------
# Style Checkers
#
@@ -721,25 +745,29 @@ def check_style(top_level, commit):
print(commit.title)
print(separator)
+ issues = 0
+
+ # Apply the commit checkers first.
+ for checker in CommitChecker.checkers():
+ for issue in checker.check(commit, top_level):
+ print('%s%s%s' % (Colours.fg(Colours.Yellow), issue.msg, Colours.reset()))
+ issues += 1
+
# Filter out files we have no checker for.
patterns = set()
patterns.update(StyleChecker.all_patterns())
patterns.update(Formatter.all_patterns())
files = [f for f in commit.files() if len([p for p in patterns if fnmatch.fnmatch(os.path.basename(f), p)])]
- if len(files) == 0:
- print("Commit doesn't touch source files, skipping")
- return 0
- issues = 0
for f in files:
issues += check_file(top_level, commit, f)
if issues == 0:
- print("No style issue detected")
+ print("No issue detected")
else:
print('---')
- print("%u potential style %s detected, please review" % \
- (issues, 'issue' if issues == 1 else 'issues'))
+ print("%u potential %s detected, please review" %
+ (issues, 'issue' if issues == 1 else 'issues'))
return issues