Mercurial > public > mercurial-scm > hg
comparison mercurial/exchange.py @ 37167:6f467adf9f05
bundle: add the possibility to bundle a stream v2 part
Differential Revision: https://phab.mercurial-scm.org/D1954
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Wed, 31 Jan 2018 11:09:20 +0100 |
parents | 6c7a6b04b274 |
children | a2b350d9f6ae |
comparison
equal
deleted
inserted
replaced
37166:568e9b928c4c | 37167:6f467adf9f05 |
---|---|
239 elif version == 'S1': | 239 elif version == 'S1': |
240 return streamclone.streamcloneapplier(fh) | 240 return streamclone.streamcloneapplier(fh) |
241 else: | 241 else: |
242 raise error.Abort(_('%s: unknown bundle version %s') % (fname, version)) | 242 raise error.Abort(_('%s: unknown bundle version %s') % (fname, version)) |
243 | 243 |
244 def _formatrequirementsspec(requirements): | |
245 return urlreq.quote(','.join(sorted(requirements))) | |
246 | |
247 def _formatrequirementsparams(requirements): | |
248 requirements = _formatrequirementsspec(requirements) | |
249 params = "%s%s" % (urlreq.quote("requirements="), requirements) | |
250 return params | |
251 | |
252 def getbundlespec(ui, fh): | 244 def getbundlespec(ui, fh): |
253 """Infer the bundlespec from a bundle file handle. | 245 """Infer the bundlespec from a bundle file handle. |
254 | 246 |
255 The input file handle is seeked and the original seek position is not | 247 The input file handle is seeked and the original seek position is not |
256 restored. | 248 restored. |
295 'bundle')) | 287 'bundle')) |
296 | 288 |
297 return '%s-%s' % (comp, version) | 289 return '%s-%s' % (comp, version) |
298 elif isinstance(b, streamclone.streamcloneapplier): | 290 elif isinstance(b, streamclone.streamcloneapplier): |
299 requirements = streamclone.readbundle1header(fh)[2] | 291 requirements = streamclone.readbundle1header(fh)[2] |
300 return 'none-packed1;%s' % _formatrequirementsparams(requirements) | 292 formatted = bundle2._formatrequirementsparams(requirements) |
293 return 'none-packed1;%s' % formatted | |
301 else: | 294 else: |
302 raise error.Abort(_('unknown bundle type: %s') % b) | 295 raise error.Abort(_('unknown bundle type: %s') % b) |
303 | 296 |
304 def _computeoutgoing(repo, heads, common): | 297 def _computeoutgoing(repo, heads, common): |
305 """Computes which revs are outgoing given a set of common | 298 """Computes which revs are outgoing given a set of common |
1823 info['prefercompressed'] = bundler.prefercompressed | 1816 info['prefercompressed'] = bundler.prefercompressed |
1824 | 1817 |
1825 return info, bundler.getchunks() | 1818 return info, bundler.getchunks() |
1826 | 1819 |
1827 @getbundle2partsgenerator('stream2') | 1820 @getbundle2partsgenerator('stream2') |
1828 def _getbundlestream2(bundler, repo, source, bundlecaps=None, | 1821 def _getbundlestream2(bundler, repo, *args, **kwargs): |
1829 b2caps=None, heads=None, common=None, **kwargs): | 1822 return bundle2.addpartbundlestream2(bundler, repo, **kwargs) |
1830 if not kwargs.get('stream', False): | |
1831 return | |
1832 | |
1833 if not streamclone.allowservergeneration(repo): | |
1834 raise error.Abort(_('stream data requested but server does not allow ' | |
1835 'this feature'), | |
1836 hint=_('well-behaved clients should not be ' | |
1837 'requesting stream data from servers not ' | |
1838 'advertising it; the client may be buggy')) | |
1839 | |
1840 # Stream clones don't compress well. And compression undermines a | |
1841 # goal of stream clones, which is to be fast. Communicate the desire | |
1842 # to avoid compression to consumers of the bundle. | |
1843 bundler.prefercompressed = False | |
1844 | |
1845 filecount, bytecount, it = streamclone.generatev2(repo) | |
1846 requirements = _formatrequirementsspec(repo.requirements) | |
1847 part = bundler.newpart('stream2', data=it) | |
1848 part.addparam('bytecount', '%d' % bytecount, mandatory=True) | |
1849 part.addparam('filecount', '%d' % filecount, mandatory=True) | |
1850 part.addparam('requirements', requirements, mandatory=True) | |
1851 | 1823 |
1852 @getbundle2partsgenerator('changegroup') | 1824 @getbundle2partsgenerator('changegroup') |
1853 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None, | 1825 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None, |
1854 b2caps=None, heads=None, common=None, **kwargs): | 1826 b2caps=None, heads=None, common=None, **kwargs): |
1855 """add a changegroup part to the requested bundle""" | 1827 """add a changegroup part to the requested bundle""" |