changeset 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 8d853cad6b14
children 12f161f08d74
files mercurial/exchange.py mercurial/localrepo.py
diffstat 2 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/exchange.py	Fri Apr 04 01:33:20 2014 -0700
+++ b/mercurial/exchange.py	Fri Apr 04 01:51:54 2014 -0700
@@ -552,3 +552,34 @@
             pullop.repo.invalidatevolatilesets()
     return tr
 
+def getbundle(repo, source, heads=None, common=None, bundlecaps=None):
+    """return a full bundle (with potentially multiple kind of parts)
+
+    Could be a bundle HG10 or a bundle HG20 depending on bundlecaps
+    passed. For now, the bundle can contain only changegroup, but this will
+    changes when more part type will be available for bundle2.
+
+    This is different from changegroup.getbundle that only returns an HG10
+    changegroup bundle. They may eventually get reunited in the future when we
+    have a clearer idea of the API we what to query different data.
+
+    The implementation is at a very early stage and will get massive rework
+    when the API of bundle is refined.
+    """
+    # build bundle here.
+    cg = changegroup.getbundle(repo, source, heads=heads,
+                               common=common, bundlecaps=None)
+    if bundlecaps is None or 'HG20' not in bundlecaps:
+        return cg
+    # very crude first implementation,
+    # the bundle API will change and the generation will be done lazily.
+    bundler = bundle2.bundle20(repo.ui)
+    tempname = changegroup.writebundle(cg, None, 'HG10UN')
+    data = open(tempname).read()
+    part = bundle2.part('changegroup', data=data)
+    bundler.addpart(part)
+    temp = cStringIO.StringIO()
+    for c in bundler.getchunks():
+        temp.write(c)
+    temp.seek(0)
+    return bundle2.unbundle20(repo.ui, temp)
--- a/mercurial/localrepo.py	Fri Apr 04 01:33:20 2014 -0700
+++ b/mercurial/localrepo.py	Fri Apr 04 01:51:54 2014 -0700
@@ -105,8 +105,8 @@
 
     def getbundle(self, source, heads=None, common=None, bundlecaps=None,
                   format='HG10'):
-        return changegroup.getbundle(self._repo, source, heads=heads,
-                                     common=common, bundlecaps=bundlecaps)
+        return exchange.getbundle(self._repo, source, heads=heads,
+                                  common=common, bundlecaps=bundlecaps)
 
     # TODO We might want to move the next two calls into legacypeer and add
     # unbundle instead.