[PATCH STABLE] wireproto: move clonebundles command from extension (issue4931)

Gregory Szorc gregory.szorc at gmail.com
Tue Nov 3 20:41:06 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1446582693 28800
#      Tue Nov 03 12:31:33 2015 -0800
# Branch stable
# Node ID 7c07c5a84f1a012ee240e7969cef4caedc91c0db
# Parent  2c0a9941100c292b3062ebd37613027f956712c2
wireproto: move clonebundles command from extension (issue4931)

The SSH peer class accesses wireproto.commands[cmd] as part of encoding
command arguments. Previously, the wire protocol command was defined in
the clonebundles extension. If the client didn't have this extension
enabled (which it likely doesn't since it is meant as a server-side
extension), then clients attempting to clone via ssh:// would get a
crash due to a KeyError accessing wireproto.commands['clonebundles']
when cloning from a server that is advertising clone bundles.

Moving the definition of the wire protocol command to wireproto.py makes
this problem go away.

A side effect of this code move is servers will always respond to
"clonebundles" wire protocol command requests. This should be fine: the
server will return an empty response unless a clone bundles manifest
file is present and clients shouldn't call the command unless the server
is advertising the capability, which only happens if the clonebundles
extension is enabled and the manifest file exists.

diff --git a/hgext/clonebundles.py b/hgext/clonebundles.py
--- a/hgext/clonebundles.py
+++ b/hgext/clonebundles.py
@@ -210,20 +210,8 @@ def capabilities(orig, repo, proto):
         caps.append('clonebundles')
 
     return caps
 
- at wireproto.wireprotocommand('clonebundles', '')
-def bundles(repo, proto):
-    """Server command for returning info for available bundles to seed clones.
-
-    Clients will parse this response and determine what bundle to fetch.
-
-    Other extensions may wrap this command to filter or dynamically emit
-    data depending on the request. e.g. you could advertise URLs for
-    the closest data center given the client's IP address.
-    """
-    return repo.opener.tryread('clonebundles.manifest')
-
 @exchange.getbundle2partsgenerator('clonebundlesadvertise', 0)
 def advertiseclonebundlespart(bundler, repo, source, bundlecaps=None,
                               b2caps=None, heads=None, common=None,
                               cbattempted=None, **kwargs):
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -548,8 +548,19 @@ def branches(repo, proto, nodes):
     for b in repo.branches(nodes):
         r.append(encodelist(b) + "\n")
     return "".join(r)
 
+ at wireprotocommand('clonebundles', '')
+def clonebundles(repo, proto):
+    """Server command for returning info for available bundles to seed clones.
+
+    Clients will parse this response and determine what bundle to fetch.
+
+    Extensions may wrap this command to filter or dynamically emit data
+    depending on the request. e.g. you could advertise URLs for the closest
+    data center given the client's IP address.
+    """
+    return repo.opener.tryread('clonebundles.manifest')
 
 wireprotocaps = ['lookup', 'changegroupsubset', 'branchmap', 'pushkey',
                  'known', 'getbundle', 'unbundlehash', 'batch']
 
diff --git a/tests/test-clonebundles.t b/tests/test-clonebundles.t
--- a/tests/test-clonebundles.t
+++ b/tests/test-clonebundles.t
@@ -223,8 +223,20 @@ by old clients.
   finished applying clone bundle
   searching for changes
   no changes found
 
+Feature works over SSH
+
+  $ hg clone -U -e "python \"$TESTDIR/dummyssh\"" ssh://user@dummy/server ssh-full-clone
+  applying clone bundle from http://localhost:$HGPORT1/full.hg
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  finished applying clone bundle
+  searching for changes
+  no changes found
+
 Entry with unknown BUNDLESPEC is filtered and not used
 
   $ cat > server/.hg/clonebundles.manifest << EOF
   > http://bad.entry1 BUNDLESPEC=UNKNOWN


More information about the Mercurial-devel mailing list