comparison hgext/clonebundles.py @ 26857:e5a1df51bb25 stable

wireproto: move clonebundles command from extension (issue4931) The SSH peer class accesses wireproto.commands[cmd] as part of encoding command arguments. Previously, the wire protocol command was defined in the clonebundles extension. If the client didn't have this extension enabled (which it likely doesn't since it is meant as a server-side extension), then clients attempting to clone via ssh:// would get a crash due to a KeyError accessing wireproto.commands['clonebundles'] when cloning from a server that is advertising clone bundles. Moving the definition of the wire protocol command to wireproto.py makes this problem go away. A side effect of this code move is servers will always respond to "clonebundles" wire protocol command requests. This should be fine: the server will return an empty response unless a clone bundles manifest file is present and clients shouldn't call the command unless the server is advertising the capability, which only happens if the clonebundles extension is enabled and the manifest file exists.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 03 Nov 2015 12:31:33 -0800
parents 26f622859288
children 762bf510b42c
comparison
equal deleted inserted replaced
26856:baa77652be68 26857:e5a1df51bb25
209 if repo.opener.exists('clonebundles.manifest'): 209 if repo.opener.exists('clonebundles.manifest'):
210 caps.append('clonebundles') 210 caps.append('clonebundles')
211 211
212 return caps 212 return caps
213 213
214 @wireproto.wireprotocommand('clonebundles', '')
215 def bundles(repo, proto):
216 """Server command for returning info for available bundles to seed clones.
217
218 Clients will parse this response and determine what bundle to fetch.
219
220 Other extensions may wrap this command to filter or dynamically emit
221 data depending on the request. e.g. you could advertise URLs for
222 the closest data center given the client's IP address.
223 """
224 return repo.opener.tryread('clonebundles.manifest')
225
226 @exchange.getbundle2partsgenerator('clonebundlesadvertise', 0) 214 @exchange.getbundle2partsgenerator('clonebundlesadvertise', 0)
227 def advertiseclonebundlespart(bundler, repo, source, bundlecaps=None, 215 def advertiseclonebundlespart(bundler, repo, source, bundlecaps=None,
228 b2caps=None, heads=None, common=None, 216 b2caps=None, heads=None, common=None,
229 cbattempted=None, **kwargs): 217 cbattempted=None, **kwargs):
230 """Inserts an output part to advertise clone bundles availability.""" 218 """Inserts an output part to advertise clone bundles availability."""