# HG changeset patch # User Gregory Szorc # Date 2015-11-03 20:31:33 # Node ID e5a1df51bb2572ee642bba2261cc479ce6a96ed5 # Parent baa77652be68a56ba69aac36c36fe8823089fce2 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 @@ -211,18 +211,6 @@ def capabilities(orig, repo, proto): 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, diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -549,6 +549,17 @@ def branches(repo, proto, 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 @@ -224,6 +224,18 @@ by old clients. 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