comparison mercurial/exchange.py @ 20954:dba91f8060eb

bundle2: add an exchange.getbundle function This function can return a `HG10` or `HG20` bundle. It uses the `bundlecaps` parameters to decides which one to return. This is a distinct function from `changegroup.getbundle` for two reasons. First the APIs of `bundle10` and `bundle20` are not compatible yet. The two functions may be reunited in the future. Second `exchange.getbundle` will grow parameters for all kinds of data (phases, obsmarkers, ...) so it's better to keep the changegroup generation in its own function for now. This function will be used it in the next changesets.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 04 Apr 2014 01:51:54 -0700
parents d3775db748a0
children 12f161f08d74
comparison
equal deleted inserted replaced
20953:8d853cad6b14 20954:dba91f8060eb
550 data = base85.b85decode(remoteobs[key]) 550 data = base85.b85decode(remoteobs[key])
551 pullop.repo.obsstore.mergemarkers(tr, data) 551 pullop.repo.obsstore.mergemarkers(tr, data)
552 pullop.repo.invalidatevolatilesets() 552 pullop.repo.invalidatevolatilesets()
553 return tr 553 return tr
554 554
555 def getbundle(repo, source, heads=None, common=None, bundlecaps=None):
556 """return a full bundle (with potentially multiple kind of parts)
557
558 Could be a bundle HG10 or a bundle HG20 depending on bundlecaps
559 passed. For now, the bundle can contain only changegroup, but this will
560 changes when more part type will be available for bundle2.
561
562 This is different from changegroup.getbundle that only returns an HG10
563 changegroup bundle. They may eventually get reunited in the future when we
564 have a clearer idea of the API we what to query different data.
565
566 The implementation is at a very early stage and will get massive rework
567 when the API of bundle is refined.
568 """
569 # build bundle here.
570 cg = changegroup.getbundle(repo, source, heads=heads,
571 common=common, bundlecaps=None)
572 if bundlecaps is None or 'HG20' not in bundlecaps:
573 return cg
574 # very crude first implementation,
575 # the bundle API will change and the generation will be done lazily.
576 bundler = bundle2.bundle20(repo.ui)
577 tempname = changegroup.writebundle(cg, None, 'HG10UN')
578 data = open(tempname).read()
579 part = bundle2.part('changegroup', data=data)
580 bundler.addpart(part)
581 temp = cStringIO.StringIO()
582 for c in bundler.getchunks():
583 temp.write(c)
584 temp.seek(0)
585 return bundle2.unbundle20(repo.ui, temp)