##// END OF EJS Templates
bundle2: rename unbundle2 test command to statbundle2...
Pierre-Yves David -
r20888:0b0d3800 default
parent child Browse files
Show More
@@ -1,329 +1,329 b''
1
1
2 Create an extension to test bundle2 API
2 Create an extension to test bundle2 API
3
3
4 $ cat > bundle2.py << EOF
4 $ cat > bundle2.py << EOF
5 > """A small extension to test bundle2 implementation
5 > """A small extension to test bundle2 implementation
6 >
6 >
7 > Current bundle2 implementation is far too limited to be used in any core
7 > Current bundle2 implementation is far too limited to be used in any core
8 > code. We still need to be able to test it while it grow up.
8 > code. We still need to be able to test it while it grow up.
9 > """
9 > """
10 >
10 >
11 > import sys
11 > import sys
12 > from mercurial import cmdutil
12 > from mercurial import cmdutil
13 > from mercurial import util
13 > from mercurial import util
14 > from mercurial import bundle2
14 > from mercurial import bundle2
15 > cmdtable = {}
15 > cmdtable = {}
16 > command = cmdutil.command(cmdtable)
16 > command = cmdutil.command(cmdtable)
17 >
17 >
18 > ELEPHANTSSONG = """Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
18 > ELEPHANTSSONG = """Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
19 > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
19 > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
20 > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko."""
20 > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko."""
21 > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it.
21 > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it.
22 >
22 >
23 > @command('bundle2',
23 > @command('bundle2',
24 > [('', 'param', [], 'stream level parameter'),
24 > [('', 'param', [], 'stream level parameter'),
25 > ('', 'parts', False, 'include some arbitrary parts to the bundle'),],
25 > ('', 'parts', False, 'include some arbitrary parts to the bundle'),],
26 > '[OUTPUTFILE]')
26 > '[OUTPUTFILE]')
27 > def cmdbundle2(ui, repo, path=None, **opts):
27 > def cmdbundle2(ui, repo, path=None, **opts):
28 > """write a bundle2 container on standard ouput"""
28 > """write a bundle2 container on standard ouput"""
29 > bundler = bundle2.bundle20(ui)
29 > bundler = bundle2.bundle20(ui)
30 > for p in opts['param']:
30 > for p in opts['param']:
31 > p = p.split('=', 1)
31 > p = p.split('=', 1)
32 > try:
32 > try:
33 > bundler.addparam(*p)
33 > bundler.addparam(*p)
34 > except ValueError, exc:
34 > except ValueError, exc:
35 > raise util.Abort('%s' % exc)
35 > raise util.Abort('%s' % exc)
36 >
36 >
37 > if opts['parts']:
37 > if opts['parts']:
38 > part = bundle2.part('test:empty')
38 > part = bundle2.part('test:empty')
39 > bundler.addpart(part)
39 > bundler.addpart(part)
40 > # add a second one to make sure we handle multiple parts
40 > # add a second one to make sure we handle multiple parts
41 > part = bundle2.part('test:empty')
41 > part = bundle2.part('test:empty')
42 > bundler.addpart(part)
42 > bundler.addpart(part)
43 > part = bundle2.part('test:song', data=ELEPHANTSSONG)
43 > part = bundle2.part('test:song', data=ELEPHANTSSONG)
44 > bundler.addpart(part)
44 > bundler.addpart(part)
45 > part = bundle2.part('test:math',
45 > part = bundle2.part('test:math',
46 > [('pi', '3.14'), ('e', '2.72')],
46 > [('pi', '3.14'), ('e', '2.72')],
47 > [('cooking', 'raw')],
47 > [('cooking', 'raw')],
48 > '42')
48 > '42')
49 > bundler.addpart(part)
49 > bundler.addpart(part)
50 >
50 >
51 > if path is None:
51 > if path is None:
52 > file = sys.stdout
52 > file = sys.stdout
53 > else:
53 > else:
54 > file = open(path, 'w')
54 > file = open(path, 'w')
55 >
55 >
56 > for chunk in bundler.getchunks():
56 > for chunk in bundler.getchunks():
57 > file.write(chunk)
57 > file.write(chunk)
58 >
58 >
59 > @command('unbundle2', [], '')
59 > @command('statbundle2', [], '')
60 > def cmdunbundle2(ui, repo):
60 > def cmdstatbundle2(ui, repo):
61 > """read a bundle2 container from standard input"""
61 > """print statistic on the bundle2 container read from stdin"""
62 > unbundler = bundle2.unbundle20(ui, sys.stdin)
62 > unbundler = bundle2.unbundle20(ui, sys.stdin)
63 > try:
63 > try:
64 > params = unbundler.params
64 > params = unbundler.params
65 > except KeyError, exc:
65 > except KeyError, exc:
66 > raise util.Abort('unknown parameters: %s' % exc)
66 > raise util.Abort('unknown parameters: %s' % exc)
67 > ui.write('options count: %i\n' % len(params))
67 > ui.write('options count: %i\n' % len(params))
68 > for key in sorted(params):
68 > for key in sorted(params):
69 > ui.write('- %s\n' % key)
69 > ui.write('- %s\n' % key)
70 > value = params[key]
70 > value = params[key]
71 > if value is not None:
71 > if value is not None:
72 > ui.write(' %s\n' % value)
72 > ui.write(' %s\n' % value)
73 > parts = list(unbundler)
73 > parts = list(unbundler)
74 > ui.write('parts count: %i\n' % len(parts))
74 > ui.write('parts count: %i\n' % len(parts))
75 > for p in parts:
75 > for p in parts:
76 > ui.write(' :%s:\n' % p.type)
76 > ui.write(' :%s:\n' % p.type)
77 > ui.write(' mandatory: %i\n' % len(p.mandatoryparams))
77 > ui.write(' mandatory: %i\n' % len(p.mandatoryparams))
78 > ui.write(' advisory: %i\n' % len(p.advisoryparams))
78 > ui.write(' advisory: %i\n' % len(p.advisoryparams))
79 > ui.write(' payload: %i bytes\n' % len(p.data))
79 > ui.write(' payload: %i bytes\n' % len(p.data))
80 > EOF
80 > EOF
81 $ cat >> $HGRCPATH << EOF
81 $ cat >> $HGRCPATH << EOF
82 > [extensions]
82 > [extensions]
83 > bundle2=$TESTTMP/bundle2.py
83 > bundle2=$TESTTMP/bundle2.py
84 > EOF
84 > EOF
85
85
86 The extension requires a repo (currently unused)
86 The extension requires a repo (currently unused)
87
87
88 $ hg init main
88 $ hg init main
89 $ cd main
89 $ cd main
90 $ touch a
90 $ touch a
91 $ hg add a
91 $ hg add a
92 $ hg commit -m 'a'
92 $ hg commit -m 'a'
93
93
94
94
95 Empty bundle
95 Empty bundle
96 =================
96 =================
97
97
98 - no option
98 - no option
99 - no parts
99 - no parts
100
100
101 Test bundling
101 Test bundling
102
102
103 $ hg bundle2
103 $ hg bundle2
104 HG20\x00\x00\x00\x00 (no-eol) (esc)
104 HG20\x00\x00\x00\x00 (no-eol) (esc)
105
105
106 Test unbundling
106 Test unbundling
107
107
108 $ hg bundle2 | hg unbundle2
108 $ hg bundle2 | hg statbundle2
109 options count: 0
109 options count: 0
110 parts count: 0
110 parts count: 0
111
111
112 Test old style bundle are detected and refused
112 Test old style bundle are detected and refused
113
113
114 $ hg bundle --all ../bundle.hg
114 $ hg bundle --all ../bundle.hg
115 1 changesets found
115 1 changesets found
116 $ hg unbundle2 < ../bundle.hg
116 $ hg statbundle2 < ../bundle.hg
117 abort: unknown bundle version 10
117 abort: unknown bundle version 10
118 [255]
118 [255]
119
119
120 Test parameters
120 Test parameters
121 =================
121 =================
122
122
123 - some options
123 - some options
124 - no parts
124 - no parts
125
125
126 advisory parameters, no value
126 advisory parameters, no value
127 -------------------------------
127 -------------------------------
128
128
129 Simplest possible parameters form
129 Simplest possible parameters form
130
130
131 Test generation simple option
131 Test generation simple option
132
132
133 $ hg bundle2 --param 'caution'
133 $ hg bundle2 --param 'caution'
134 HG20\x00\x07caution\x00\x00 (no-eol) (esc)
134 HG20\x00\x07caution\x00\x00 (no-eol) (esc)
135
135
136 Test unbundling
136 Test unbundling
137
137
138 $ hg bundle2 --param 'caution' | hg unbundle2
138 $ hg bundle2 --param 'caution' | hg statbundle2
139 options count: 1
139 options count: 1
140 - caution
140 - caution
141 parts count: 0
141 parts count: 0
142
142
143 Test generation multiple option
143 Test generation multiple option
144
144
145 $ hg bundle2 --param 'caution' --param 'meal'
145 $ hg bundle2 --param 'caution' --param 'meal'
146 HG20\x00\x0ccaution meal\x00\x00 (no-eol) (esc)
146 HG20\x00\x0ccaution meal\x00\x00 (no-eol) (esc)
147
147
148 Test unbundling
148 Test unbundling
149
149
150 $ hg bundle2 --param 'caution' --param 'meal' | hg unbundle2
150 $ hg bundle2 --param 'caution' --param 'meal' | hg statbundle2
151 options count: 2
151 options count: 2
152 - caution
152 - caution
153 - meal
153 - meal
154 parts count: 0
154 parts count: 0
155
155
156 advisory parameters, with value
156 advisory parameters, with value
157 -------------------------------
157 -------------------------------
158
158
159 Test generation
159 Test generation
160
160
161 $ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants'
161 $ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants'
162 HG20\x00\x1ccaution meal=vegan elephants\x00\x00 (no-eol) (esc)
162 HG20\x00\x1ccaution meal=vegan elephants\x00\x00 (no-eol) (esc)
163
163
164 Test unbundling
164 Test unbundling
165
165
166 $ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants' | hg unbundle2
166 $ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants' | hg statbundle2
167 options count: 3
167 options count: 3
168 - caution
168 - caution
169 - elephants
169 - elephants
170 - meal
170 - meal
171 vegan
171 vegan
172 parts count: 0
172 parts count: 0
173
173
174 parameter with special char in value
174 parameter with special char in value
175 ---------------------------------------------------
175 ---------------------------------------------------
176
176
177 Test generation
177 Test generation
178
178
179 $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple
179 $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple
180 HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)
180 HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)
181
181
182 Test unbundling
182 Test unbundling
183
183
184 $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple | hg unbundle2
184 $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple | hg statbundle2
185 options count: 2
185 options count: 2
186 - e|! 7/
186 - e|! 7/
187 babar%#==tutu
187 babar%#==tutu
188 - simple
188 - simple
189 parts count: 0
189 parts count: 0
190
190
191 Test unknown mandatory option
191 Test unknown mandatory option
192 ---------------------------------------------------
192 ---------------------------------------------------
193
193
194 $ hg bundle2 --param 'Gravity' | hg unbundle2
194 $ hg bundle2 --param 'Gravity' | hg statbundle2
195 abort: unknown parameters: 'Gravity'
195 abort: unknown parameters: 'Gravity'
196 [255]
196 [255]
197
197
198 Test debug output
198 Test debug output
199 ---------------------------------------------------
199 ---------------------------------------------------
200
200
201 bundling debug
201 bundling debug
202
202
203 $ hg bundle2 --debug --param 'e|! 7/=babar%#==tutu' --param simple ../out.hg2
203 $ hg bundle2 --debug --param 'e|! 7/=babar%#==tutu' --param simple ../out.hg2
204 start emission of HG20 stream
204 start emission of HG20 stream
205 bundle parameter: e%7C%21%207/=babar%25%23%3D%3Dtutu simple
205 bundle parameter: e%7C%21%207/=babar%25%23%3D%3Dtutu simple
206 start of parts
206 start of parts
207 end of bundle
207 end of bundle
208
208
209 file content is ok
209 file content is ok
210
210
211 $ cat ../out.hg2
211 $ cat ../out.hg2
212 HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)
212 HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)
213
213
214 unbundling debug
214 unbundling debug
215
215
216 $ hg unbundle2 --debug < ../out.hg2
216 $ hg statbundle2 --debug < ../out.hg2
217 start processing of HG20 stream
217 start processing of HG20 stream
218 reading bundle2 stream parameters
218 reading bundle2 stream parameters
219 ignoring unknown parameter 'e|! 7/'
219 ignoring unknown parameter 'e|! 7/'
220 ignoring unknown parameter 'simple'
220 ignoring unknown parameter 'simple'
221 options count: 2
221 options count: 2
222 - e|! 7/
222 - e|! 7/
223 babar%#==tutu
223 babar%#==tutu
224 - simple
224 - simple
225 start extraction of bundle2 parts
225 start extraction of bundle2 parts
226 part header size: 0
226 part header size: 0
227 end of bundle2 stream
227 end of bundle2 stream
228 parts count: 0
228 parts count: 0
229
229
230
230
231 Test buggy input
231 Test buggy input
232 ---------------------------------------------------
232 ---------------------------------------------------
233
233
234 empty parameter name
234 empty parameter name
235
235
236 $ hg bundle2 --param '' --quiet
236 $ hg bundle2 --param '' --quiet
237 abort: empty parameter name
237 abort: empty parameter name
238 [255]
238 [255]
239
239
240 bad parameter name
240 bad parameter name
241
241
242 $ hg bundle2 --param 42babar
242 $ hg bundle2 --param 42babar
243 abort: non letter first character: '42babar'
243 abort: non letter first character: '42babar'
244 [255]
244 [255]
245
245
246
246
247 Test part
247 Test part
248 =================
248 =================
249
249
250 $ hg bundle2 --parts ../parts.hg2 --debug
250 $ hg bundle2 --parts ../parts.hg2 --debug
251 start emission of HG20 stream
251 start emission of HG20 stream
252 bundle parameter:
252 bundle parameter:
253 start of parts
253 start of parts
254 bundle part: "test:empty"
254 bundle part: "test:empty"
255 bundle part: "test:empty"
255 bundle part: "test:empty"
256 bundle part: "test:song"
256 bundle part: "test:song"
257 bundle part: "test:math"
257 bundle part: "test:math"
258 end of bundle
258 end of bundle
259
259
260 $ cat ../parts.hg2
260 $ cat ../parts.hg2
261 HG20\x00\x00\x00\r (esc)
261 HG20\x00\x00\x00\r (esc)
262 test:empty\x00\x00\x00\x00\x00\x00\x00\r (esc)
262 test:empty\x00\x00\x00\x00\x00\x00\x00\r (esc)
263 test:empty\x00\x00\x00\x00\x00\x00\x00\x0c test:song\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc)
263 test:empty\x00\x00\x00\x00\x00\x00\x00\x0c test:song\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc)
264 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
264 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
265 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00' test:math\x02\x01\x02\x04\x01\x04\x07\x03pi3.14e2.72cookingraw\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
265 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00' test:math\x02\x01\x02\x04\x01\x04\x07\x03pi3.14e2.72cookingraw\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
266
266
267
267
268 $ hg unbundle2 < ../parts.hg2
268 $ hg statbundle2 < ../parts.hg2
269 options count: 0
269 options count: 0
270 parts count: 4
270 parts count: 4
271 :test:empty:
271 :test:empty:
272 mandatory: 0
272 mandatory: 0
273 advisory: 0
273 advisory: 0
274 payload: 0 bytes
274 payload: 0 bytes
275 :test:empty:
275 :test:empty:
276 mandatory: 0
276 mandatory: 0
277 advisory: 0
277 advisory: 0
278 payload: 0 bytes
278 payload: 0 bytes
279 :test:song:
279 :test:song:
280 mandatory: 0
280 mandatory: 0
281 advisory: 0
281 advisory: 0
282 payload: 178 bytes
282 payload: 178 bytes
283 :test:math:
283 :test:math:
284 mandatory: 2
284 mandatory: 2
285 advisory: 1
285 advisory: 1
286 payload: 2 bytes
286 payload: 2 bytes
287
287
288 $ hg unbundle2 --debug < ../parts.hg2
288 $ hg statbundle2 --debug < ../parts.hg2
289 start processing of HG20 stream
289 start processing of HG20 stream
290 reading bundle2 stream parameters
290 reading bundle2 stream parameters
291 options count: 0
291 options count: 0
292 start extraction of bundle2 parts
292 start extraction of bundle2 parts
293 part header size: 13
293 part header size: 13
294 part type: "test:empty"
294 part type: "test:empty"
295 part parameters: 0
295 part parameters: 0
296 payload chunk size: 0
296 payload chunk size: 0
297 part header size: 13
297 part header size: 13
298 part type: "test:empty"
298 part type: "test:empty"
299 part parameters: 0
299 part parameters: 0
300 payload chunk size: 0
300 payload chunk size: 0
301 part header size: 12
301 part header size: 12
302 part type: "test:song"
302 part type: "test:song"
303 part parameters: 0
303 part parameters: 0
304 payload chunk size: 178
304 payload chunk size: 178
305 payload chunk size: 0
305 payload chunk size: 0
306 part header size: 39
306 part header size: 39
307 part type: "test:math"
307 part type: "test:math"
308 part parameters: 3
308 part parameters: 3
309 payload chunk size: 2
309 payload chunk size: 2
310 payload chunk size: 0
310 payload chunk size: 0
311 part header size: 0
311 part header size: 0
312 end of bundle2 stream
312 end of bundle2 stream
313 parts count: 4
313 parts count: 4
314 :test:empty:
314 :test:empty:
315 mandatory: 0
315 mandatory: 0
316 advisory: 0
316 advisory: 0
317 payload: 0 bytes
317 payload: 0 bytes
318 :test:empty:
318 :test:empty:
319 mandatory: 0
319 mandatory: 0
320 advisory: 0
320 advisory: 0
321 payload: 0 bytes
321 payload: 0 bytes
322 :test:song:
322 :test:song:
323 mandatory: 0
323 mandatory: 0
324 advisory: 0
324 advisory: 0
325 payload: 178 bytes
325 payload: 178 bytes
326 :test:math:
326 :test:math:
327 mandatory: 2
327 mandatory: 2
328 advisory: 1
328 advisory: 1
329 payload: 2 bytes
329 payload: 2 bytes
General Comments 0
You need to be logged in to leave comments. Login now