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

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 3, 2015, 8:41 p.m.
Message ID <7c07c5a84f1a012ee240.1446583266@gps-mbp.local>
Download mbox | patch
Permalink /patch/11282/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 3, 2015, 8:41 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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.
Matt Mackall - Nov. 4, 2015, 8:04 p.m.
On Tue, 2015-11-03 at 12:41 -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@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)

Queued for stable, thanks.

Patch

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
 
-@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)
 
+@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