[Replicant] [libsamsung-ipc][PATCH 03/53] Add a tool to help check the conversion to Linux code style

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Thu Jun 11 10:57:05 UTC 2020


When sending a patch for Linux, and running checkpatch.pl,
you typically only need to check the patch with it.

However since we're doing an initial conversion to the
Linux code style, we also need to check all the content of
the files as well, as otherwise the parts that are not
being touched by the patches won't be checked at all.

We also need to get it right, as otherwise running
checkpatch.pl on subsequent patches could trigger some
errors that would not come from the patches being checked,
but that would instead come from previous code style
errors, that were left unfixed.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
 scripts/check_code_style_conversion.py | 83 ++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100755 scripts/check_code_style_conversion.py

diff --git a/scripts/check_code_style_conversion.py b/scripts/check_code_style_conversion.py
new file mode 100755
index 0000000..015796a
--- /dev/null
+++ b/scripts/check_code_style_conversion.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# This is a script that helps checking the initial patches that converted
+# libsamsung-ipc to the kernel code style.
+#
+# As there is a massive amount of files to convert, and that the number of
+# patches is also big, this script can hopefully make testing and reviewing
+# easier.
+#
+# Copyright (C) 2020 Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+import os
+import re
+import sh
+import sys
+
+def usage(progname):
+    print("{} <revision_range>".format(progname))
+    sys.exit(1)
+
+def run(*args):
+    # print(*args)
+    return sh.sh("-c", " ".join(args))
+
+def git(*args):
+    return sh.git("--no-pager", *args)
+
+def git_log_oneline(revision_range, *args):
+    return git("show",
+               "--oneline",
+               "-s",
+               "--no-decorate",
+               '--color=never',
+               revision_range,
+               *args).split(os.linesep)[:-1]
+
+def git_get_diffed_files(commit1, commit2):
+    return git("diff", "--name-only", commit1, commit2).split(os.linesep)[:-1]
+
+def git_get_commit_list(revision_range):
+    return git_log_oneline(revision_range, '--reverse', '--format=%h')
+
+def checkpatch(revision_range):
+    for commit in git_get_commit_list(revision_range):
+        print("Checking {}".format(git_log_oneline(commit)[0]))
+
+        # Check the commit
+        try:
+            diff = run("scripts" + os.sep + "checkpatch.pl", "-g", commit)
+            print("  [  OK  ] Commit")
+        except:
+            print("  [  !!  ] Commit")
+
+        # Check the files of the commit
+        modified_files = git_get_diffed_files(commit, commit + "~1")
+        for modified_file in modified_files:
+            try:
+                file_report = run("scripts" + os.sep + "checkpatch.pl",
+                                  "-f", modified_file)
+                print("  [  OK  ] {}".format(modified_file))
+            except:
+                print("  [  !!  ] {}".format(modified_file))
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        usage(sys.argv[0])
+
+    revision_range = sys.argv[1]
+    checkpatch(revision_range)
-- 
2.27.0



More information about the Replicant mailing list