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