Mercurial > hg
annotate tests/test-parseindex2.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 | df448de7cf3b |
children | b4e42a9bd12e |
rev | line source |
---|---|
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
1 """This unit test primarily tests parsers.parse_index2(). |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
2 |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
3 It also checks certain aspects of the parsers module as a whole. |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
4 """ |
20166
7eda5bb9ec8f
parsers: clarify documentation of test-parseindex2.py
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20159
diff
changeset
|
5 |
28754
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
6 from __future__ import absolute_import, print_function |
28841
e155b8d5e3b7
tests: move stdlib imports before mercurial modules in test-parseindex2
Yuya Nishihara <yuya@tcha.org>
parents:
28754
diff
changeset
|
7 |
e155b8d5e3b7
tests: move stdlib imports before mercurial modules in test-parseindex2
Yuya Nishihara <yuya@tcha.org>
parents:
28754
diff
changeset
|
8 import struct |
e155b8d5e3b7
tests: move stdlib imports before mercurial modules in test-parseindex2
Yuya Nishihara <yuya@tcha.org>
parents:
28754
diff
changeset
|
9 import subprocess |
e155b8d5e3b7
tests: move stdlib imports before mercurial modules in test-parseindex2
Yuya Nishihara <yuya@tcha.org>
parents:
28754
diff
changeset
|
10 import sys |
e155b8d5e3b7
tests: move stdlib imports before mercurial modules in test-parseindex2
Yuya Nishihara <yuya@tcha.org>
parents:
28754
diff
changeset
|
11 |
28753
0c2295384eea
py3: use absolute_import in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
27637
diff
changeset
|
12 from mercurial.node import ( |
0c2295384eea
py3: use absolute_import in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
27637
diff
changeset
|
13 nullid, |
0c2295384eea
py3: use absolute_import in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
27637
diff
changeset
|
14 nullrev, |
0c2295384eea
py3: use absolute_import in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
27637
diff
changeset
|
15 ) |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28841
diff
changeset
|
16 from mercurial import ( |
32372
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
29205
diff
changeset
|
17 policy, |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28841
diff
changeset
|
18 ) |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
19 |
32372
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
29205
diff
changeset
|
20 parsers = policy.importmod(r'parsers') |
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
29205
diff
changeset
|
21 |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
22 # original python implementation |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
23 def gettype(q): |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
24 return int(q & 0xFFFF) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
25 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
26 def offset_type(offset, type): |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
27 return long(long(offset) << 16 | type) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
28 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
29 indexformatng = ">Qiiiiii20s12x" |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
30 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
31 def py_parseindex(data, inline) : |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
32 s = 64 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
33 cache = None |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
34 index = [] |
27637
b502138f5faa
cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents:
20742
diff
changeset
|
35 nodemap = {nullid: nullrev} |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
36 n = off = 0 |
13253 | 37 |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
38 l = len(data) - s |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
39 append = index.append |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
40 if inline: |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
41 cache = (0, data) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
42 while off <= l: |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
43 e = struct.unpack(indexformatng, data[off:off + s]) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
44 nodemap[e[7]] = n |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
45 append(e) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
46 n += 1 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
47 if e[1] < 0: |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
48 break |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
49 off += e[1] + s |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
50 else: |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
51 while off <= l: |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
52 e = struct.unpack(indexformatng, data[off:off + s]) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
53 nodemap[e[7]] = n |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
54 append(e) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
55 n += 1 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
56 off += s |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
57 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
58 e = list(index[0]) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
59 type = gettype(e[0]) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
60 e[0] = offset_type(0, type) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
61 index[0] = tuple(e) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
62 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
63 # add the magic null revision at -1 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
64 index.append((0, 0, 0, -1, -1, -1, -1, nullid)) |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
65 |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
13253
diff
changeset
|
66 return index, cache |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
67 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
68 data_inlined = '\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00\x01\x8c' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
69 '\x00\x00\x04\x07\x00\x00\x00\x00\x00\x00\x15\x15\xff\xff\xff' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
70 '\xff\xff\xff\xff\xff\xebG\x97\xb7\x1fB\x04\xcf\x13V\x81\tw\x1b' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
71 'w\xdduR\xda\xc6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
72 'x\x9c\x9d\x93?O\xc30\x10\xc5\xf7|\x8a\xdb\x9a\xa8m\x06\xd8*\x95' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
73 '\x81B\xa1\xa2\xa2R\xcb\x86Pd\x9a\x0b5$vd_\x04\xfd\xf6\x9c\xff@' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
74 '\x11!\x0b\xd9\xec\xf7\xbbw\xe7gG6\xad6\x04\xdaN\xc0\x92\xa0$)' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
75 '\xb1\x82\xa2\xd1%\x16\xa4\x8b7\xa9\xca\xd4-\xb2Y\x02\xfc\xc9' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
76 '\xcaS\xf9\xaeX\xed\xb6\xd77Q\x02\x83\xd4\x19\xf5--Y\xea\xe1W' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
77 '\xab\xed\x10\xceR\x0f_\xdf\xdf\r\xe1,\xf5\xf0\xcb\xf5 \xceR\x0f' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
78 '_\xdc\x0e\x0e\xc3R\x0f_\xae\x96\x9b!\x9e\xa5\x1e\xbf\xdb,\x06' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
79 '\xc7q\x9a/\x88\x82\xc3B\xea\xb5\xb4TJ\x93\xb6\x82\x0e\xe16\xe6' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
80 'KQ\xdb\xaf\xecG\xa3\xd1 \x01\xd3\x0b_^\xe8\xaa\xa0\xae\xad\xd1' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
81 '&\xbef\x1bz\x08\xb0|\xc9Xz\x06\xf6Z\x91\x90J\xaa\x17\x90\xaa' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
82 '\xd2\xa6\x11$5C\xcf\xba#\xa0\x03\x02*2\x92-\xfc\xb1\x94\xdf\xe2' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
83 '\xae\xb8\'m\x8ey0^\x85\xd3\x82\xb4\xf0`:\x9c\x00\x8a\xfd\x01' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
84 '\xb0\xc6\x86\x8b\xdd\xae\x80\xf3\xa9\x9fd\x16\n\x00R%\x1a\x06' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
85 '\xe9\xd8b\x98\x1d\xf4\xf3+\x9bf\x01\xd8p\x1b\xf3.\xed\x9f^g\xc3' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
86 '^\xd9W81T\xdb\xd5\x04sx|\xf2\xeb\xd6`%?x\xed"\x831\xbf\xf3\xdc' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
87 'b\xeb%gaY\xe1\xad\x9f\xb9f\'1w\xa9\xa5a\x83s\x82J\xb98\xbc4\x8b' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
88 '\x83\x00\x9f$z\xb8#\xa5\xb1\xdf\x98\xd9\xec\x1b\x89O\xe3Ts\x9a4' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
89 '\x17m\x8b\xfc\x8f\xa5\x95\x9a\xfc\xfa\xed,\xe5|\xa1\xfe\x15\xb9' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
90 '\xbc\xb2\x93\x1f\xf2\x95\xff\xdf,\x1a\xc5\xe7\x17*\x93Oz:>\x0e' |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
91 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
92 data_non_inlined = '\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01D\x19' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
93 '\x00\x07e\x12\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
94 '\xff\xff\xff\xff\xd1\xf4\xbb\xb0\xbe\xfc\x13\xbd\x8c\xd3\x9d' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
95 '\x0f\xcd\xd9;\x8c\x07\x8cJ/\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
96 '\x00\x00\x00\x00\x00\x00\x01D\x19\x00\x00\x00\x00\x00\xdf\x00' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
97 '\x00\x01q\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\xff' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
98 '\xff\xff\xff\xc1\x12\xb9\x04\x96\xa4Z1t\x91\xdfsJ\x90\xf0\x9bh' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
99 '\x07l&\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
100 '\x00\x01D\xf8\x00\x00\x00\x00\x01\x1b\x00\x00\x01\xb8\x00\x00' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
101 '\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\xff\xff\xff\xff\x02\n' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
102 '\x0e\xc6&\xa1\x92\xae6\x0b\x02i\xfe-\xe5\xbao\x05\xd1\xe7\x00' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
103 '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01F' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
104 '\x13\x00\x00\x00\x00\x01\xec\x00\x00\x03\x06\x00\x00\x00\x01' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
105 '\x00\x00\x00\x03\x00\x00\x00\x02\xff\xff\xff\xff\x12\xcb\xeby1' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
106 '\xb6\r\x98B\xcb\x07\xbd`\x8f\x92\xd9\xc4\x84\xbdK\x00\x00\x00' \ |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
107 '\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
108 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
13254
diff
changeset
|
109 def parse_index2(data, inline): |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
13254
diff
changeset
|
110 index, chunkcache = parsers.parse_index2(data, inline) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
13254
diff
changeset
|
111 return list(index), chunkcache |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
112 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
113 def importparsers(hexversion): |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
114 """Import mercurial.parsers with the given sys.hexversion.""" |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
115 # The file parsers.c inspects sys.hexversion to determine the version |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
116 # of the currently-running Python interpreter, so we monkey-patch |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
117 # sys.hexversion to simulate using different versions. |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
118 code = ("import sys; sys.hexversion=%s; " |
32372
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
29205
diff
changeset
|
119 "import mercurial.cext.parsers" % hexversion) |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
120 cmd = "python -c \"%s\"" % code |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
121 # We need to do these tests inside a subprocess because parser.c's |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
122 # version-checking code happens inside the module init function, and |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
123 # when using reload() to reimport an extension module, "The init function |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
124 # of extension modules is not called a second time" |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
125 # (from http://docs.python.org/2/library/functions.html?#reload). |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
126 p = subprocess.Popen(cmd, shell=True, |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
127 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
128 return p.communicate() # returns stdout, stderr |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
129 |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
130 def printhexfail(testnumber, hexversion, stdout, expected): |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
131 try: |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
132 hexstring = hex(hexversion) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
133 except TypeError: |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
134 hexstring = None |
28754
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
135 print("FAILED: version test #%s with Python %s and patched " |
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
136 "sys.hexversion %r (%r):\n Expected %s but got:\n-->'%s'\n" % |
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
137 (testnumber, sys.version_info, hexversion, hexstring, expected, |
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
138 stdout)) |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
139 |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
140 def testversionokay(testnumber, hexversion): |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
141 stdout, stderr = importparsers(hexversion) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
142 if stdout: |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
143 printhexfail(testnumber, hexversion, stdout, expected="no stdout") |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
144 |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
145 def testversionfail(testnumber, hexversion): |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
146 stdout, stderr = importparsers(hexversion) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
147 # We include versionerrortext to distinguish from other ImportErrors. |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
148 errtext = "ImportError: %s" % parsers.versionerrortext |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
149 if errtext not in stdout: |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
150 printhexfail(testnumber, hexversion, stdout, |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
151 expected="stdout to contain %r" % errtext) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
152 |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
153 def makehex(major, minor, micro): |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
154 return int("%x%02x%02x00" % (major, minor, micro), 16) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
155 |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
156 def runversiontests(): |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
157 """Check the version-detection logic when importing parsers.""" |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
158 info = sys.version_info |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
159 major, minor, micro = info[0], info[1], info[2] |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
160 # Test same major-minor versions. |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
161 testversionokay(1, makehex(major, minor, micro)) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
162 testversionokay(2, makehex(major, minor, micro + 1)) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
163 # Test different major-minor versions. |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
164 testversionfail(3, makehex(major + 1, minor, micro)) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
165 testversionfail(4, makehex(major, minor + 1, micro)) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
166 testversionfail(5, "'foo'") |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
167 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
13254
diff
changeset
|
168 def runtest() : |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
169 # Only test the version-detection logic if it is present. |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
170 try: |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
171 parsers.versionerrortext |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
172 except AttributeError: |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
173 pass |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
174 else: |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
175 runversiontests() |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20166
diff
changeset
|
176 |
20109
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
16620
diff
changeset
|
177 # Check that parse_index2() raises TypeError on bad arguments. |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
16620
diff
changeset
|
178 try: |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
16620
diff
changeset
|
179 parse_index2(0, True) |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
16620
diff
changeset
|
180 except TypeError: |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
16620
diff
changeset
|
181 pass |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
16620
diff
changeset
|
182 else: |
28754
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
183 print("Expected to get TypeError.") |
20109
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
16620
diff
changeset
|
184 |
20166
7eda5bb9ec8f
parsers: clarify documentation of test-parseindex2.py
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20159
diff
changeset
|
185 # Check parsers.parse_index2() on an index file against the original |
7eda5bb9ec8f
parsers: clarify documentation of test-parseindex2.py
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20159
diff
changeset
|
186 # Python implementation of parseindex, both with and without inlined data. |
7eda5bb9ec8f
parsers: clarify documentation of test-parseindex2.py
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20159
diff
changeset
|
187 |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
188 py_res_1 = py_parseindex(data_inlined, True) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
13254
diff
changeset
|
189 c_res_1 = parse_index2(data_inlined, True) |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
190 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
191 py_res_2 = py_parseindex(data_non_inlined, False) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
13254
diff
changeset
|
192 c_res_2 = parse_index2(data_non_inlined, False) |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
193 |
8117
2b30d8488819
remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents:
7110
diff
changeset
|
194 if py_res_1 != c_res_1: |
28754
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
195 print("Parse index result (with inlined data) differs!") |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
196 |
8117
2b30d8488819
remove unnecessary outer parenthesis in if-statements
Martin Geisler <mg@lazybytes.net>
parents:
7110
diff
changeset
|
197 if py_res_2 != c_res_2: |
28754
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
198 print("Parse index result (no inlined data) differs!") |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
199 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
200 ix = parsers.parse_index2(data_inlined, True)[0] |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
201 for i, r in enumerate(ix): |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
202 if r[7] == nullid: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
203 i = -1 |
16620
e22d6b1dec1d
tests: fix test-parseindex2.py when run with --pure
Bryan O'Sullivan <bryano@fb.com>
parents:
16414
diff
changeset
|
204 try: |
e22d6b1dec1d
tests: fix test-parseindex2.py when run with --pure
Bryan O'Sullivan <bryano@fb.com>
parents:
16414
diff
changeset
|
205 if ix[r[7]] != i: |
28754
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
206 print('Reverse lookup inconsistent for %r' |
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
207 % r[7].encode('hex')) |
16620
e22d6b1dec1d
tests: fix test-parseindex2.py when run with --pure
Bryan O'Sullivan <bryano@fb.com>
parents:
16414
diff
changeset
|
208 except TypeError: |
e22d6b1dec1d
tests: fix test-parseindex2.py when run with --pure
Bryan O'Sullivan <bryano@fb.com>
parents:
16414
diff
changeset
|
209 # pure version doesn't support this |
e22d6b1dec1d
tests: fix test-parseindex2.py when run with --pure
Bryan O'Sullivan <bryano@fb.com>
parents:
16414
diff
changeset
|
210 break |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
211 |
28754
7e5744e8334c
py3: use print_function in test-parseindex2.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28753
diff
changeset
|
212 print("done") |
7110
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
213 |
75fdc39b6172
Add parseindex2.py test case
Bernhard Leiner <bleiner@gmail.com>
parents:
diff
changeset
|
214 runtest() |