diff options
Diffstat (limited to 'scripts/contrib/patchreview.py')
-rwxr-xr-x | scripts/contrib/patchreview.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/scripts/contrib/patchreview.py b/scripts/contrib/patchreview.py index 36038d06d2..f95cadab0c 100755 --- a/scripts/contrib/patchreview.py +++ b/scripts/contrib/patchreview.py | |||
@@ -5,6 +5,15 @@ | |||
5 | # SPDX-License-Identifier: GPL-2.0-only | 5 | # SPDX-License-Identifier: GPL-2.0-only |
6 | # | 6 | # |
7 | 7 | ||
8 | import argparse | ||
9 | import collections | ||
10 | import json | ||
11 | import os | ||
12 | import os.path | ||
13 | import pathlib | ||
14 | import re | ||
15 | import subprocess | ||
16 | |||
8 | # TODO | 17 | # TODO |
9 | # - option to just list all broken files | 18 | # - option to just list all broken files |
10 | # - test suite | 19 | # - test suite |
@@ -35,14 +44,12 @@ def blame_patch(patch): | |||
35 | From a patch filename, return a list of "commit summary (author name <author | 44 | From a patch filename, return a list of "commit summary (author name <author |
36 | email>)" strings representing the history. | 45 | email>)" strings representing the history. |
37 | """ | 46 | """ |
38 | import subprocess | ||
39 | return subprocess.check_output(("git", "log", | 47 | return subprocess.check_output(("git", "log", |
40 | "--follow", "--find-renames", "--diff-filter=A", | 48 | "--follow", "--find-renames", "--diff-filter=A", |
41 | "--format=%s (%aN <%aE>)", | 49 | "--format=%s (%aN <%aE>)", |
42 | "--", patch)).decode("utf-8").splitlines() | 50 | "--", patch)).decode("utf-8").splitlines() |
43 | 51 | ||
44 | def patchreview(patches): | 52 | def patchreview(patches): |
45 | import re, os.path | ||
46 | 53 | ||
47 | # General pattern: start of line, optional whitespace, tag with optional | 54 | # General pattern: start of line, optional whitespace, tag with optional |
48 | # hyphen or spaces, maybe a colon, some whitespace, then the value, all case | 55 | # hyphen or spaces, maybe a colon, some whitespace, then the value, all case |
@@ -192,6 +199,7 @@ Patches in Pending state: %s""" % (total_patches, | |||
192 | def histogram(results): | 199 | def histogram(results): |
193 | from toolz import recipes, dicttoolz | 200 | from toolz import recipes, dicttoolz |
194 | import math | 201 | import math |
202 | |||
195 | counts = recipes.countby(lambda r: r.upstream_status, results.values()) | 203 | counts = recipes.countby(lambda r: r.upstream_status, results.values()) |
196 | bars = dicttoolz.valmap(lambda v: "#" * int(math.ceil(float(v) / len(results) * 100)), counts) | 204 | bars = dicttoolz.valmap(lambda v: "#" * int(math.ceil(float(v) / len(results) * 100)), counts) |
197 | for k in bars: | 205 | for k in bars: |
@@ -226,8 +234,6 @@ def count_recipes(layers): | |||
226 | return count | 234 | return count |
227 | 235 | ||
228 | if __name__ == "__main__": | 236 | if __name__ == "__main__": |
229 | import argparse, subprocess, os, pathlib | ||
230 | |||
231 | args = argparse.ArgumentParser(description="Patch Review Tool") | 237 | args = argparse.ArgumentParser(description="Patch Review Tool") |
232 | args.add_argument("-b", "--blame", action="store_true", help="show blame for malformed patches") | 238 | args.add_argument("-b", "--blame", action="store_true", help="show blame for malformed patches") |
233 | args.add_argument("-v", "--verbose", action="store_true", help="show per-patch results") | 239 | args.add_argument("-v", "--verbose", action="store_true", help="show per-patch results") |
@@ -243,7 +249,6 @@ if __name__ == "__main__": | |||
243 | analyse(results, want_blame=args.blame, verbose=args.verbose) | 249 | analyse(results, want_blame=args.blame, verbose=args.verbose) |
244 | 250 | ||
245 | if args.json: | 251 | if args.json: |
246 | import json, os.path, collections | ||
247 | if os.path.isfile(args.json): | 252 | if os.path.isfile(args.json): |
248 | data = json.load(open(args.json)) | 253 | data = json.load(open(args.json)) |
249 | else: | 254 | else: |