mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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.
This commit is contained in:
parent
532786848b
commit
f8a42ef0b3
Notes:
sideshowbarker
2024-07-17 06:51:00 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/f8a42ef0b3 Pull-request: https://github.com/SerenityOS/serenity/pull/15281 Reviewed-by: https://github.com/bgianfo ✅
1 changed files with 20 additions and 5 deletions
|
@ -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 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():
|
||||
files = subprocess.run(GIT_LS_FILES, check=True, capture_output=True).stdout.decode().strip('\n').split('\n')
|
||||
assert len(files) > 1000
|
||||
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue