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.
--- a/hgext/clonebundles.py Wed Nov 04 23:48:15 2015 +0900
+++ b/hgext/clonebundles.py Tue Nov 03 12:31:33 2015 -0800
@@ -211,18 +211,6 @@
return caps
-@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,
--- a/mercurial/wireproto.py Wed Nov 04 23:48:15 2015 +0900
+++ b/mercurial/wireproto.py Tue Nov 03 12:31:33 2015 -0800
@@ -549,6 +549,17 @@
r.append(encodelist(b) + "\n")
return "".join(r)
+@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']
--- a/tests/test-clonebundles.t Wed Nov 04 23:48:15 2015 +0900
+++ b/tests/test-clonebundles.t Tue Nov 03 12:31:33 2015 -0800
@@ -224,6 +224,18 @@
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