From 05b60f40acc709b83599dc0ad31d1b8c2c4f9699 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 27 Jul 2023 14:22:34 +0100 Subject: [PATCH 1/4] Make code_style.py -s more precise Signed-off-by: Dave Rodgman --- scripts/code_style.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 7de93b085e..89263cec06 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -81,11 +81,15 @@ def get_src_files(since: Optional[str]) -> List[str]: universal_newlines=True) src_files = output.split() if since: - output = subprocess.check_output(["git", "diff", "--name-only", - since, "--"] + - src_files, - universal_newlines=True) - src_files = output.split() + # get all files changed in commits since the starting point + cmd = ["git", "log", since + "..HEAD", "--name-only", "--pretty=", "--" ] + src_files + output = subprocess.check_output(cmd, universal_newlines=True) + committed_changed_files = output.split() + # and also get all files with uncommitted changes + cmd = ["git", "diff", "--name-only", "--" ] + src_files + output = subprocess.check_output(cmd, universal_newlines=True) + uncommitted_changed_files = output.split() + src_files = set(committed_changed_files + uncommitted_changed_files) generated_files = list_generated_files() # Don't correct style for third-party files (and, for simplicity, From eaf2761ae125a5e7d5dacc71691894b002063d74 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 27 Jul 2023 14:22:55 +0100 Subject: [PATCH 2/4] Make code_style.py -s default to -s=development Signed-off-by: Dave Rodgman --- scripts/code_style.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 89263cec06..664222df5a 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -193,9 +193,10 @@ def main() -> int: parser.add_argument('-f', '--fix', action='store_true', help=('modify source files to fix the code style ' '(default: print diff, do not modify files)')) - parser.add_argument('-s', '--since', metavar='COMMIT', + parser.add_argument('-s', '--since', metavar='COMMIT', const='development', nargs='?', help=('only check files modified since the specified commit' - ' (e.g. --since=HEAD~3 or --since=development)')) + ' (e.g. --since=HEAD~3 or --since=development). If no' + ' commit is specified, default to development.')) # --subset is almost useless: it only matters if there are no files # ('code_style.py' without arguments checks all files known to Git, # 'code_style.py --subset' does nothing). In particular, From 82d174a6a80e160a7375385c3c1da5f9488a6d06 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 27 Jul 2023 18:50:50 +0100 Subject: [PATCH 3/4] pylint tidy-up Signed-off-by: Dave Rodgman --- scripts/code_style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 664222df5a..d6e56b29d3 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -82,14 +82,14 @@ def get_src_files(since: Optional[str]) -> List[str]: src_files = output.split() if since: # get all files changed in commits since the starting point - cmd = ["git", "log", since + "..HEAD", "--name-only", "--pretty=", "--" ] + src_files + cmd = ["git", "log", since + "..HEAD", "--name-only", "--pretty=", "--"] + src_files output = subprocess.check_output(cmd, universal_newlines=True) committed_changed_files = output.split() # and also get all files with uncommitted changes cmd = ["git", "diff", "--name-only", "--" ] + src_files output = subprocess.check_output(cmd, universal_newlines=True) uncommitted_changed_files = output.split() - src_files = set(committed_changed_files + uncommitted_changed_files) + src_files = list(set(committed_changed_files + uncommitted_changed_files)) generated_files = list_generated_files() # Don't correct style for third-party files (and, for simplicity, From fccc5f8b9d74efd600d0a51cb5fc673b83e0ac7c Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 27 Jul 2023 20:00:41 +0100 Subject: [PATCH 4/4] whitespace fix Signed-off-by: Dave Rodgman --- scripts/code_style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index d6e56b29d3..ddd0a9800b 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -86,7 +86,7 @@ def get_src_files(since: Optional[str]) -> List[str]: output = subprocess.check_output(cmd, universal_newlines=True) committed_changed_files = output.split() # and also get all files with uncommitted changes - cmd = ["git", "diff", "--name-only", "--" ] + src_files + cmd = ["git", "diff", "--name-only", "--"] + src_files output = subprocess.check_output(cmd, universal_newlines=True) uncommitted_changed_files = output.split() src_files = list(set(committed_changed_files + uncommitted_changed_files))