comparison mercurial/exchange.py @ 35785:ba15580e53d5

exchange: return bundle info from getbundlechunks() (API) We generally want a mechanism to pass information about the generated bundle back to callers (in addition to the byte stream). Ideally we would return a bundler from this function and have the caller code to an interface. But the bundling APIs are not great and getbundlechunks() is the best API we have for obtaining bundle contents in a unified manner. We change getbundlechunks() to return a dict that we can use to communicate metadata. We populate that dict with the bundle version number to demonstrate some value. .. api:: exchange.getbundlechunks() now returns a 2-tuple instead of just an iterator. Differential Revision: https://phab.mercurial-scm.org/D1925
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 20 Jan 2018 13:41:57 -0800
parents 08cc94dd3d3c
children a84dbc87dae9
comparison
equal deleted inserted replaced
35784:08cc94dd3d3c 35785:ba15580e53d5
1725 """Return chunks constituting a bundle's raw data. 1725 """Return chunks constituting a bundle's raw data.
1726 1726
1727 Could be a bundle HG10 or a bundle HG20 depending on bundlecaps 1727 Could be a bundle HG10 or a bundle HG20 depending on bundlecaps
1728 passed. 1728 passed.
1729 1729
1730 Returns an iterator over raw chunks (of varying sizes). 1730 Returns a 2-tuple of a dict with metadata about the generated bundle
1731 and an iterator over raw chunks (of varying sizes).
1731 """ 1732 """
1732 kwargs = pycompat.byteskwargs(kwargs) 1733 kwargs = pycompat.byteskwargs(kwargs)
1734 info = {}
1733 usebundle2 = bundle2requested(bundlecaps) 1735 usebundle2 = bundle2requested(bundlecaps)
1734 # bundle10 case 1736 # bundle10 case
1735 if not usebundle2: 1737 if not usebundle2:
1736 if bundlecaps and not kwargs.get('cg', True): 1738 if bundlecaps and not kwargs.get('cg', True):
1737 raise ValueError(_('request for bundle10 must include changegroup')) 1739 raise ValueError(_('request for bundle10 must include changegroup'))
1738 1740
1739 if kwargs: 1741 if kwargs:
1740 raise ValueError(_('unsupported getbundle arguments: %s') 1742 raise ValueError(_('unsupported getbundle arguments: %s')
1741 % ', '.join(sorted(kwargs.keys()))) 1743 % ', '.join(sorted(kwargs.keys())))
1742 outgoing = _computeoutgoing(repo, heads, common) 1744 outgoing = _computeoutgoing(repo, heads, common)
1743 return changegroup.makestream(repo, outgoing, '01', source, 1745 info['bundleversion'] = 1
1744 bundlecaps=bundlecaps) 1746 return info, changegroup.makestream(repo, outgoing, '01', source,
1747 bundlecaps=bundlecaps)
1745 1748
1746 # bundle20 case 1749 # bundle20 case
1750 info['bundleversion'] = 2
1747 b2caps = {} 1751 b2caps = {}
1748 for bcaps in bundlecaps: 1752 for bcaps in bundlecaps:
1749 if bcaps.startswith('bundle2='): 1753 if bcaps.startswith('bundle2='):
1750 blob = urlreq.unquote(bcaps[len('bundle2='):]) 1754 blob = urlreq.unquote(bcaps[len('bundle2='):])
1751 b2caps.update(bundle2.decodecaps(blob)) 1755 b2caps.update(bundle2.decodecaps(blob))
1757 for name in getbundle2partsorder: 1761 for name in getbundle2partsorder:
1758 func = getbundle2partsmapping[name] 1762 func = getbundle2partsmapping[name]
1759 func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps, 1763 func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps,
1760 **pycompat.strkwargs(kwargs)) 1764 **pycompat.strkwargs(kwargs))
1761 1765
1762 return bundler.getchunks() 1766 return info, bundler.getchunks()
1763 1767
1764 @getbundle2partsgenerator('stream') 1768 @getbundle2partsgenerator('stream')
1765 def _getbundlestream(bundler, repo, source, bundlecaps=None, 1769 def _getbundlestream(bundler, repo, source, bundlecaps=None,
1766 b2caps=None, heads=None, common=None, **kwargs): 1770 b2caps=None, heads=None, common=None, **kwargs):
1767 if not kwargs.get('stream', False): 1771 if not kwargs.get('stream', False):