Mercurial > public > mercurial-scm > hg
comparison mercurial/bundle2.py @ 28666:ae53ecc47414
bundle: move writebundle() from changegroup.py to bundle2.py (API)
writebundle() writes a bundle2 bundle or a plain changegroup1. Imagine
away the "2" in "bundle2.py" for a moment and this change should makes
sense. The bundle wraps the changegroup, so it makes sense that it
knows about it. Another sign that this is correct is that the delayed
import of bundle2 in changegroup goes away.
I'll leave it for another time to remove the "2" in "bundle2.py"
(alternatively, extract a new bundle.py from it).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 28 Mar 2016 14:41:29 -0700 |
parents | 88609cfa3745 |
children | ca4896110011 |
comparison
equal
deleted
inserted
replaced
28655:0e330d7d9f53 | 28666:ae53ecc47414 |
---|---|
471 vals = [urllib.quote(v) for v in vals] | 471 vals = [urllib.quote(v) for v in vals] |
472 if vals: | 472 if vals: |
473 ca = "%s=%s" % (ca, ','.join(vals)) | 473 ca = "%s=%s" % (ca, ','.join(vals)) |
474 chunks.append(ca) | 474 chunks.append(ca) |
475 return '\n'.join(chunks) | 475 return '\n'.join(chunks) |
476 | |
477 bundletypes = { | |
478 "": ("", None), # only when using unbundle on ssh and old http servers | |
479 # since the unification ssh accepts a header but there | |
480 # is no capability signaling it. | |
481 "HG20": (), # special-cased below | |
482 "HG10UN": ("HG10UN", None), | |
483 "HG10BZ": ("HG10", 'BZ'), | |
484 "HG10GZ": ("HG10GZ", 'GZ'), | |
485 } | |
486 | |
487 # hgweb uses this list to communicate its preferred type | |
488 bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN'] | |
476 | 489 |
477 class bundle20(object): | 490 class bundle20(object): |
478 """represent an outgoing bundle2 container | 491 """represent an outgoing bundle2 container |
479 | 492 |
480 Use the `addparam` method to add stream level parameter. and `newpart` to | 493 Use the `addparam` method to add stream level parameter. and `newpart` to |
1263 """extract the list of supported obsmarkers versions from a bundle2caps dict | 1276 """extract the list of supported obsmarkers versions from a bundle2caps dict |
1264 """ | 1277 """ |
1265 obscaps = caps.get('obsmarkers', ()) | 1278 obscaps = caps.get('obsmarkers', ()) |
1266 return [int(c[1:]) for c in obscaps if c.startswith('V')] | 1279 return [int(c[1:]) for c in obscaps if c.startswith('V')] |
1267 | 1280 |
1281 def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None): | |
1282 """Write a bundle file and return its filename. | |
1283 | |
1284 Existing files will not be overwritten. | |
1285 If no filename is specified, a temporary file is created. | |
1286 bz2 compression can be turned off. | |
1287 The bundle file will be deleted in case of errors. | |
1288 """ | |
1289 | |
1290 if bundletype == "HG20": | |
1291 bundle = bundle20(ui) | |
1292 bundle.setcompression(compression) | |
1293 part = bundle.newpart('changegroup', data=cg.getchunks()) | |
1294 part.addparam('version', cg.version) | |
1295 chunkiter = bundle.getchunks() | |
1296 else: | |
1297 # compression argument is only for the bundle2 case | |
1298 assert compression is None | |
1299 if cg.version != '01': | |
1300 raise error.Abort(_('old bundle types only supports v1 ' | |
1301 'changegroups')) | |
1302 header, comp = bundletypes[bundletype] | |
1303 if comp not in util.compressors: | |
1304 raise error.Abort(_('unknown stream compression type: %s') | |
1305 % comp) | |
1306 z = util.compressors[comp]() | |
1307 subchunkiter = cg.getchunks() | |
1308 def chunkiter(): | |
1309 yield header | |
1310 for chunk in subchunkiter: | |
1311 yield z.compress(chunk) | |
1312 yield z.flush() | |
1313 chunkiter = chunkiter() | |
1314 | |
1315 # parse the changegroup data, otherwise we will block | |
1316 # in case of sshrepo because we don't know the end of the stream | |
1317 | |
1318 # an empty chunkgroup is the end of the changegroup | |
1319 # a changegroup has at least 2 chunkgroups (changelog and manifest). | |
1320 # after that, an empty chunkgroup is the end of the changegroup | |
1321 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs) | |
1322 | |
1268 @parthandler('changegroup', ('version', 'nbchanges', 'treemanifest')) | 1323 @parthandler('changegroup', ('version', 'nbchanges', 'treemanifest')) |
1269 def handlechangegroup(op, inpart): | 1324 def handlechangegroup(op, inpart): |
1270 """apply a changegroup part on the repo | 1325 """apply a changegroup part on the repo |
1271 | 1326 |
1272 This is a very early implementation that will massive rework before being | 1327 This is a very early implementation that will massive rework before being |