[PATCH] bundle2: refactor getbundle a bit

Sune Foldager sune.foldager at me.com
Mon Sep 8 14:22:21 CDT 2014


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1410203835 -7200
#      Mon Sep 08 21:17:15 2014 +0200
# Node ID a2e8d7f1e5a565ca30deb0cf22946d9a1251fdb2
# Parent  1f177bca1fd1149f1a61ccbe1478892b5c6703b3
bundle2: refactor getbundle a bit

This separates the bundle10 and bundle20 parts. Some code is currently
duplicated, but the paths will diverge more in the future.

diff -r 1f177bca1fd1 -r a2e8d7f1e5a5 mercurial/exchange.py
--- a/mercurial/exchange.py	Fri Sep 05 19:54:26 2014 +0200
+++ b/mercurial/exchange.py	Mon Sep 08 21:17:15 2014 +0200
@@ -976,28 +976,27 @@
     The implementation is at a very early stage and will get massive rework
     when the API of bundle is refined.
     """
-    cg = None
-    if kwargs.get('cg', True):
-        # build changegroup bundle here.
-        cg = changegroup.getchangegroup(repo, source, heads=heads,
-                                         common=common, bundlecaps=bundlecaps)
-    elif 'HG2X' not in bundlecaps:
-        raise ValueError(_('request for bundle10 must include changegroup'))
     if bundlecaps is None or 'HG2X' not in bundlecaps:
         if kwargs:
             raise ValueError(_('unsupported getbundle arguments: %s')
                              % ', '.join(sorted(kwargs.keys())))
-        return cg
+        return changegroup.getchangegroup(repo, source, heads=heads,
+                                          common=common, bundlecaps=bundlecaps)
+
     # very crude first implementation,
     # the bundle API will change and the generation will be done lazily.
+    cg = None
     b2caps = {}
     for bcaps in bundlecaps:
         if bcaps.startswith('bundle2='):
             blob = urllib.unquote(bcaps[len('bundle2='):])
             b2caps.update(bundle2.decodecaps(blob))
     bundler = bundle2.bundle20(repo.ui, b2caps)
-    if cg:
-        bundler.newpart('b2x:changegroup', data=cg.getchunks())
+    if kwargs.get('cg', True):
+        cg = changegroup.getchangegroup(repo, source, heads=heads,
+                                        common=common, bundlecaps=bundlecaps)
+        if cg:
+            bundler.newpart('b2x:changegroup', data=cg.getchunks())
     listkeys = kwargs.get('listkeys', ())
     for namespace in listkeys:
         part = bundler.newpart('b2x:listkeys')


More information about the Mercurial-devel mailing list