##// END OF EJS Templates
exchange: implement function for inferring bundle specification...
Gregory Szorc -
r27883:4f4b80b3 default
parent child Browse files
Show More
@@ -187,6 +187,59 b' def readbundle(ui, fh, fname, vfs=None):'
187 else:
187 else:
188 raise error.Abort(_('%s: unknown bundle version %s') % (fname, version))
188 raise error.Abort(_('%s: unknown bundle version %s') % (fname, version))
189
189
190 def getbundlespec(ui, fh):
191 """Infer the bundlespec from a bundle file handle.
192
193 The input file handle is seeked and the original seek position is not
194 restored.
195 """
196 def speccompression(alg):
197 for k, v in _bundlespeccompressions.items():
198 if v == alg:
199 return k
200 return None
201
202 b = readbundle(ui, fh, None)
203 if isinstance(b, changegroup.cg1unpacker):
204 alg = b._type
205 if alg == '_truncatedBZ':
206 alg = 'BZ'
207 comp = speccompression(alg)
208 if not comp:
209 raise error.Abort(_('unknown compression algorithm: %s') % alg)
210 return '%s-v1' % comp
211 elif isinstance(b, bundle2.unbundle20):
212 if 'Compression' in b.params:
213 comp = speccompression(b.params['Compression'])
214 if not comp:
215 raise error.Abort(_('unknown compression algorithm: %s') % comp)
216 else:
217 comp = 'none'
218
219 version = None
220 for part in b.iterparts():
221 if part.type == 'changegroup':
222 version = part.params['version']
223 if version in ('01', '02'):
224 version = 'v2'
225 else:
226 raise error.Abort(_('changegroup version %s does not have '
227 'a known bundlespec') % version,
228 hint=_('try upgrading your Mercurial '
229 'client'))
230
231 if not version:
232 raise error.Abort(_('could not identify changegroup version in '
233 'bundle'))
234
235 return '%s-%s' % (comp, version)
236 elif isinstance(b, streamclone.streamcloneapplier):
237 requirements = streamclone.readbundle1header(fh)[2]
238 params = 'requirements=%s' % ','.join(sorted(requirements))
239 return 'none-packed1;%s' % urllib.quote(params)
240 else:
241 raise error.Abort(_('unknown bundle type: %s') % b)
242
190 def buildobsmarkerspart(bundler, markers):
243 def buildobsmarkerspart(bundler, markers):
191 """add an obsmarker part to the bundler with <markers>
244 """add an obsmarker part to the bundler with <markers>
192
245
General Comments 0
You need to be logged in to leave comments. Login now