##// END OF EJS Templates
exchange: refactor APIs to obtain bundle data (API)...
Gregory Szorc -
r30187:3e86261b default
parent child Browse files
Show More
@@ -1532,20 +1532,14 def bundle2requested(bundlecaps):
1532 1532 return any(cap.startswith('HG2') for cap in bundlecaps)
1533 1533 return False
1534 1534
1535 def getbundle(repo, source, heads=None, common=None, bundlecaps=None,
1535 def getbundlechunks(repo, source, heads=None, common=None, bundlecaps=None,
1536 1536 **kwargs):
1537 """return a full bundle (with potentially multiple kind of parts)
1537 """Return chunks constituting a bundle's raw data.
1538 1538
1539 1539 Could be a bundle HG10 or a bundle HG20 depending on bundlecaps
1540 passed. For now, the bundle can contain only changegroup, but this will
1541 changes when more part type will be available for bundle2.
1540 passed.
1542 1541
1543 This is different from changegroup.getchangegroup that only returns an HG10
1544 changegroup bundle. They may eventually get reunited in the future when we
1545 have a clearer idea of the API we what to query different data.
1546
1547 The implementation is at a very early stage and will get massive rework
1548 when the API of bundle is refined.
1542 Returns an iterator over raw chunks (of varying sizes).
1549 1543 """
1550 1544 usebundle2 = bundle2requested(bundlecaps)
1551 1545 # bundle10 case
@@ -1557,8 +1551,8 def getbundle(repo, source, heads=None,
1557 1551 raise ValueError(_('unsupported getbundle arguments: %s')
1558 1552 % ', '.join(sorted(kwargs.keys())))
1559 1553 outgoing = _computeoutgoing(repo, heads, common)
1560 return changegroup.getchangegroup(repo, source, outgoing,
1561 bundlecaps=bundlecaps)
1554 bundler = changegroup.getbundler('01', repo, bundlecaps)
1555 return changegroup.getsubsetraw(repo, outgoing, bundler, source)
1562 1556
1563 1557 # bundle20 case
1564 1558 b2caps = {}
@@ -1576,7 +1570,7 def getbundle(repo, source, heads=None,
1576 1570 func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps,
1577 1571 **kwargs)
1578 1572
1579 return util.chunkbuffer(bundler.getchunks())
1573 return bundler.getchunks()
1580 1574
1581 1575 @getbundle2partsgenerator('changegroup')
1582 1576 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
@@ -149,14 +149,18 class localpeer(peer.peerrepository):
149 149
150 150 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
151 151 **kwargs):
152 cg = exchange.getbundle(self._repo, source, heads=heads,
153 common=common, bundlecaps=bundlecaps, **kwargs)
152 chunks = exchange.getbundlechunks(self._repo, source, heads=heads,
153 common=common, bundlecaps=bundlecaps,
154 **kwargs)
155 cb = util.chunkbuffer(chunks)
156
154 157 if bundlecaps is not None and 'HG20' in bundlecaps:
155 158 # When requesting a bundle2, getbundle returns a stream to make the
156 159 # wire level function happier. We need to build a proper object
157 160 # from it in local peer.
158 cg = bundle2.getunbundler(self.ui, cg)
159 return cg
161 return bundle2.getunbundler(self.ui, cb)
162 else:
163 return changegroup.getunbundler('01', cb, None)
160 164
161 165 # TODO We might want to move the next two calls into legacypeer and add
162 166 # unbundle instead.
@@ -772,8 +772,10 def getbundle(repo, proto, others):
772 772 if not exchange.bundle2requested(opts.get('bundlecaps')):
773 773 return ooberror(bundle2required)
774 774
775 cg = exchange.getbundle(repo, 'serve', **opts)
776 return streamres(proto.groupchunks(cg))
775 chunks = exchange.getbundlechunks(repo, 'serve', **opts)
776 # TODO avoid util.chunkbuffer() here since it is adding overhead to
777 # what is fundamentally a generator proxying operation.
778 return streamres(proto.groupchunks(util.chunkbuffer(chunks)))
777 779
778 780 @wireprotocommand('heads')
779 781 def heads(repo, proto):
@@ -170,7 +170,7 Get branch and merge:
170 170 $ hg debuggetbundle repo bundle -t bundle2
171 171 $ hg debugbundle bundle
172 172 Stream params: {}
173 changegroup -- "sortdict([('version', '01'), ('nbchanges', '18')])"
173 changegroup -- "sortdict([('version', '01')])"
174 174 7704483d56b2a7b5db54dcee7c62378ac629b348
175 175 29a4d1f17bd3f0779ca0525bebb1cfb51067c738
176 176 713346a995c363120712aed1aee7e04afd867638
General Comments 0
You need to be logged in to leave comments. Login now