Show More
@@ -16,7 +16,50 b' perfpypats = [' | |||||
16 | ] |
|
16 | ] | |
17 | ] |
|
17 | ] | |
18 |
|
18 | |||
|
19 | def modulewhitelist(names): | |||
|
20 | replacement = [('.py', ''), ('.c', ''), # trim suffix | |||
|
21 | ('mercurial%s' % (os.sep), ''), # trim "mercurial/" path | |||
|
22 | ] | |||
|
23 | ignored = set(['__init__']) | |||
|
24 | modules = {} | |||
|
25 | ||||
|
26 | # convert from file name to module name, and count # of appearances | |||
|
27 | for name in names: | |||
|
28 | name = name.strip() | |||
|
29 | for old, new in replacement: | |||
|
30 | name = name.replace(old, new) | |||
|
31 | if name not in ignored: | |||
|
32 | modules[name] = modules.get(name, 0) + 1 | |||
|
33 | ||||
|
34 | # list up module names, which appear multiple times | |||
|
35 | whitelist = [] | |||
|
36 | for name, count in modules.items(): | |||
|
37 | if count > 1: | |||
|
38 | whitelist.append(name) | |||
|
39 | ||||
|
40 | return whitelist | |||
|
41 | ||||
19 | if __name__ == "__main__": |
|
42 | if __name__ == "__main__": | |
|
43 | # in this case, it is assumed that result of "hg files" at | |||
|
44 | # multiple revisions is given via stdin | |||
|
45 | whitelist = modulewhitelist(sys.stdin) | |||
|
46 | assert whitelist, "module whitelist is empty" | |||
|
47 | ||||
|
48 | # build up module whitelist check from file names given at runtime | |||
|
49 | perfpypats[0].append( | |||
|
50 | # this matching pattern assumes importing modules from | |||
|
51 | # "mercurial" package in the current style below, for simplicity | |||
|
52 | # | |||
|
53 | # from mercurial import ( | |||
|
54 | # foo, | |||
|
55 | # bar, | |||
|
56 | # baz | |||
|
57 | # ) | |||
|
58 | ((r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])' | |||
|
59 | % ',| *'.join(whitelist)), | |||
|
60 | "import newer module separately in try clause for early Mercurial" | |||
|
61 | )) | |||
|
62 | ||||
20 | # import contrib/check-code.py as checkcode |
|
63 | # import contrib/check-code.py as checkcode | |
21 | assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script" |
|
64 | assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script" | |
22 | contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib') |
|
65 | contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib') |
@@ -152,4 +152,6 b' Check perf.py for historical portability' | |||||
152 |
|
152 | |||
153 | $ cd "$TESTDIR/.." |
|
153 | $ cd "$TESTDIR/.." | |
154 |
|
154 | |||
155 | $ "$TESTDIR"/check-perf-code.py contrib/perf.py |
|
155 | $ (hg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py; | |
|
156 | > hg files -r tip glob:mercurial/*.c glob:mercurial/*.py) | | |||
|
157 | > "$TESTDIR"/check-perf-code.py contrib/perf.py |
General Comments 0
You need to be logged in to leave comments.
Login now