peer: introduce real peer classes
authorPeter Arrenbrecht <peter.arrenbrecht@gmail.com>
Fri, 13 Jul 2012 21:47:06 +0200
changeset 17192 1ac628cd7113e993bb54ebe1893a4f0d81fc6405
parent 17191 5884812686f76eeb0c6c4bd100b2ee0f33f8fa6a
child 17193 1d710fe5ee0e99a724311724dda32289b0733c61
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
peer: introduce real peer classes This change separates peer implementations from the repository implementation. localpeer currently is a simple pass-through to localrepository, except for legacy calls, which have already been removed from localpeer. This ensures that the local client code only uses the most modern peer API when talking to local repos. Peers have a .local() method which returns either None or the underlying localrepository (or descendant thereof). Repos have a .peer() method to return a freshly constructed localpeer. The latter is used by hg.peer(), and also to allow folks to pass either a peer or a repo to some generic helper methods. We might want to get rid of .peer() eventually. The only user of locallegacypeer is debugdiscovery, which uses it to pose as a pre-setdiscovery client. But we decided to leave the old API defined in locallegacypeer for clarity and maybe for other uses in the future. It might be nice to actually define the peer API directly in peer.py as stub methods. One problem there is, however, that localpeer implements lock/addchangegroup, whereas the true remote peers implement unbundle. It might be desireable to get rid of this distinction eventually.
hgext/largefiles/proto.py
hgext/largefiles/uisetup.py
mercurial/commands.py
mercurial/hg.py
mercurial/httppeer.py
mercurial/httprepo.py
mercurial/localrepo.py
mercurial/peer.py
mercurial/repo.py
mercurial/sshpeer.py
mercurial/sshrepo.py
mercurial/statichttprepo.py
mercurial/wireproto.py
tests/notcapable
tests/test-wireproto.py
--- a/hgext/largefiles/proto.py
+++ b/hgext/largefiles/proto.py
@@ -1,17 +1,17 @@
 # Copyright 2011 Fog Creek Software
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 import os
 import urllib2
 
-from mercurial import error, httprepo, util, wireproto
+from mercurial import error, httppeer, util, wireproto
 from mercurial.wireproto import batchable, future
 from mercurial.i18n import _
 
 import lfutil
 
 LARGEFILES_REQUIRED_MSG = ('\nThis repository uses the largefiles extension.'
                            '\n\nPlease enable it in your Mercurial config '
                            'file.\n')
@@ -77,17 +77,17 @@ def statlfile(repo, proto, sha):
             fd.close()
 
 def wirereposetup(ui, repo):
     class lfileswirerepository(repo.__class__):
         def putlfile(self, sha, fd):
             # unfortunately, httprepository._callpush tries to convert its
             # input file-like into a bundle before sending it, so we can't use
             # it ...
-            if issubclass(self.__class__, httprepo.httprepository):
+            if issubclass(self.__class__, httppeer.httppeer):
                 res = None
                 try:
                     res = self._call('putlfile', data=fd, sha=sha,
                         headers={'content-type':'application/mercurial-0.1'})
                     d, output = res.split('\n', 1)
                     for l in output.splitlines(True):
                         self.ui.warn(_('remote: '), l, '\n')
                     return int(d)
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -4,17 +4,17 @@
 # Copyright 2010-2011 Unity Technologies
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 '''setup for largefiles extension: uisetup'''
 
 from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \
-    httprepo, localrepo, merge, sshrepo, sshserver, wireproto
+    httppeer, localrepo, merge, sshpeer, sshserver, wireproto
 from mercurial.i18n import _
 from mercurial.hgweb import hgweb_mod, protocol, webcommands
 from mercurial.subrepo import hgsubrepo
 
 import overrides
 import proto
 
 def uisetup(ui):
@@ -138,20 +138,20 @@ def uisetup(ui):
 
     # these let us reject non-largefiles clients and make them display
     # our error messages
     protocol.webproto.refuseclient = proto.webprotorefuseclient
     sshserver.sshserver.refuseclient = proto.sshprotorefuseclient
 
     # can't do this in reposetup because it needs to have happened before
     # wirerepo.__init__ is called
