annotate tests/check-perf-code.py @ 37048:fc5e261915b9

wireproto: require POST for all HTTPv2 requests Wire protocol version 1 transfers argument data via request headers by default. This has historically caused problems because servers institute limits on the length of individual HTTP headers as well as the total size of all request headers. Mercurial servers can advertise the maximum length of an individual header. But there's no guarantee any intermediate HTTP agents will accept headers up to that length. In the existing wire protocol, server operators typically also key off the HTTP request method to implement authentication. For example, GET requests translate to read-only requests and can be allowed. But read-write commands must use POST and require authentication. This has typically worked because the only wire protocol commands that use POST modify the repo (e.g. the "unbundle" command). There is an experimental feature to enable clients to transmit argument data via POST request bodies. This is technically a better and more robust solution. But we can't enable it by default because of servers assuming POST means write access. In version 2 of the wire protocol, the permissions of a request are encoded in the URL. And with it being a new protocol in a new URL space, we're not constrained by backwards compatibility requirements. This commit adopts the technically superior mechanism of using HTTP request bodies to send argument data by requiring POST for all commands. Strictly speaking, it may be possible to send request bodies on GET requests. But my experience is that not all HTTP stacks support this. POST pretty much always works. Using POST for read-only operations does sacrifice some RESTful design purity. But this API cares about practicality, not about being in Roy T. Fielding's REST ivory tower. There's a chance we may relax this restriction in the future. But for now, I want to see how far we can get with a POST only API. Differential Revision: https://phab.mercurial-scm.org/D2837
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 13 Mar 2018 11:57:43 -0700
parents bd872f64a8ba
children eb8a8af4cbd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29570
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
1 #!/usr/bin/env python
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
2 #
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
3 # check-perf-code - (historical) portability checker for contrib/perf.py
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
4
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
5 from __future__ import absolute_import
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
6
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
7 import os
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
8 import sys
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
9
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
10 # write static check patterns here
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
11 perfpypats = [
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
12 [
30144
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29571
diff changeset
13 (r'(branchmap|repoview)\.subsettable',
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29571
diff changeset
14 "use getbranchmapsubsettable() for early Mercurial"),
30146
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
15 (r'\.(vfs|svfs|opener|sopener)',
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
16 "use getvfs()/getsvfs() for early Mercurial"),
30149
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
17 (r'ui\.configint',
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
18 "use getint() instead of ui.configint() for early Mercurial"),
29570
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
19 ],
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
20 # warnings
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
21 [
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
22 ]
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
23 ]
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
24
29571
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
25 def modulewhitelist(names):
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
26 replacement = [('.py', ''), ('.c', ''), # trim suffix
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
27 ('mercurial%s' % (os.sep), ''), # trim "mercurial/" path
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
28 ]
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 30149
diff changeset
29 ignored = {'__init__'}
29571
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
30 modules = {}
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
31
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
32 # convert from file name to module name, and count # of appearances
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
33 for name in names:
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
34 name = name.strip()
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
35 for old, new in replacement:
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
36 name = name.replace(old, new)
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
37 if name not in ignored:
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
38 modules[name] = modules.get(name, 0) + 1
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
39
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
40 # list up module names, which appear multiple times
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
41 whitelist = []
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
42 for name, count in modules.items():
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
43 if count > 1:
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
44 whitelist.append(name)
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
45
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
46 return whitelist
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
47
29570
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
48 if __name__ == "__main__":
29571
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
49 # in this case, it is assumed that result of "hg files" at
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
50 # multiple revisions is given via stdin
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
51 whitelist = modulewhitelist(sys.stdin)
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
52 assert whitelist, "module whitelist is empty"
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
53
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
54 # build up module whitelist check from file names given at runtime
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
55 perfpypats[0].append(
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
56 # this matching pattern assumes importing modules from
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
57 # "mercurial" package in the current style below, for simplicity
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
58 #
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
59 # from mercurial import (
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
60 # foo,
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
61 # bar,
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
62 # baz
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
63 # )
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
64 ((r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])'
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
65 % ',| *'.join(whitelist)),
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
66 "import newer module separately in try clause for early Mercurial"
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
67 ))
d1a7d9c279bb tests: check importing modules in perf.py for historical portability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29570
diff changeset
68
29570
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
69 # import contrib/check-code.py as checkcode
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
70 assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script"
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
71 contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib')
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
72 sys.path.insert(0, contribpath)
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
73 checkcode = __import__('check-code')
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
74
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
75 # register perf.py specific entry with "checks" in check-code.py
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
76 checkcode.checks.append(('perf.py', r'contrib/perf.py$', '',
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
77 checkcode.pyfilters, perfpypats))
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
78
cbd240188e4e tests: introduce check-perf-code.py to add extra checks on perf.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
79 sys.exit(checkcode.main())