Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/bundle2.py @ 32261:9dc36df78403
bundle: introduce an higher level function to write bundle on disk
The current function ('writebundle') is focussing on getting an existing
changegroup to disk. It is no easy ways to includes more part in the generated
bundle2. So we introduce a slightly higher level function that is fed the
'outgoing' object (that defines the bundled spec) and the bundlespec parameters
(to control the changegroup generation and inclusion of other parts).
This is creating the third logic dedicated to create a consistent bundle2 (the
other 2 are the push code and the getbundle code). We should probably reconcile
them at some points but they all takes different types of input. So we need to
introduce an intermediate "object" that each different input could be converted
to. Such unified "bundle2 specification" could be fed to some unified code.
We start by having the `hg bundle` related code on its own to helps defines its
specific needs first. Once the common and specific parts of each logic will be
known we can start unification.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 05 May 2017 17:09:47 +0200 |
parents | 76f9a0009b4b |
children | 6068712cbf03 |
comparison
equal
deleted
inserted
replaced
32260:e17b8466857e | 32261:9dc36df78403 |
---|---|
1337 """extract the list of supported obsmarkers versions from a bundle2caps dict | 1337 """extract the list of supported obsmarkers versions from a bundle2caps dict |
1338 """ | 1338 """ |
1339 obscaps = caps.get('obsmarkers', ()) | 1339 obscaps = caps.get('obsmarkers', ()) |
1340 return [int(c[1:]) for c in obscaps if c.startswith('V')] | 1340 return [int(c[1:]) for c in obscaps if c.startswith('V')] |
1341 | 1341 |
1342 def writenewbundle(ui, repo, source, filename, bundletype, outgoing, opts, | |
1343 vfs=None, compression=None, compopts=None): | |
1344 if bundletype.startswith('HG10'): | |
1345 cg = changegroup.getchangegroup(repo, source, outgoing, version='01') | |
1346 return writebundle(ui, cg, filename, bundletype, vfs=vfs, | |
1347 compression=compression, compopts=compopts) | |
1348 elif not bundletype.startswith('HG20'): | |
1349 raise error.ProgrammingError('unknown bundle type: %s' % bundletype) | |
1350 | |
1351 bundle = bundle20(ui) | |
1352 bundle.setcompression(compression, compopts) | |
1353 _addpartsfromopts(ui, repo, bundle, source, outgoing, opts) | |
1354 chunkiter = bundle.getchunks() | |
1355 | |
1356 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs) | |
1357 | |
1358 def _addpartsfromopts(ui, repo, bundler, source, outgoing, opts): | |
1359 # We should eventually reconcile this logic with the one behind | |
1360 # 'exchange.getbundle2partsgenerator'. | |
1361 # | |
1362 # The type of input from 'getbundle' and 'writenewbundle' are a bit | |
1363 # different right now. So we keep them separated for now for the sake of | |
1364 # simplicity. | |
1365 | |
1366 # we always want a changegroup in such bundle | |
1367 cgversion = opts.get('cg.version') | |
1368 if cgversion is None: | |
1369 cgversion = changegroup.safeversion(repo) | |
1370 cg = changegroup.getchangegroup(repo, source, outgoing, | |
1371 version=cgversion) | |
1372 part = bundler.newpart('changegroup', data=cg.getchunks()) | |
1373 part.addparam('version', cg.version) | |
1374 if 'clcount' in cg.extras: | |
1375 part.addparam('nbchanges', str(cg.extras['clcount']), | |
1376 mandatory=False) | |
1377 | |
1342 def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None, | 1378 def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None, |
1343 compopts=None): | 1379 compopts=None): |
1344 """Write a bundle file and return its filename. | 1380 """Write a bundle file and return its filename. |
1345 | 1381 |
1346 Existing files will not be overwritten. | 1382 Existing files will not be overwritten. |