comparison tests/test-bundle2.t @ 21184:28d76afa1568 stable

bundle2: fix raising errors during heads checking If the heads on the server differ from the ones reported seen by the client at bundle time, we raise a PushRaced exception. However, the part raising the exception was broken. To fix it, we move the PushRaced class in the error module so it can be accessible everywhere without an import cycle. A test is also added to prevent regression.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 21 Apr 2014 18:59:09 -0700
parents 4345274adc4b
children 5b3717e1a3ea
comparison
equal deleted inserted replaced
21183:4345274adc4b 21184:28d76afa1568
13 > from mercurial import util 13 > from mercurial import util
14 > from mercurial import bundle2 14 > from mercurial import bundle2
15 > from mercurial import scmutil 15 > from mercurial import scmutil
16 > from mercurial import discovery 16 > from mercurial import discovery
17 > from mercurial import changegroup 17 > from mercurial import changegroup
18 > from mercurial import error
18 > cmdtable = {} 19 > cmdtable = {}
19 > command = cmdutil.command(cmdtable) 20 > command = cmdutil.command(cmdtable)
20 > 21 >
21 > ELEPHANTSSONG = """Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko 22 > ELEPHANTSSONG = """Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
22 > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko 23 > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
57 > @command('bundle2', 58 > @command('bundle2',
58 > [('', 'param', [], 'stream level parameter'), 59 > [('', 'param', [], 'stream level parameter'),
59 > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'), 60 > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
60 > ('', 'parts', False, 'include some arbitrary parts to the bundle'), 61 > ('', 'parts', False, 'include some arbitrary parts to the bundle'),
61 > ('', 'reply', False, 'produce a reply bundle'), 62 > ('', 'reply', False, 'produce a reply bundle'),
63 > ('', 'pushrace', False, 'includes a check:head part with unknown nodes'),
62 > ('r', 'rev', [], 'includes those changeset in the bundle'),], 64 > ('r', 'rev', [], 'includes those changeset in the bundle'),],
63 > '[OUTPUTFILE]') 65 > '[OUTPUTFILE]')
64 > def cmdbundle2(ui, repo, path=None, **opts): 66 > def cmdbundle2(ui, repo, path=None, **opts):
65 > """write a bundle2 container on standard ouput""" 67 > """write a bundle2 container on standard ouput"""
66 > bundler = bundle2.bundle20(ui) 68 > bundler = bundle2.bundle20(ui)
72 > raise util.Abort('%s' % exc) 74 > raise util.Abort('%s' % exc)
73 > 75 >
74 > if opts['reply']: 76 > if opts['reply']:
75 > capsstring = 'ping-pong\nelephants=babar,celeste\ncity%3D%21=celeste%2Cville' 77 > capsstring = 'ping-pong\nelephants=babar,celeste\ncity%3D%21=celeste%2Cville'
76 > bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsstring)) 78 > bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsstring))
79 >
80 > if opts['pushrace']:
81 > dummynode = '01234567890123456789'
82 > bundler.addpart(bundle2.bundlepart('b2x:check:heads', data=dummynode))
77 > 83 >
78 > revs = opts['rev'] 84 > revs = opts['rev']
79 > if 'rev' in opts: 85 > if 'rev' in opts:
80 > revs = scmutil.revrange(repo, opts['rev']) 86 > revs = scmutil.revrange(repo, opts['rev'])
81 > if revs: 87 > if revs:
130 > unbundler = bundle2.unbundle20(ui, sys.stdin) 136 > unbundler = bundle2.unbundle20(ui, sys.stdin)
131 > op = bundle2.processbundle(repo, unbundler, lambda: tr) 137 > op = bundle2.processbundle(repo, unbundler, lambda: tr)
132 > tr.close() 138 > tr.close()
133 > except KeyError, exc: 139 > except KeyError, exc:
134 > raise util.Abort('missing support for %s' % exc) 140 > raise util.Abort('missing support for %s' % exc)
141 > except error.PushRaced, exc:
142 > raise util.Abort('push race')
135 > finally: 143 > finally:
136 > if tr is not None: 144 > if tr is not None:
137 > tr.release() 145 > tr.release()
138 > lock.release() 146 > lock.release()
139 > remains = sys.stdin.read() 147 > remains = sys.stdin.read()
598 remote: debugreply: 'celeste' 606 remote: debugreply: 'celeste'
599 remote: debugreply: 'ping-pong' 607 remote: debugreply: 'ping-pong'
600 remote: received ping request (id 6) 608 remote: received ping request (id 6)
601 remote: replying to ping request (id 6) 609 remote: replying to ping request (id 6)
602 0 unread bytes 610 0 unread bytes
611
612 Test push race detection
613
614 $ hg bundle2 --pushrace ../part-race.hg2
615
616 $ hg unbundle2 < ../part-race.hg2
617 0 unread bytes
618 abort: push race
619 [255]
603 620
604 Support for changegroup 621 Support for changegroup
605 =================================== 622 ===================================
606 623
607 $ hg unbundle $TESTDIR/bundles/rebase.hg 624 $ hg unbundle $TESTDIR/bundles/rebase.hg