##// END OF EJS Templates
py3: use print as a function in tests/test-parseindex.t...
Pulkit Goyal -
r38090:ce307af0 default
parent child Browse files
Show More
@@ -1,203 +1,206 b''
1 revlog.parseindex must be able to parse the index file even if
1 revlog.parseindex must be able to parse the index file even if
2 an index entry is split between two 64k blocks. The ideal test
2 an index entry is split between two 64k blocks. The ideal test
3 would be to create an index file with inline data where
3 would be to create an index file with inline data where
4 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
4 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
5 the size of an index entry) and with an index entry starting right
5 the size of an index entry) and with an index entry starting right
6 before the 64k block boundary, and try to read it.
6 before the 64k block boundary, and try to read it.
7 We approximate that by reducing the read buffer to 1 byte.
7 We approximate that by reducing the read buffer to 1 byte.
8
8
9 $ hg init a
9 $ hg init a
10 $ cd a
10 $ cd a
11 $ echo abc > foo
11 $ echo abc > foo
12 $ hg add foo
12 $ hg add foo
13 $ hg commit -m 'add foo'
13 $ hg commit -m 'add foo'
14 $ echo >> foo
14 $ echo >> foo
15 $ hg commit -m 'change foo'
15 $ hg commit -m 'change foo'
16 $ hg log -r 0:
16 $ hg log -r 0:
17 changeset: 0:7c31755bf9b5
17 changeset: 0:7c31755bf9b5
18 user: test
18 user: test
19 date: Thu Jan 01 00:00:00 1970 +0000
19 date: Thu Jan 01 00:00:00 1970 +0000
20 summary: add foo
20 summary: add foo
21
21
22 changeset: 1:26333235a41c
22 changeset: 1:26333235a41c
23 tag: tip
23 tag: tip
24 user: test
24 user: test
25 date: Thu Jan 01 00:00:00 1970 +0000
25 date: Thu Jan 01 00:00:00 1970 +0000
26 summary: change foo
26 summary: change foo
27
27
28 $ cat >> test.py << EOF
28 $ cat >> test.py << EOF
29 > from __future__ import print_function
29 > from mercurial import changelog, vfs
30 > from mercurial import changelog, vfs
30 > from mercurial.node import *
31 > from mercurial.node import *
31 >
32 >
32 > class singlebyteread(object):
33 > class singlebyteread(object):
33 > def __init__(self, real):
34 > def __init__(self, real):
34 > self.real = real
35 > self.real = real
35 >
36 >
36 > def read(self, size=-1):
37 > def read(self, size=-1):
37 > if size == 65536:
38 > if size == 65536:
38 > size = 1
39 > size = 1
39 > return self.real.read(size)
40 > return self.real.read(size)
40 >
41 >
41 > def __getattr__(self, key):
42 > def __getattr__(self, key):
42 > return getattr(self.real, key)
43 > return getattr(self.real, key)
43 >
44 >
44 > def __enter__(self):
45 > def __enter__(self):
45 > self.real.__enter__()
46 > self.real.__enter__()
46 > return self
47 > return self
47 >
48 >
48 > def __exit__(self, *args, **kwargs):
49 > def __exit__(self, *args, **kwargs):
49 > return self.real.__exit__(*args, **kwargs)
50 > return self.real.__exit__(*args, **kwargs)
50 >
51 >
51 > def opener(*args):
52 > def opener(*args):
52 > o = vfs.vfs(*args)
53 > o = vfs.vfs(*args)
53 > def wrapper(*a, **kwargs):
54 > def wrapper(*a, **kwargs):
54 > f = o(*a, **kwargs)
55 > f = o(*a, **kwargs)
55 > return singlebyteread(f)
56 > return singlebyteread(f)
56 > return wrapper
57 > return wrapper
57 >
58 >
58 > cl = changelog.changelog(opener('.hg/store'))
59 > cl = changelog.changelog(opener('.hg/store'))
59 > print len(cl), 'revisions:'
60 > print(len(cl), 'revisions:')
60 > for r in cl:
61 > for r in cl:
61 > print short(cl.node(r))
62 > print(short(cl.node(r)))
62 > EOF
63 > EOF
63 $ $PYTHON test.py
64 $ $PYTHON test.py
64 2 revisions:
65 2 revisions:
65 7c31755bf9b5
66 7c31755bf9b5
66 26333235a41c
67 26333235a41c
67
68
68 $ cd ..
69 $ cd ..
69
70
70 #if no-pure
71 #if no-pure
71
72
72 Test SEGV caused by bad revision passed to reachableroots() (issue4775):
73 Test SEGV caused by bad revision passed to reachableroots() (issue4775):
73
74
74 $ cd a
75 $ cd a
75
76
76 $ $PYTHON <<EOF
77 $ $PYTHON <<EOF
78 > from __future__ import print_function
77 > from mercurial import changelog, vfs
79 > from mercurial import changelog, vfs
78 > cl = changelog.changelog(vfs.vfs('.hg/store'))
80 > cl = changelog.changelog(vfs.vfs('.hg/store'))
79 > print 'good heads:'
81 > print('good heads:')
80 > for head in [0, len(cl) - 1, -1]:
82 > for head in [0, len(cl) - 1, -1]:
81 > print'%s: %r' % (head, cl.reachableroots(0, [head], [0]))
83 > print('%s: %r' % (head, cl.reachableroots(0, [head], [0])))
82 > print 'bad heads:'
84 > print('bad heads:')
83 > for head in [len(cl), 10000, -2, -10000, None]:
85 > for head in [len(cl), 10000, -2, -10000, None]:
84 > print '%s:' % head,
86 > print('%s:' % head, end=' ')
85 > try:
87 > try:
86 > cl.reachableroots(0, [head], [0])
88 > cl.reachableroots(0, [head], [0])
87 > print 'uncaught buffer overflow?'
89 > print('uncaught buffer overflow?')
88 > except (IndexError, TypeError) as inst:
90 > except (IndexError, TypeError) as inst:
89 > print inst
91 > print(inst)
90 > print 'good roots:'
92 > print('good roots:')
91 > for root in [0, len(cl) - 1, -1]:
93 > for root in [0, len(cl) - 1, -1]:
92 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
94 > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
93 > print 'out-of-range roots are ignored:'
95 > print('out-of-range roots are ignored:')
94 > for root in [len(cl), 10000, -2, -10000]:
96 > for root in [len(cl), 10000, -2, -10000]:
95 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
97 > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
96 > print 'bad roots:'
98 > print('bad roots:')
97 > for root in [None]:
99 > for root in [None]:
98 > print '%s:' % root,
100 > print('%s:' % root, end=' ')
99 > try:
101 > try:
100 > cl.reachableroots(root, [len(cl) - 1], [root])
102 > cl.reachableroots(root, [len(cl) - 1], [root])
101 > print 'uncaught error?'
103 > print('uncaught error?')
102 > except TypeError as inst:
104 > except TypeError as inst:
103 > print inst
105 > print(inst)
104 > EOF
106 > EOF
105 good heads:
107 good heads:
106 0: [0]
108 0: [0]
107 1: [0]
109 1: [0]
108 -1: []
110 -1: []
109 bad heads:
111 bad heads:
110 2: head out of range
112 2: head out of range
111 10000: head out of range
113 10000: head out of range
112 -2: head out of range
114 -2: head out of range
113 -10000: head out of range
115 -10000: head out of range
114 None: an integer is required
116 None: an integer is required
115 good roots:
117 good roots:
116 0: [0]
118 0: [0]
117 1: [1]
119 1: [1]
118 -1: [-1]
120 -1: [-1]
119 out-of-range roots are ignored:
121 out-of-range roots are ignored:
120 2: []
122 2: []
121 10000: []
123 10000: []
122 -2: []
124 -2: []
123 -10000: []
125 -10000: []
124 bad roots:
126 bad roots:
125 None: an integer is required
127 None: an integer is required
126
128
127 $ cd ..
129 $ cd ..
128
130
129 Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
131 Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
130
132
131 $ mkdir invalidparent
133 $ mkdir invalidparent
132 $ cd invalidparent
134 $ cd invalidparent
133
135
134 $ hg clone --pull -q --config phases.publish=False ../a limit
136 $ hg clone --pull -q --config phases.publish=False ../a limit
135 $ hg clone --pull -q --config phases.publish=False ../a segv
137 $ hg clone --pull -q --config phases.publish=False ../a segv
136 $ rm -R limit/.hg/cache segv/.hg/cache
138 $ rm -R limit/.hg/cache segv/.hg/cache
137
139
138 $ $PYTHON <<EOF
140 $ $PYTHON <<EOF
139 > data = open("limit/.hg/store/00changelog.i", "rb").read()
141 > data = open("limit/.hg/store/00changelog.i", "rb").read()
140 > for n, p in [('limit', '\0\0\0\x02'), ('segv', '\0\x01\0\0')]:
142 > for n, p in [('limit', '\0\0\0\x02'), ('segv', '\0\x01\0\0')]:
141 > # corrupt p1 at rev0 and p2 at rev1
143 > # corrupt p1 at rev0 and p2 at rev1
142 > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
144 > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
143 > open(n + "/.hg/store/00changelog.i", "wb").write(d)
145 > open(n + "/.hg/store/00changelog.i", "wb").write(d)
144 > EOF
146 > EOF
145
147
146 $ hg -R limit debugindex -f1 -c
148 $ hg -R limit debugindex -f1 -c
147 rev flag size link p1 p2 nodeid
149 rev flag size link p1 p2 nodeid
148 0 0000 62 0 2 -1 7c31755bf9b5
150 0 0000 62 0 2 -1 7c31755bf9b5
149 1 0000 65 1 0 2 26333235a41c
151 1 0000 65 1 0 2 26333235a41c
150
152
151 $ hg -R limit debugdeltachain -c
153 $ hg -R limit debugdeltachain -c
152 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
154 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
153 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
155 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
154 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
156 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
155
157
156 $ hg -R segv debugindex -f1 -c
158 $ hg -R segv debugindex -f1 -c
157 rev flag size link p1 p2 nodeid
159 rev flag size link p1 p2 nodeid
158 0 0000 62 0 65536 -1 7c31755bf9b5
160 0 0000 62 0 65536 -1 7c31755bf9b5
159 1 0000 65 1 0 65536 26333235a41c
161 1 0000 65 1 0 65536 26333235a41c
160
162
161 $ hg -R segv debugdeltachain -c
163 $ hg -R segv debugdeltachain -c
162 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
164 rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio
163 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
165 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000
164 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
166 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000
165
167
166 $ cat <<EOF > test.py
168 $ cat <<EOF > test.py
169 > from __future__ import print_function
167 > import sys
170 > import sys
168 > from mercurial import changelog, vfs
171 > from mercurial import changelog, vfs
169 > cl = changelog.changelog(vfs.vfs(sys.argv[1]))
172 > cl = changelog.changelog(vfs.vfs(sys.argv[1]))
170 > n0, n1 = cl.node(0), cl.node(1)
173 > n0, n1 = cl.node(0), cl.node(1)
171 > ops = [
174 > ops = [
172 > ('reachableroots',
175 > ('reachableroots',
173 > lambda: cl.index.reachableroots2(0, [1], [0], False)),
176 > lambda: cl.index.reachableroots2(0, [1], [0], False)),
174 > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])),
177 > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])),
175 > ('index_headrevs', lambda: cl.headrevs()),
178 > ('index_headrevs', lambda: cl.headrevs()),
176 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
179 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
177 > ('find_deepest', lambda: cl.ancestor(n0, n1)),
180 > ('find_deepest', lambda: cl.ancestor(n0, n1)),
178 > ]
181 > ]
179 > for l, f in ops:
182 > for l, f in ops:
180 > print l + ':',
183 > print(l + ':', end=' ')
181 > try:
184 > try:
182 > f()
185 > f()
183 > print 'uncaught buffer overflow?'
186 > print('uncaught buffer overflow?')
184 > except ValueError, inst:
187 > except ValueError, inst:
185 > print inst
188 > print(inst)
186 > EOF
189 > EOF
187
190
188 $ $PYTHON test.py limit/.hg/store
191 $ $PYTHON test.py limit/.hg/store
189 reachableroots: parent out of range
192 reachableroots: parent out of range
190 compute_phases_map_sets: parent out of range
193 compute_phases_map_sets: parent out of range
191 index_headrevs: parent out of range
194 index_headrevs: parent out of range
192 find_gca_candidates: parent out of range
195 find_gca_candidates: parent out of range
193 find_deepest: parent out of range
196 find_deepest: parent out of range
194 $ $PYTHON test.py segv/.hg/store
197 $ $PYTHON test.py segv/.hg/store
195 reachableroots: parent out of range
198 reachableroots: parent out of range
196 compute_phases_map_sets: parent out of range
199 compute_phases_map_sets: parent out of range
197 index_headrevs: parent out of range
200 index_headrevs: parent out of range
198 find_gca_candidates: parent out of range
201 find_gca_candidates: parent out of range
199 find_deepest: parent out of range
202 find_deepest: parent out of range
200
203
201 $ cd ..
204 $ cd ..
202
205
203 #endif
206 #endif
General Comments 0
You need to be logged in to leave comments. Login now