diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2022-09-18 20:10:57 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-09-18 18:45:25 -0700 |
commit | f8a42ef0b3bf3665448491e3c8067df2e59b160f (patch) | |
tree | 1e813a22fb8abb88cebd64c5f7dd180f16dd1a03 /Meta | |
parent | 532786848b893fd4bcd6f34abedf002e808a5070 (diff) | |
download | serenity-f8a42ef0b3bf3665448491e3c8067df2e59b160f.zip |
Meta: Only check changed files in check-style.py during pre-commit
This speeds up the script from about 90ms down to about 10ms, for
reasonably common changesets.
80ms may not feel like much, but it adds up quickly, especially since
we run a dozen scripts during pre-commit.
Diffstat (limited to 'Meta')
-rwxr-xr-x | Meta/check-style.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/Meta/check-style.py b/Meta/check-style.py index 25b9d93165..5baf25a857 100755 --- a/Meta/check-style.py +++ b/Meta/check-style.py @@ -37,18 +37,33 @@ PRAGMA_ONCE_CHECK_EXCLUDES = { # We make sure that there's a blank line before and after pragma once GOOD_PRAGMA_ONCE_PATTERN = re.compile('(^|\\S\n\n)#pragma once(\n\n\\S.|$)') -GIT_LS_FILES = ['git', 'ls-files', '--', '*.cpp', '*.h', ':!:Base', ':!:Kernel/FileSystem/ext2_fs.h'] +def should_check_file(filename): + if not filename.endswith('.cpp') and not filename.endswith('.h'): + return False + if filename.startswith('Base/'): + return False + if filename == 'Kernel/FileSystem/ext2_fs.h': + return False + return True -def run(): - files = subprocess.run(GIT_LS_FILES, check=True, capture_output=True).stdout.decode().strip('\n').split('\n') - assert len(files) > 1000 +def find_files_here_or_argv(): + if len(sys.argv) > 1: + raw_list = sys.argv[1:] + else: + process = subprocess.run(["git", "ls-files"], check=True, capture_output=True) + raw_list = process.stdout.decode().strip('\n').split('\n') + + return filter(should_check_file, raw_list) + + +def run(): errors_license = [] errors_pragma_once_bad = [] errors_pragma_once_missing = [] - for filename in files: + for filename in find_files_here_or_argv(): with open(filename, "r") as f: file_content = f.read() if not any(filename.startswith(forbidden_prefix) for forbidden_prefix in LICENSE_HEADER_CHECK_EXCLUDES): |