-    proto.ssholdcallstream = sshrepo.sshrepository._callstream
-    proto.httpoldcallstream = httprepo.httprepository._callstream
-    sshrepo.sshrepository._callstream = proto.sshrepocallstream
-    httprepo.httprepository._callstream = proto.httprepocallstream
+    proto.ssholdcallstream = sshpeer.sshpeer._callstream
+    proto.httpoldcallstream = httppeer.httppeer._callstream
+    sshpeer.sshpeer._callstream = proto.sshrepocallstream
+    httppeer.httppeer._callstream = proto.httprepocallstream
 
     # don't die on seeing a repo with the largefiles requirement
     localrepo.localrepository.supported |= set(['largefiles'])
 
     # override some extensions' stuff as well
     for name, module in extensions.extensions():
         if name == 'fetch':
             extensions.wrapcommand(getattr(module, 'cmdtable'), 'fetch',
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -11,17 +11,17 @@ from i18n import _, gettext
 import os, re, difflib, time, tempfile, errno
 import hg, scmutil, util, revlog, extensions, copies, error, bookmarks
 import patch, help, url, encoding, templatekw, discovery
 import archival, changegroup, cmdutil, hbisect
 import sshserver, hgweb, hgweb.server, commandserver
 import merge as mergemod
 import minirst, revset, fileset
 import dagparser, context, simplemerge, graphmod
-import random, setdiscovery, treediscovery, dagutil, pvec
+import random, setdiscovery, treediscovery, dagutil, pvec, localrepo
 import phases, obsolete
 
 table = {}
 
 command = cmdutil.command(table)
 
 # common command options
 
@@ -1784,16 +1784,19 @@ def debugdiscovery(ui, repo, remoteurl="
     # make sure tests are repeatable
     random.seed(12323)
 
     def doit(localheads, remoteheads, remote=remote):
         if opts.get('old'):
             if localheads:
                 raise util.Abort('cannot use localheads with old style '
                                  'discovery')
+            if not util.safehasattr(remote, 'branches'):
+                # enable in-client legacy support
+                remote = localrepo.locallegacypeer(remote.local())
             common, _in, hds = treediscovery.findcommonincoming(repo, remote,
                                                                 force=True)
             common = set(common)
             if not opts.get('nonheads'):
                 ui.write("unpruned common: %s\n" % " ".join([short(n)
                                                             for n in common]))
                 dag = dagutil.revlogdag(repo.changelog)
                 all = dag.ancestorset(dag.internalizeall(common))
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -4,17 +4,17 @@
 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
 from lock import release
 from node import hex, nullid
-import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo, bookmarks
+import localrepo, bundlerepo, httppeer, sshpeer, statichttprepo, bookmarks
 import lock, util, extensions, error, node, scmutil
 import cmdutil, discovery
 import merge as mergemod
 import verify as verifymod
 import errno, os, shutil
 
 def _local(path):
     path = util.expandpath(util.urllocalpath(path))
@@ -60,19 +60,19 @@ def parseurl(path, branches=None):
     if u.fragment:
         branch = u.fragment
         u.fragment = None
     return str(u), (branch, branches or [])
 
 schemes = {
     'bundle': bundlerepo,
     'file': _local,
-    'http': httprepo,
-    'https': httprepo,
-    'ssh': sshrepo,
+    'http': httppeer,
+    'https': httppeer,
+    'ssh': sshpeer,
     'static-http': statichttprepo,
 }
 
 def _peerlookup(path):
     u = util.url(path)
     scheme = u.scheme or 'file'
     thing = schemes.get(scheme) or schemes['file']
     try:
rename from mercurial/httprepo.py
rename to mercurial/httppeer.py
--- a/mercurial/httprepo.py
+++ b/mercurial/httppeer.py
@@ -1,9 +1,9 @@
-# httprepo.py - HTTP repository proxy classes for mercurial
+# httppeer.py - HTTP repository proxy classes for mercurial
 #
 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from node import nullid
@@ -18,17 +18,17 @@ def zgenerator(f):
         for chunk in util.filechunkiter(f):
             while chunk:
                 yield zd.decompress(chunk, 2**18)
                 chunk = zd.unconsumed_tail
     except httplib.HTTPException:
         raise IOError(None, _('connection ended unexpectedly'))
     yield zd.flush()
 
-class httprepository(wireproto.wirerepository):
+class httppeer(wireproto.wirepeer):
     def __init__(self, ui, path):
         self.path = path
         self.caps = None
         self.handler = None
         self.urlopener = None
         u = util.url(path)
         if u.query or u.fragment:
             raise util.Abort(_('unsupported URL component: "%s"') %
@@ -51,28 +51,26 @@ class httprepository(wireproto.wirerepos
     def url(self):
         return self.path
 
     # look up capabilities only when needed
 
     def _fetchcaps(self):
         self.caps = set(self._call('capabilities').split())
 
-    def get_caps(self):
+    def _capabilities(self):
         if self.caps is None:
             try:
                 self._fetchcaps()
             except error.RepoError:
                 self.caps = set()
             self.ui.debug('capabilities: %s\n' %
                           (' '.join(self.caps or ['none'])))
         return self.caps
 
-    capabilities = property(get_caps)
-
     def lock(self):
         raise util.Abort(_('operation not supported over http'))
 
     def _callstream(self, cmd, **args):
         if cmd == 'pushkey':
             args['data'] = ''
         data = args.pop('data', None)
         size = 0
@@ -210,31 +208,31 @@ class httprepository(wireproto.wirerepos
             os.unlink(tempname)
 
     def _abort(self, exception):
         raise exception
 
     def _decompress(self, stream):
         return util.chunkbuffer(zgenerator(stream))
 
-class httpsrepository(httprepository):
+class httpspeer(httppeer):
     def __init__(self, ui, path):
         if not url.has_https:
             raise util.Abort(_('Python support for SSL and HTTPS '
                                'is not installed'))
-        httprepository.__init__(self, ui, path)
+        httppeer.__init__(self, ui, path)
 
 def instance(ui, path, create):
     if create:
         raise util.Abort(_('cannot create new http repository'))
     try:
         if path.startswith('https:'):
-            inst = httpsrepository(ui, path)
+            inst = httpspeer(ui, path)
         else:
-            inst = httprepository(ui, path)
+            inst = httppeer(ui, path)
         try:
             # Try to do useful work when checking compatibility.
             # Usually saves a roundtrip since we want the caps anyway.
             inst._fetchcaps()
         except error.RepoError:
             # No luck, try older compatibility check.
             inst.between([(nullid, nullid)])
         return inst
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1,47 +1,127 @@
 # localrepo.py - read/write repository class for mercurial
 #
 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 from node import bin, hex, nullid, nullrev, short
 from i18n import _
-import repo, changegroup, subrepo, discovery, pushkey, obsolete
+import peer, changegroup, subrepo, discovery, pushkey, obsolete
 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
 import lock, transaction, store, encoding, base85
 import scmutil, util, extensions, hook, error, revset
 import match as matchmod
 import merge as mergemod
 import tags as tagsmod
 from lock import release
 import weakref, errno, os, time, inspect
 propertycache = util.propertycache
 filecache = scmutil.filecache
 
 class storecache(filecache):
     """filecache for files in the store"""
     def join(self, obj, fname):
         return obj.sjoin(fname)
 
-class localrepository(repo.repository):
-    capabilities = set(('lookup', 'changegroupsubset', 'branchmap', 'pushkey',
-                        'known', 'getbundle'))
+MODERNCAPS = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle'))
+LEGACYCAPS = MODERNCAPS.union(set(['changegroupsubset']))
+
+class localpeer(peer.peerrepository):
+    '''peer for a local repo; reflects only the most recent API'''
+
+    def __init__(self, repo, caps=MODERNCAPS):
+        peer.peerrepository.__init__(self)
+        self._repo = repo
+        self.ui = repo.ui
+        self._caps = repo._restrictcapabilities(caps)
+        self.requirements = repo.requirements
+        self.supportedformats = repo.supportedformats
+
+    def close(self):
+        self._repo.close()
+
+    def _capabilities(self):
+        return self._caps
+
+    def local(self):
+        return self._repo
+
+    def cancopy(self):
+        return self._repo.cancopy() # so bundlerepo can override
+
+    def url(self):
+        return self._repo.url()
+
+    def lookup(self, key):
+        return self._repo.lookup(key)
+
+    def branchmap(self):
+        return self._repo.branchmap()
+
+    def heads(self):
+        return self._repo.heads()
+
+    def known(self, nodes):
+        return self._repo.known(nodes)
+
+    def getbundle(self, source, heads=None, common=None):
+        return self._repo.getbundle(source, heads=heads, common=common)
+
+    # TODO We might want to move the next two calls into legacypeer and add
+    # unbundle instead.
+
+    def lock(self):
+        return self._repo.lock()
+
+    def addchangegroup(self, cg, source, url):
+        return self._repo.addchangegroup(cg, source, url)
+
+    def pushkey(self, namespace, key, old, new):
+        return self._repo.pushkey(namespace, key, old, new)
+
+    def listkeys(self, namespace):
+        return self._repo.listkeys(namespace)
+
+    def debugwireargs(self, one, two, three=None, four=None, five=None):
+        '''used to test argument passing over the wire'''
+        return "%s %s %s %s %s" % (one, two, three, four, five)
+
+class locallegacypeer(localpeer):
+    '''peer extension which implements legacy methods too; used for tests with
+    restricted capabilities'''
+
+    def __init__(self, repo):
+        localpeer.__init__(self, repo, caps=LEGACYCAPS)
+
+    def branches(self, nodes):
+        return self._repo.branches(nodes)
+
+    def between(self, pairs):
+        return self._repo.between(pairs)
+
+    def changegroup(self, basenodes, source):
+        return self._repo.changegroup(basenodes, source)
+
+    def changegroupsubset(self, bases, heads, source):
+        return self._repo.changegroupsubset(bases, heads, source)
+
+class localrepository(object):
+
     supportedformats = set(('revlogv1', 'generaldelta'))
     supported = supportedformats | set(('store', 'fncache', 'shared',
                                         'dotencode'))
     openerreqs = set(('revlogv1', 'generaldelta'))
     requirements = ['revlogv1']
 
     def _baserequirements(self, create):
         return self.requirements[:]
 
     def __init__(self, baseui, path=None, create=False):
-        repo.repository.__init__(self)
         self.wopener = scmutil.opener(path, expand=True)
         self.wvfs = self.wopener
         self.root = self.wvfs.base
         self.path = self.wvfs.join(".hg")
         self.origroot = path
         self.auditor = scmutil.pathauditor(self.root, self._checknested)
         self.opener = scmutil.opener(self.path)
         self.vfs = self.opener
@@ -121,16 +201,22 @@ class localrepository(repo.repository):
         self._transref = self._lockref = self._wlockref = None
 
         # A cache for various files under .hg/ that tracks file changes,
         # (used by the filecache decorator)
         #
         # Maps a property name to its util.filecacheentry
         self._filecache = {}
 
+    def close(self):
+        pass
+
+    def _restrictcapabilities(self, caps):
+        return caps
+
     def _applyrequirements(self, requirements):
         self.requirements = requirements
         self.sopener.options = dict((r, 1) for r in requirements
                                            if r in self.openerreqs)
 
     def _writerequirements(self):
         reqfile = self.opener("requires", "w")
         for r in self.requirements:
@@ -170,16 +256,19 @@ class localrepository(repo.repository):
                     return True
                 else:
                     sub = ctx.sub(prefix)
                     return sub.checknested(subpath[len(prefix) + 1:])
             else:
                 parts.pop()
         return False
 
+    def peer(self):
+        return localpeer(self) # not cached to avoid reference cycle
+
     @filecache('bookmarks')
     def _bookmarks(self):
         return bookmarks.read(self)
 
     @filecache('bookmarks.current')
     def _bookmarkcurrent(self):
         return bookmarks.readcurrent(self)
 
@@ -663,16 +752,19 @@ class localrepository(repo.repository):
             r = nm.get(n)
             resp = not (r is None or pc.phase(self, r) >= phases.secret)
             result.append(resp)
         return result
 
     def local(self):
         return self
 
+    def cancopy(self):
+        return self.local() # so statichttprepo's override of local() works
+
     def join(self, f):
         return os.path.join(self.path, f)
 
     def wjoin(self, f):
         return os.path.join(self.root, f)
 
     def file(self, f):
         if f[0] == '/':
rename from mercurial/repo.py
rename to mercurial/peer.py
--- a/mercurial/repo.py
+++ b/mercurial/peer.py
@@ -1,43 +1,49 @@
-# repo.py - repository base classes for mercurial
+# peer.py - repository base classes for mercurial
 #
 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
 import error
 
-class repository(object):
+class peerrepository(object):
+
     def capable(self, name):
         '''tell whether repo supports named capability.
         return False if not supported.
         if boolean capability, return True.
         if string capability, return string.'''
-        if name in self.capabilities:
+        caps = self._capabilities()
+        if name in caps:
             return True
         name_eq = name + '='
-        for cap in self.capabilities:
+        for cap in caps:
             if cap.startswith(name_eq):
                 return cap[len(name_eq):]
         return False
 
     def requirecap(self, name, purpose):
         '''raise an exception if the given capability is not present'''
         if not self.capable(name):
             raise error.CapabilityError(
                 _('cannot %s; remote repository does not '
                   'support the %r capability') % (purpose, name))
 
     def local(self):
-        return False
+        '''return peer as a localrepo, or None'''
+        return None
+
+    def peer(self):
+        return self
 
     def peer(self):
         return self
 
     def cancopy(self):
-        return self.local()
+        return False
 
     def close(self):
         pass
rename from mercurial/sshrepo.py
rename to mercurial/sshpeer.py
--- a/mercurial/sshrepo.py
+++ b/mercurial/sshpeer.py
@@ -1,9 +1,9 @@
-# sshrepo.py - ssh repository proxy class for mercurial
+# sshpeer.py - ssh repository proxy class for mercurial
 #
 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 import re
 from i18n import _
@@ -20,17 +20,17 @@ class remotelock(object):
             self.release()
 
 def _serverquote(s):
     '''quote a string for the remote shell ... which we assume is sh'''
     if re.match('[a-zA-Z0-9@%_+=:,./-]*$', s):
         return s
     return "'%s'" % s.replace("'", "'\\''")
 
-class sshrepository(wireproto.wirerepository):
+class sshpeer(wireproto.wirepeer):
     def __init__(self, ui, path, create=False):
         self._url = path
         self.ui = ui
         self.pipeo = self.pipei = self.pipee = None
 
         u = util.url(path, parsequery=False, parsefragment=False)
         if u.scheme != 'ssh' or not u.host or u.path is None:
             self._abort(error.RepoError(_("couldn't parse location %s") % path))
@@ -85,22 +85,25 @@ class sshrepository(wireproto.wirereposi
             if l:
                 ui.debug("remote: ", l)
             lines.append(l)
             max_noise -= 1
         else:
             self._abort(error.RepoError(_('no suitable response from '
                                           'remote hg')))
 
-        self.capabilities = set()
+        self._caps = set()
         for l in reversed(lines):
             if l.startswith("capabilities:"):
-                self.capabilities.update(l[:-1].split(":")[1].split())
+                self._caps.update(l[:-1].split(":")[1].split())
                 break
 
+    def _capabilities(self):
+        return self._caps
+
     def readerr(self):
         while True:
             size = util.fstat(self.pipee).st_size
             if size == 0:
                 break
             s = self.pipee.read(size)
             if not s:
                 break
@@ -228,9 +231,9 @@ class sshrepository(wireproto.wirereposi
         r = self._recv()
         if not r:
             return 1
         try:
             return int(r)
         except ValueError:
             self._abort(error.ResponseError(_("unexpected response:"), r))
 
-instance = sshrepository
+instance = sshpeer
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -71,16 +71,20 @@ def build_opener(ui, authinfo):
         def __call__(self, path, mode="r", atomictemp=None):
             if mode not in ('r', 'rb'):
                 raise IOError('Permission denied')
             f = "/".join((self.base, urllib.quote(path)))
             return httprangereader(f, urlopener)
 
     return statichttpopener
 
+class statichttppeer(localrepo.localpeer):
+    def local(self):
+        return None
+
 class statichttprepository(localrepo.localrepository):
     def __init__(self, ui, path):
         self._url = path
         self.ui = ui
 
         self.root = path
         u = util.url(path.rstrip('/') + "/.hg")
         self.path, authinfo = u.authinfo()
@@ -111,32 +115,38 @@ class statichttprepository(localrepo.loc
 
         # setup store
         self.store = store.store(requirements, self.path, opener)
         self.spath = self.store.path
         self.sopener = self.store.opener
         self.svfs = self.sopener
         self.sjoin = self.store.join
         self._filecache = {}
+        self.requirements = requirements
 
         self.manifest = manifest.manifest(self.sopener)
         self.changelog = changelog.changelog(self.sopener)
         self._tags = None
         self.nodetagscache = None
         self._branchcache = None
         self._branchcachetip = None
         self.encodepats = None
         self.decodepats = None
-        self.capabilities.difference_update(["pushkey"])
+
+    def _restrictcapabilities(self, caps):
+        return caps.difference(["pushkey"])
 
     def url(self):
         return self._url
 
     def local(self):
         return False
 
+    def peer(self):
+        return statichttppeer(self)
+
     def lock(self, wait=True):
         raise util.Abort(_('cannot lock static-http repository'))
 
 def instance(ui, path, create):
     if create:
         raise util.Abort(_('cannot create new static-http repository'))
     return statichttprepository(ui, path[7:])
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -4,17 +4,17 @@
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 import urllib, tempfile, os, sys
 from i18n import _
 from node import bin, hex
 import changegroup as changegroupmod
-import repo, error, encoding, util, store
+import peer, error, encoding, util, store
 import phases
 
 # abstract batching support
 
 class future(object):
     '''placeholder for a value to be set later'''
     def set(self, value):
         if util.safehasattr(self, 'value'):
@@ -144,17 +144,17 @@ def unescapearg(escaped):
             .replace(':,', ',')
             .replace('::', ':'))
 
 # client side
 
 def todict(**args):
     return args
 
-class wirerepository(repo.repository):
+class wirepeer(peer.peerrepository):
 
     def batch(self):
         return remotebatch(self)
     def _submitbatch(self, req):
         cmds = []
         for op, argsdict in req:
             args = ','.join('%s=%s' % p for p in argsdict.iteritems())
             cmds.append('%s %s' % (op, args))
--- a/tests/notcapable
+++ b/tests/notcapable
@@ -1,19 +1,24 @@
 # Disable the $CAP wire protocol capability.
 
 if test -z "$CAP"
 then
     echo "CAP environment variable not set."
 fi
 
 cat > notcapable-$CAP.py << EOF
-from mercurial import extensions, repo
+from mercurial import extensions, peer, localrepo
 def extsetup():
-    extensions.wrapfunction(repo.repository, 'capable', wrapper)
-def wrapper(orig, self, name, *args, **kwargs):
+    extensions.wrapfunction(peer.peerrepository, 'capable', wrapcapable)
+    extensions.wrapfunction(localrepo.localrepository, 'peer', wrappeer)
+def wrapcapable(orig, self, name, *args, **kwargs):
     if name in '$CAP'.split(' '):
         return False
     return orig(self, name, *args, **kwargs)
+def wrappeer(orig, self):
+    # Since we're disabling some newer features, we need to make sure local
+    # repos add in the legacy features again.
+    return localrepo.locallegacypeer(self)
 EOF
 
 echo '[extensions]' >> $HGRCPATH
 echo "notcapable-$CAP = `pwd`/notcapable-$CAP.py" >> $HGRCPATH
--- a/tests/test-wireproto.py
+++ b/tests/test-wireproto.py
@@ -4,17 +4,17 @@ class proto(object):
     def __init__(self, args):
         self.args = args
     def getargs(self, spec):
         args = self.args
         args.setdefault('*', {})
         names = spec.split()
         return [args[n] for n in names]
 
-class clientrepo(wireproto.wirerepository):
+class clientpeer(wireproto.wirepeer):
     def __init__(self, serverrepo):
         self.serverrepo = serverrepo
     def _call(self, cmd, **args):
         return wireproto.dispatch(self.serverrepo, proto(args), cmd)
 
     @wireproto.batchable
     def greet(self, name):
         f = wireproto.future()
@@ -31,15 +31,15 @@ def unmangle(s):
     return ''.join(chr(ord(c) - 1) for c in s)
 
 def greet(repo, proto, name):
     return mangle(repo.greet(unmangle(name)))
 
 wireproto.commands['greet'] = (greet, 'name',)
 
 srv = serverrepo()
-clt = clientrepo(srv)
+clt = clientpeer(srv)
 
 print clt.greet("Foobar")
 b = clt.batch()
 fs = [b.greet(s) for s in ["Fo, =;o", "Bar"]]
 b.submit()
 print [f.value for f in fs]