Show More
@@ -22,6 +22,7 b' Create an extension to test bundle2 API' | |||||
22 | > from mercurial import changegroup |
|
22 | > from mercurial import changegroup | |
23 | > from mercurial import error |
|
23 | > from mercurial import error | |
24 | > from mercurial import obsolete |
|
24 | > from mercurial import obsolete | |
|
25 | > from mercurial import pycompat | |||
25 | > from mercurial import registrar |
|
26 | > from mercurial import registrar | |
26 | > |
|
27 | > | |
27 | > |
|
28 | > | |
@@ -36,58 +37,58 b' Create an extension to test bundle2 API' | |||||
36 | > cmdtable = {} |
|
37 | > cmdtable = {} | |
37 | > command = registrar.command(cmdtable) |
|
38 | > command = registrar.command(cmdtable) | |
38 | > |
|
39 | > | |
39 | > ELEPHANTSSONG = """Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko |
|
40 | > ELEPHANTSSONG = b"""Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko | |
40 | > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko |
|
41 | > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | |
41 | > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.""" |
|
42 | > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.""" | |
42 | > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it. |
|
43 | > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it. | |
43 | > |
|
44 | > | |
44 | > @bundle2.parthandler('test:song') |
|
45 | > @bundle2.parthandler(b'test:song') | |
45 | > def songhandler(op, part): |
|
46 | > def songhandler(op, part): | |
46 | > """handle a "test:song" bundle2 part, printing the lyrics on stdin""" |
|
47 | > """handle a "test:song" bundle2 part, printing the lyrics on stdin""" | |
47 | > op.ui.write('The choir starts singing:\n') |
|
48 | > op.ui.write(b'The choir starts singing:\n') | |
48 | > verses = 0 |
|
49 | > verses = 0 | |
49 | > for line in part.read().split('\n'): |
|
50 | > for line in part.read().split(b'\n'): | |
50 | > op.ui.write(' %s\n' % line) |
|
51 | > op.ui.write(b' %s\n' % line) | |
51 | > verses += 1 |
|
52 | > verses += 1 | |
52 | > op.records.add('song', {'verses': verses}) |
|
53 | > op.records.add(b'song', {b'verses': verses}) | |
53 | > |
|
54 | > | |
54 | > @bundle2.parthandler('test:ping') |
|
55 | > @bundle2.parthandler(b'test:ping') | |
55 | > def pinghandler(op, part): |
|
56 | > def pinghandler(op, part): | |
56 | > op.ui.write('received ping request (id %i)\n' % part.id) |
|
57 | > op.ui.write(b'received ping request (id %i)\n' % part.id) | |
57 | > if op.reply is not None and 'ping-pong' in op.reply.capabilities: |
|
58 | > if op.reply is not None and b'ping-pong' in op.reply.capabilities: | |
58 | > op.ui.write_err('replying to ping request (id %i)\n' % part.id) |
|
59 | > op.ui.write_err(b'replying to ping request (id %i)\n' % part.id) | |
59 |
> op.reply.newpart('test:pong', [('in-reply-to', |
|
60 | > op.reply.newpart(b'test:pong', [(b'in-reply-to', b'%d' % part.id)], | |
60 |
> mandatory=False |
|
61 | > mandatory=False) | |
61 | > |
|
62 | > | |
62 | > @bundle2.parthandler('test:debugreply') |
|
63 | > @bundle2.parthandler(b'test:debugreply') | |
63 | > def debugreply(op, part): |
|
64 | > def debugreply(op, part): | |
64 | > """print data about the capacity of the bundle reply""" |
|
65 | > """print data about the capacity of the bundle reply""" | |
65 | > if op.reply is None: |
|
66 | > if op.reply is None: | |
66 | > op.ui.write('debugreply: no reply\n') |
|
67 | > op.ui.write(b'debugreply: no reply\n') | |
67 | > else: |
|
68 | > else: | |
68 | > op.ui.write('debugreply: capabilities:\n') |
|
69 | > op.ui.write(b'debugreply: capabilities:\n') | |
69 | > for cap in sorted(op.reply.capabilities): |
|
70 | > for cap in sorted(op.reply.capabilities): | |
70 | > op.ui.write('debugreply: %r\n' % cap) |
|
71 | > op.ui.write(b'debugreply: %r\n' % cap) | |
71 | > for val in op.reply.capabilities[cap]: |
|
72 | > for val in op.reply.capabilities[cap]: | |
72 | > op.ui.write('debugreply: %r\n' % val) |
|
73 | > op.ui.write(b'debugreply: %r\n' % val) | |
73 | > |
|
74 | > | |
74 | > @command(b'bundle2', |
|
75 | > @command(b'bundle2', | |
75 | > [('', 'param', [], 'stream level parameter'), |
|
76 | > [(b'', b'param', [], b'stream level parameter'), | |
76 | > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'), |
|
77 | > (b'', b'unknown', False, b'include an unknown mandatory part in the bundle'), | |
77 | > ('', 'unknownparams', False, 'include an unknown part parameters in the bundle'), |
|
78 | > (b'', b'unknownparams', False, b'include an unknown part parameters in the bundle'), | |
78 | > ('', 'parts', False, 'include some arbitrary parts to the bundle'), |
|
79 | > (b'', b'parts', False, b'include some arbitrary parts to the bundle'), | |
79 | > ('', 'reply', False, 'produce a reply bundle'), |
|
80 | > (b'', b'reply', False, b'produce a reply bundle'), | |
80 | > ('', 'pushrace', False, 'includes a check:head part with unknown nodes'), |
|
81 | > (b'', b'pushrace', False, b'includes a check:head part with unknown nodes'), | |
81 | > ('', 'genraise', False, 'includes a part that raise an exception during generation'), |
|
82 | > (b'', b'genraise', False, b'includes a part that raise an exception during generation'), | |
82 | > ('', 'timeout', False, 'emulate a timeout during bundle generation'), |
|
83 | > (b'', b'timeout', False, b'emulate a timeout during bundle generation'), | |
83 | > ('r', 'rev', [], 'includes those changeset in the bundle'), |
|
84 | > (b'r', b'rev', [], b'includes those changeset in the bundle'), | |
84 | > ('', 'compress', '', 'compress the stream'),], |
|
85 | > (b'', b'compress', b'', b'compress the stream'),], | |
85 | > '[OUTPUTFILE]') |
|
86 | > b'[OUTPUTFILE]') | |
86 | > def cmdbundle2(ui, repo, path=None, **opts): |
|
87 | > def cmdbundle2(ui, repo, path=None, **opts): | |
87 | > """write a bundle2 container on standard output""" |
|
88 | > """write a bundle2 container on standard output""" | |
88 | > bundler = bundle2.bundle20(ui) |
|
89 | > bundler = bundle2.bundle20(ui) | |
89 | > for p in opts['param']: |
|
90 | > for p in opts['param']: | |
90 | > p = p.split('=', 1) |
|
91 | > p = p.split(b'=', 1) | |
91 | > try: |
|
92 | > try: | |
92 | > bundler.addparam(*p) |
|
93 | > bundler.addparam(*p) | |
93 | > except ValueError as exc: |
|
94 | > except ValueError as exc: | |
@@ -97,13 +98,13 b' Create an extension to test bundle2 API' | |||||
97 | > bundler.setcompression(opts['compress']) |
|
98 | > bundler.setcompression(opts['compress']) | |
98 | > |
|
99 | > | |
99 | > if opts['reply']: |
|
100 | > if opts['reply']: | |
100 | > capsstring = 'ping-pong\nelephants=babar,celeste\ncity%3D%21=celeste%2Cville' |
|
101 | > capsstring = b'ping-pong\nelephants=babar,celeste\ncity%3D%21=celeste%2Cville' | |
101 | > bundler.newpart('replycaps', data=capsstring) |
|
102 | > bundler.newpart(b'replycaps', data=capsstring) | |
102 | > |
|
103 | > | |
103 | > if opts['pushrace']: |
|
104 | > if opts['pushrace']: | |
104 | > # also serve to test the assignement of data outside of init |
|
105 | > # also serve to test the assignement of data outside of init | |
105 | > part = bundler.newpart('check:heads') |
|
106 | > part = bundler.newpart(b'check:heads') | |
106 | > part.data = '01234567890123456789' |
|
107 | > part.data = b'01234567890123456789' | |
107 | > |
|
108 | > | |
108 | > revs = opts['rev'] |
|
109 | > revs = opts['rev'] | |
109 | > if 'rev' in opts: |
|
110 | > if 'rev' in opts: | |
@@ -114,46 +115,46 b' Create an extension to test bundle2 API' | |||||
114 | > headmissing = [c.node() for c in repo.set('heads(%ld)', revs)] |
|
115 | > headmissing = [c.node() for c in repo.set('heads(%ld)', revs)] | |
115 | > headcommon = [c.node() for c in repo.set('parents(%ld) - %ld', revs, revs)] |
|
116 | > headcommon = [c.node() for c in repo.set('parents(%ld) - %ld', revs, revs)] | |
116 | > outgoing = discovery.outgoing(repo, headcommon, headmissing) |
|
117 | > outgoing = discovery.outgoing(repo, headcommon, headmissing) | |
117 | > cg = changegroup.makechangegroup(repo, outgoing, '01', |
|
118 | > cg = changegroup.makechangegroup(repo, outgoing, b'01', | |
118 | > 'test:bundle2') |
|
119 | > b'test:bundle2') | |
119 |
> bundler.newpart('changegroup', data=cg.getchunks() |
|
120 | > bundler.newpart(b'changegroup', data=cg.getchunks(), | |
120 |
> mandatory=False |
|
121 | > mandatory=False) | |
121 | > |
|
122 | > | |
122 | > if opts['parts']: |
|
123 | > if opts['parts']: | |
123 | > bundler.newpart('test:empty', mandatory=False) |
|
124 | > bundler.newpart(b'test:empty', mandatory=False) | |
124 | > # add a second one to make sure we handle multiple parts |
|
125 | > # add a second one to make sure we handle multiple parts | |
125 | > bundler.newpart('test:empty', mandatory=False) |
|
126 | > bundler.newpart(b'test:empty', mandatory=False) | |
126 | > bundler.newpart('test:song', data=ELEPHANTSSONG, mandatory=False) |
|
127 | > bundler.newpart(b'test:song', data=ELEPHANTSSONG, mandatory=False) | |
127 | > bundler.newpart('test:debugreply', mandatory=False) |
|
128 | > bundler.newpart(b'test:debugreply', mandatory=False) | |
128 | > mathpart = bundler.newpart('test:math') |
|
129 | > mathpart = bundler.newpart(b'test:math') | |
129 | > mathpart.addparam('pi', '3.14') |
|
130 | > mathpart.addparam(b'pi', b'3.14') | |
130 | > mathpart.addparam('e', '2.72') |
|
131 | > mathpart.addparam(b'e', b'2.72') | |
131 | > mathpart.addparam('cooking', 'raw', mandatory=False) |
|
132 | > mathpart.addparam(b'cooking', b'raw', mandatory=False) | |
132 | > mathpart.data = '42' |
|
133 | > mathpart.data = b'42' | |
133 | > mathpart.mandatory = False |
|
134 | > mathpart.mandatory = False | |
134 | > # advisory known part with unknown mandatory param |
|
135 | > # advisory known part with unknown mandatory param | |
135 | > bundler.newpart('test:song', [('randomparam','')], mandatory=False) |
|
136 | > bundler.newpart(b'test:song', [(b'randomparam', b'')], mandatory=False) | |
136 | > if opts['unknown']: |
|
137 | > if opts['unknown']: | |
137 |
> bundler.newpart('test:unknown', data='some random content' |
|
138 | > bundler.newpart(b'test:unknown', data=b'some random content') | |
138 | > if opts['unknownparams']: |
|
139 | > if opts['unknownparams']: | |
139 | > bundler.newpart('test:song', [('randomparams', '')]) |
|
140 | > bundler.newpart(b'test:song', [(b'randomparams', b'')]) | |
140 | > if opts['parts']: |
|
141 | > if opts['parts']: | |
141 |
> bundler.newpart('test:ping', mandatory=False |
|
142 | > bundler.newpart(b'test:ping', mandatory=False) | |
142 | > if opts['genraise']: |
|
143 | > if opts['genraise']: | |
143 | > def genraise(): |
|
144 | > def genraise(): | |
144 | > yield 'first line\n' |
|
145 | > yield b'first line\n' | |
145 | > raise RuntimeError('Someone set up us the bomb!') |
|
146 | > raise RuntimeError('Someone set up us the bomb!') | |
146 |
> bundler.newpart('output', data=genraise() |
|
147 | > bundler.newpart(b'output', data=genraise(), mandatory=False) | |
147 | > |
|
148 | > | |
148 | > if path is None: |
|
149 | > if path is None: | |
149 |
> file = |
|
150 | > file = pycompat.stdout | |
150 | > else: |
|
151 | > else: | |
151 | > file = open(path, 'wb') |
|
152 | > file = open(path, 'wb') | |
152 | > |
|
153 | > | |
153 | > if opts['timeout']: |
|
154 | > if opts['timeout']: | |
154 |
> bundler.newpart('test:song', data=ELEPHANTSSONG |
|
155 | > bundler.newpart(b'test:song', data=ELEPHANTSSONG, mandatory=False) | |
155 | > for idx, junk in enumerate(bundler.getchunks()): |
|
156 | > for idx, junk in enumerate(bundler.getchunks()): | |
156 | > ui.write('%d chunk\n' % idx) |
|
157 | > ui.write(b'%d chunk\n' % idx) | |
157 | > if idx > 4: |
|
158 | > if idx > 4: | |
158 | > # This throws a GeneratorExit inside the generator, which |
|
159 | > # This throws a GeneratorExit inside the generator, which | |
159 | > # can cause problems if the exception-recovery code is |
|
160 | > # can cause problems if the exception-recovery code is | |
@@ -161,7 +162,7 b' Create an extension to test bundle2 API' | |||||
161 | > # occur while we're in the middle of a part. |
|
162 | > # occur while we're in the middle of a part. | |
162 | > break |
|
163 | > break | |
163 | > gc.collect() |
|
164 | > gc.collect() | |
164 | > ui.write('fake timeout complete.\n') |
|
165 | > ui.write(b'fake timeout complete.\n') | |
165 | > return |
|
166 | > return | |
166 | > try: |
|
167 | > try: | |
167 | > for chunk in bundler.getchunks(): |
|
168 | > for chunk in bundler.getchunks(): | |
@@ -171,15 +172,15 b' Create an extension to test bundle2 API' | |||||
171 | > finally: |
|
172 | > finally: | |
172 | > file.flush() |
|
173 | > file.flush() | |
173 | > |
|
174 | > | |
174 | > @command(b'unbundle2', [], '') |
|
175 | > @command(b'unbundle2', [], b'') | |
175 | > def cmdunbundle2(ui, repo, replypath=None): |
|
176 | > def cmdunbundle2(ui, repo, replypath=None): | |
176 | > """process a bundle2 stream from stdin on the current repo""" |
|
177 | > """process a bundle2 stream from stdin on the current repo""" | |
177 | > try: |
|
178 | > try: | |
178 | > tr = None |
|
179 | > tr = None | |
179 | > lock = repo.lock() |
|
180 | > lock = repo.lock() | |
180 | > tr = repo.transaction('processbundle') |
|
181 | > tr = repo.transaction(b'processbundle') | |
181 | > try: |
|
182 | > try: | |
182 |
> unbundler = bundle2.getunbundler(ui, |
|
183 | > unbundler = bundle2.getunbundler(ui, pycompat.stdin) | |
183 | > op = bundle2.processbundle(repo, unbundler, lambda: tr) |
|
184 | > op = bundle2.processbundle(repo, unbundler, lambda: tr) | |
184 | > tr.close() |
|
185 | > tr.close() | |
185 | > except error.BundleValueError as exc: |
|
186 | > except error.BundleValueError as exc: | |
@@ -190,40 +191,40 b' Create an extension to test bundle2 API' | |||||
190 | > if tr is not None: |
|
191 | > if tr is not None: | |
191 | > tr.release() |
|
192 | > tr.release() | |
192 | > lock.release() |
|
193 | > lock.release() | |
193 |
> remains = |
|
194 | > remains = pycompat.stdin.read() | |
194 | > ui.write('%i unread bytes\n' % len(remains)) |
|
195 | > ui.write(b'%i unread bytes\n' % len(remains)) | |
195 | > if op.records['song']: |
|
196 | > if op.records[b'song']: | |
196 | > totalverses = sum(r['verses'] for r in op.records['song']) |
|
197 | > totalverses = sum(r[b'verses'] for r in op.records[b'song']) | |
197 | > ui.write('%i total verses sung\n' % totalverses) |
|
198 | > ui.write(b'%i total verses sung\n' % totalverses) | |
198 | > for rec in op.records['changegroup']: |
|
199 | > for rec in op.records[b'changegroup']: | |
199 | > ui.write('addchangegroup return: %i\n' % rec['return']) |
|
200 | > ui.write(b'addchangegroup return: %i\n' % rec[b'return']) | |
200 | > if op.reply is not None and replypath is not None: |
|
201 | > if op.reply is not None and replypath is not None: | |
201 | > with open(replypath, 'wb') as file: |
|
202 | > with open(replypath, 'wb') as file: | |
202 | > for chunk in op.reply.getchunks(): |
|
203 | > for chunk in op.reply.getchunks(): | |
203 | > file.write(chunk) |
|
204 | > file.write(chunk) | |
204 | > |
|
205 | > | |
205 | > @command(b'statbundle2', [], '') |
|
206 | > @command(b'statbundle2', [], b'') | |
206 | > def cmdstatbundle2(ui, repo): |
|
207 | > def cmdstatbundle2(ui, repo): | |
207 | > """print statistic on the bundle2 container read from stdin""" |
|
208 | > """print statistic on the bundle2 container read from stdin""" | |
208 |
> unbundler = bundle2.getunbundler(ui, |
|
209 | > unbundler = bundle2.getunbundler(ui, pycompat.stdin) | |
209 | > try: |
|
210 | > try: | |
210 | > params = unbundler.params |
|
211 | > params = unbundler.params | |
211 | > except error.BundleValueError as exc: |
|
212 | > except error.BundleValueError as exc: | |
212 | > raise error.Abort('unknown parameters: %s' % exc) |
|
213 | > raise error.Abort(b'unknown parameters: %s' % exc) | |
213 | > ui.write('options count: %i\n' % len(params)) |
|
214 | > ui.write(b'options count: %i\n' % len(params)) | |
214 | > for key in sorted(params): |
|
215 | > for key in sorted(params): | |
215 | > ui.write('- %s\n' % key) |
|
216 | > ui.write(b'- %s\n' % key) | |
216 | > value = params[key] |
|
217 | > value = params[key] | |
217 | > if value is not None: |
|
218 | > if value is not None: | |
218 | > ui.write(' %s\n' % value) |
|
219 | > ui.write(b' %s\n' % value) | |
219 | > count = 0 |
|
220 | > count = 0 | |
220 | > for p in unbundler.iterparts(): |
|
221 | > for p in unbundler.iterparts(): | |
221 | > count += 1 |
|
222 | > count += 1 | |
222 | > ui.write(' :%s:\n' % p.type) |
|
223 | > ui.write(b' :%s:\n' % p.type) | |
223 | > ui.write(' mandatory: %i\n' % len(p.mandatoryparams)) |
|
224 | > ui.write(b' mandatory: %i\n' % len(p.mandatoryparams)) | |
224 | > ui.write(' advisory: %i\n' % len(p.advisoryparams)) |
|
225 | > ui.write(b' advisory: %i\n' % len(p.advisoryparams)) | |
225 | > ui.write(' payload: %i bytes\n' % len(p.read())) |
|
226 | > ui.write(b' payload: %i bytes\n' % len(p.read())) | |
226 | > ui.write('parts count: %i\n' % count) |
|
227 | > ui.write(b'parts count: %i\n' % count) | |
227 | > EOF |
|
228 | > EOF | |
228 | $ cat >> $HGRCPATH << EOF |
|
229 | $ cat >> $HGRCPATH << EOF | |
229 | > [extensions] |
|
230 | > [extensions] |
General Comments 0
You need to be logged in to leave comments.
Login now