Patchwork [3,of,5,clonebundles,V3] clonebundle: support bundle2

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 13, 2015, 6:54 p.m.
Message ID <2d1cf61c7beca610a09a.1444762448@gps-mbp.local>
Download mbox | patch
Permalink /patch/11022/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 13, 2015, 6:54 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1444758114 25200
#      Tue Oct 13 10:41:54 2015 -0700
# Node ID 2d1cf61c7beca610a09ab49a8fdd2f56db5e7d23
# Parent  770e985c4dd0e46deebcdeecf74f75f2351b86b1
clonebundle: support bundle2

exchange.readbundle() can return 2 different types. We weren't handling
the bundle2 case. Handle it.

At some point we'll likely want a generic API for applying a bundle from
a file handle. For now, create another one-off until we figure out what
the unified bundle API should look like (addressing this is a can of
worms I don't want to open right now).

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1652,9 +1652,13 @@  def trypullbundlefromurl(ui, repo, url):
         try:
             try:
                 fh = urlmod.open(ui, url)
                 cg = readbundle(ui, fh, 'stream')
-                changegroup.addchangegroup(repo, cg, 'clonebundles', url)
+
+                if isinstance(cg, bundle2.unbundle20):
+                    bundle2.processbundle(repo, cg, lambda: tr)
+                else:
+                    changegroup.addchangegroup(repo, cg, 'clonebundles', url)
                 tr.close()
                 return True
             except urllib2.HTTPError as e:
                 ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
diff --git a/tests/test-clonebundles.t b/tests/test-clonebundles.t
--- a/tests/test-clonebundles.t
+++ b/tests/test-clonebundles.t
@@ -127,9 +127,9 @@  Bundle with partial content works
   added 1 changesets with 1 changes to 1 files
 
 Bundle with full content works
 
-  $ hg -R server bundle --type gzip --base null -r tip full.hg
+  $ hg -R server bundle --type gzip-v2 --base null -r tip full.hg
   2 changesets found
 
   $ echo "http://localhost:$HGPORT1/full.hg" > server/.hg/clonebundles.manifest
   $ hg clone -U http://localhost:$HGPORT full-bundle