[PATCH RFC] peer: introduce real peer classes

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Thu Sep 1 10:42:52 CDT 2011


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1314891684 -7200
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.

hg.repository() now raises an exception if the supplied path does not
resolve to a localrepo or descendant.

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.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2046,24 +2046,25 @@
         return url + '/.hg/patches'
     if dest is None:
         dest = hg.defaultdest(source)
-    sr = hg.repository(hg.remoteui(ui, opts), ui.expandpath(source))
+    sr = hg.peer(ui, opts, ui.expandpath(source))
     if opts.get('patches'):
         patchespath = ui.expandpath(opts.get('patches'))
     else:
         patchespath = patchdir(sr)
     try:
-        hg.repository(ui, patchespath)
+        hg.peer(ui, opts, patchespath)
     except error.RepoError:
         raise util.Abort(_('versioned patch repository not found'
                            ' (see init --mq)'))
     qbase, destrev = None, None
     if sr.local():
-        if sr.mq.applied:
-            qbase = sr.mq.applied[0].node
+        repo = sr.local()
+        if repo.mq.applied:
+            qbase = repo.mq.applied[0].node
             if not hg.islocal(dest):
-                heads = set(sr.heads())
-                destrev = list(heads.difference(sr.heads(qbase)))
-                destrev.append(sr.changelog.parents(qbase)[0])
+                heads = set(repo.heads())
+                destrev = list(heads.difference(repo.heads(qbase)))
+                destrev.append(repo.changelog.parents(qbase)[0])
     elif sr.capable('lookup'):
         try:
             qbase = sr.lookup('qbase')
@@ -2080,13 +2081,14 @@
              pull=opts.get('pull'), update=not opts.get('noupdate'),
              stream=opts.get('uncompressed'))
     if dr.local():
+        repo = dr.local()
         if qbase:
             ui.note(_('stripping applied patches from destination '
                       'repository\n'))
-            dr.mq.strip(dr, [qbase], update=False, backup=None)
+            repo.mq.strip(repo, [qbase], update=False, backup=None)
         if not opts.get('noupdate'):
             ui.note(_('updating destination repository\n'))
-            hg.update(dr, dr.changelog.tip())
+            hg.update(repo, repo.changelog.tip())
 
 @command("qcommit|qci",
          commands.table["^commit|ci"][1],
diff --git a/hgext/relink.py b/hgext/relink.py
--- a/hgext/relink.py
+++ b/hgext/relink.py
@@ -41,8 +41,6 @@
         raise util.Abort(_('hardlinks are not supported on this system'))
     src = hg.repository(ui, ui.expandpath(origin or 'default-relink',
                                           origin or 'default'))
-    if not src.local():
-        raise util.Abort(_('must specify local origin repository'))
     ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
     if repo.root == src.root:
         ui.status(_('there is nothing to relink\n'))
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -128,7 +128,7 @@
                         continue
                     if pulls:
                         if source != repo:
-                            repo.pull(source, heads=pulls)
+                            repo.pull(source.peer(), heads=pulls)
                         merge.update(repo, pulls[-1], False, False, None)
                         p1, p2 = repo.dirstate.parents()
                         pulls = []
@@ -173,7 +173,7 @@
                         if patchfile:
                             os.unlink(patchfile)
             if pulls:
-                repo.pull(source, heads=pulls)
+                repo.pull(source.peer(), heads=pulls)
                 merge.update(repo, pulls[-1], False, False, None)
         finally:
             self.saveseries(revmap, merges)
@@ -562,9 +562,9 @@
 
     sourcerepo = opts.get('source')
     if sourcerepo:
-        source = hg.peer(ui, opts, ui.expandpath(sourcerepo))
-        branches = map(source.lookup, opts.get('branch', ()))
-        source, csets, cleanupfn = bundlerepo.getremotechanges(ui, repo, source,
+        peer = hg.peer(ui, opts, ui.expandpath(sourcerepo))
+        branches = map(peer.lookup, opts.get('branch', ()))
+        source, csets, cleanupfn = bundlerepo.getremotechanges(ui, repo, peer,
                                     onlyheads=branches, force=True)
     else:
         source = repo
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -322,8 +322,8 @@
 
     bundle = None
     bundlerepo = None
-    localrepo = other
-    if bundlename or not other.local():
+    localrepo = other.local()
+    if bundlename or not localrepo:
         # create a bundle (uncompressed if other repo is not local)
 
         if other.capable('getbundle'):
@@ -334,12 +334,12 @@
             rheads = None
         else:
             cg = other.changegroupsubset(incoming, rheads, 'incoming')
-        bundletype = other.local() and "HG10BZ" or "HG10UN"
+        bundletype = localrepo and "HG10BZ" or "HG10UN"
         fname = bundle = changegroup.writebundle(cg, bundlename, bundletype)
         # keep written bundle?
         if bundlename:
             bundle = None
-        if not other.local():
+        if not localrepo:
             # use the created uncompressed bundlerepo
             localrepo = bundlerepo = bundlerepository(ui, repo.root, fname)
             # this repo contains local and other now, so filter out local again
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -16,7 +16,7 @@
 import merge as mergemod
 import minirst, revset, fileset
 import dagparser, context, simplemerge
-import random, setdiscovery, treediscovery, dagutil
+import random, setdiscovery, treediscovery, dagutil, localrepo
 
 table = {}
 
@@ -1558,10 +1558,13 @@
     # make sure tests are repeatable
     random.seed(12323)
 
-    def doit(localheads, remoteheads):
+    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)
@@ -2928,10 +2931,11 @@
 
     if source:
         source, branches = hg.parseurl(ui.expandpath(source))
-        repo = hg.peer(ui, {}, source)
-        revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
-
-    if not repo.local():
+        peer = hg.peer(ui, {}, source)
+        repo = peer.local()
+        revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
+
+    if not repo:
         if num or branch or tags:
             raise util.Abort(
                 _("can't query remote revision number, branch, or tags"))
@@ -2940,16 +2944,16 @@
         if not rev:
             rev = "tip"
 
-        remoterev = repo.lookup(rev)
+        remoterev = peer.lookup(rev)
         if default or id:
             output = [hexfunc(remoterev)]
 
         def getbms():
             bms = []
 
-            if 'bookmarks' in repo.listkeys('namespaces'):
+            if 'bookmarks' in peer.listkeys('namespaces'):
                 hexremoterev = hex(remoterev)
-                bms = [bm for bm, bmr in repo.listkeys('bookmarks').iteritems()
+                bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems()
                        if bmr == hexremoterev]
 
             return bms
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -9,7 +9,7 @@
 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
 import cmdutil, discovery
 import merge as mergemod
@@ -20,21 +20,22 @@
     path = util.expandpath(util.urllocalpath(path))
     return (os.path.isfile(path) and bundlerepo or localrepo)
 
-def addbranchrevs(lrepo, repo, branches, revs):
+def addbranchrevs(lrepo, other, branches, revs):
+    peer = other.peer() # a courtesy to callers using a localrepo for other
     hashbranch, branches = branches
     if not hashbranch and not branches:
         return revs or None, revs and revs[0] or None
     revs = revs and list(revs) or []
-    if not repo.capable('branchmap'):
+    if not peer.capable('branchmap'):
         if branches:
             raise util.Abort(_("remote branch lookup not supported"))
         revs.append(hashbranch)
         return revs, revs[0]
-    branchmap = repo.branchmap()
+    branchmap = peer.branchmap()
 
     def primary(branch):
         if branch == '.':
-            if not lrepo or not lrepo.local():
+            if not lrepo:
                 raise util.Abort(_("dirstate branch not accessible"))
             branch = lrepo.dirstate.branch()
         if branch in branchmap:
@@ -64,9 +65,9 @@
 schemes = {
     'bundle': bundlerepo,
     'file': _local,
-    'http': httprepo,
-    'https': httprepo,
-    'ssh': sshrepo,
+    'http': httppeer,
+    'https': httppeer,
+    'ssh': sshpeer,
     'static-http': statichttprepo,
 }
 
@@ -88,20 +89,28 @@
             return False
     return repo.local()
 
-def repository(ui, path='', create=False):
+def _peerorrepo(ui, path, create=False):
     """return a repository object for the specified path"""
-    repo = _peerlookup(path).instance(ui, path, create)
-    ui = getattr(repo, "ui", ui)
+    obj = _peerlookup(path).instance(ui, path, create)
+    ui = getattr(obj, "ui", ui)
     for name, module in extensions.extensions():
         hook = getattr(module, 'reposetup', None)
         if hook:
-            hook(ui, repo)
+            hook(ui, obj)
+    return obj
+
+def repository(ui, path='', create=False):
+    """return a repository object for the specified path"""
+    peer = _peerorrepo(ui, path, create)
+    repo = peer.local()
+    if not repo:
+        raise util.Abort(_("repository '%s' is not local") % (path or peer.url()))
     return repo
 
 def peer(uiorrepo, opts, path, create=False):
     '''return a repository peer for the specified path'''
     rui = remoteui(uiorrepo, opts)
-    return repository(rui, path, create)
+    return _peerorrepo(rui, path, create).peer()
 
 def defaultdest(source):
     '''return default destination of clone if none is given'''
@@ -124,7 +133,7 @@
         srcrepo = repository(ui, source)
         rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None)
     else:
-        srcrepo = source
+        srcrepo = source.local()
         origsource = source = srcrepo.url()
         checkout = None
 
@@ -180,7 +189,7 @@
 
     Create a copy of an existing repository in a new directory.  The
     source and destination are URLs, as passed to the repository
-    function.  Returns a pair of repository objects, the source and
+    function.  Returns a pair of repository peers, the source and
     newly created destination.
 
     The location of the source is added to the new repository's
@@ -214,12 +223,12 @@
     if isinstance(source, str):
         origsource = ui.expandpath(source)
         source, branch = parseurl(origsource, branch)
-        srcrepo = repository(remoteui(ui, peeropts), source)
+        srcpeer = peer(ui, peeropts, source)
     else:
-        srcrepo = source
+        srcpeer = source.peer() # in case we were called with a localrepo
         branch = (None, branch or [])
-        origsource = source = srcrepo.url()
-    rev, checkout = addbranchrevs(srcrepo, srcrepo, branch, rev)
+        origsource = source = srcpeer.url()
+    rev, checkout = addbranchrevs(srcpeer, srcpeer, branch, rev)
 
     if dest is None:
         dest = defaultdest(source)
@@ -256,10 +265,11 @@
             dircleanup = DirCleanup(dest)
 
         copy = False
-        if srcrepo.cancopy() and islocal(dest):
+        if srcpeer.cancopy() and islocal(dest):
             copy = not pull and not rev
 
         if copy:
+            srcrepo = srcpeer.local()
             try:
                 # we use a lock here because if we race with commit, we
                 # can end up with extra data in the cloned revlogs that's
@@ -308,13 +318,12 @@
 
             # we need to re-init the repo after manually copying the data
             # into it
-            destrepo = repository(remoteui(ui, peeropts), dest)
+            destpeer = peer(ui, peeropts, dest)
             srcrepo.hook('outgoing', source='clone',
                           node=node.hex(node.nullid))
         else:
             try:
-                destrepo = repository(remoteui(ui, peeropts), dest,
-                                      create=True)
+                destpeer = peer(ui, peeropts, dest, create=True)
             except OSError, inst:
                 if inst.errno == errno.EEXIST:
                     dircleanup.close()
@@ -324,23 +333,24 @@
 
             revs = None
             if rev:
-                if not srcrepo.capable('lookup'):
+                if not srcpeer.capable('lookup'):
                     raise util.Abort(_("src repository does not support "
                                        "revision lookup and so doesn't "
                                        "support clone by revision"))
-                revs = [srcrepo.lookup(r) for r in rev]
+                revs = [srcpeer.lookup(r) for r in rev]
                 checkout = revs[0]
-            if destrepo.local():
-                destrepo.clone(srcrepo, heads=revs, stream=stream)
-            elif srcrepo.local():
-                srcrepo.push(destrepo, revs=revs)
+            if destpeer.local():
+                destpeer.local().clone(srcpeer, heads=revs, stream=stream)
+            elif srcpeer.local():
+                srcpeer.local().push(destpeer, revs=revs)
             else:
                 raise util.Abort(_("clone from remote to remote not supported"))
 
         if dircleanup:
             dircleanup.close()
 
-        if destrepo.local():
+        if destpeer.local():
+            destrepo = destpeer.local()
             fp = destrepo.opener("hgrc", "w", text=True)
             fp.write("[paths]\n")
             fp.write("default = %s\n" % abspath)
@@ -351,8 +361,8 @@
             if update:
                 if update is not True:
                     checkout = update
-                    if srcrepo.local():
-                        checkout = srcrepo.lookup(update)
+                    if srcpeer.local():
+                        checkout = srcpeer.local().lookup(update)
                 for test in (checkout, 'default', 'tip'):
                     if test is None:
                         continue
@@ -366,8 +376,9 @@
                 _update(destrepo, uprev)
 
         # clone all bookmarks
-        if destrepo.local() and srcrepo.capable("pushkey"):
-            rb = srcrepo.listkeys('bookmarks')
+        if destpeer.local() and srcpeer.capable("pushkey"):
+            destrepo = destpeer.local()
+            rb = srcpeer.listkeys('bookmarks')
             for k, n in rb.iteritems():
                 try:
                     m = destrepo.lookup(n)
@@ -376,11 +387,12 @@
                     pass
             if rb:
                 bookmarks.write(destrepo)
-        elif srcrepo.local() and destrepo.capable("pushkey"):
+        elif srcpeer.local() and destpeer.capable("pushkey"):
+            srcrepo = srcpeer.local()
             for k, n in srcrepo._bookmarks.iteritems():
-                destrepo.pushkey('bookmarks', k, '', hex(n))
+                destpeer.pushkey('bookmarks', k, '', hex(n))
 
-        return srcrepo, destrepo
+        return srcpeer, destpeer
     finally:
         release(srclock, destlock)
         if dircleanup is not None:
diff --git a/mercurial/httprepo.py b/mercurial/httppeer.py
rename from mercurial/httprepo.py
rename to mercurial/httppeer.py
--- a/mercurial/httprepo.py
+++ b/mercurial/httppeer.py
@@ -1,4 +1,4 @@
-# httprepo.py - HTTP repository proxy classes for mercurial
+# httppeer.py - HTTP repository proxy classes for mercurial
 #
 # Copyright 2005, 2006 Matt Mackall <mpm at selenic.com>
 # Copyright 2006 Vadim Gelfer <vadim.gelfer at gmail.com>
@@ -23,7 +23,7 @@
         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
@@ -54,7 +54,7 @@
     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()
@@ -64,8 +64,6 @@
                           (' '.join(self.caps or ['none'])))
         return self.caps
 
-    capabilities = property(get_caps)
-
     def lock(self):
         raise util.Abort(_('operation not supported over http'))
 
@@ -211,21 +209,21 @@
     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.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -7,7 +7,7 @@
 
 from node import bin, hex, nullid, nullrev, short
 from i18n import _
-import repo, changegroup, subrepo, discovery, pushkey
+import peer, changegroup, subrepo, discovery, pushkey
 import changelog, dirstate, filelog, manifest, context, bookmarks
 import lock, transaction, store, encoding
 import scmutil, util, extensions, hook, error, revset
@@ -19,15 +19,95 @@
 propertycache = util.propertycache
 filecache = scmutil.filecache
 
-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, lock=None):
+        return self._repo.addchangegroup(cg, source, url, lock=lock)
+
+    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'))
 
     def __init__(self, baseui, path=None, create=False):
-        repo.repository.__init__(self)
         self.root = os.path.realpath(util.expandpath(path))
         self.path = os.path.join(self.root, ".hg")
         self.origroot = path
@@ -110,6 +190,12 @@
         # 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
         openerreqs = set(('revlogv1', 'generaldelta'))
@@ -159,6 +245,9 @@
                 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)
@@ -599,6 +688,9 @@
     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)
 
diff --git a/mercurial/repo.py b/mercurial/peer.py
rename from mercurial/repo.py
rename to mercurial/peer.py
--- a/mercurial/repo.py
+++ b/mercurial/peer.py
@@ -1,4 +1,4 @@
-# repo.py - repository base classes for mercurial
+# peer.py - repository base classes for mercurial
 #
 # Copyright 2005, 2006 Matt Mackall <mpm at selenic.com>
 # Copyright 2006 Vadim Gelfer <vadim.gelfer at gmail.com>
@@ -9,16 +9,18 @@
 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
@@ -31,10 +33,14 @@
                   '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 cancopy(self):
-        return self.local()
+        return False
 
     def close(self):
         pass
diff --git a/mercurial/sshrepo.py b/mercurial/sshpeer.py
rename from mercurial/sshrepo.py
rename to mercurial/sshpeer.py
--- a/mercurial/sshrepo.py
+++ b/mercurial/sshpeer.py
@@ -1,4 +1,4 @@
-# sshrepo.py - ssh repository proxy class for mercurial
+# sshpeer.py - ssh repository proxy class for mercurial
 #
 # Copyright 2005, 2006 Matt Mackall <mpm at selenic.com>
 #
@@ -18,7 +18,7 @@
         if self.repo:
             self.release()
 
-class sshrepository(wireproto.wirerepository):
+class sshpeer(wireproto.wirepeer):
     def __init__(self, ui, path, create=False):
         self._url = path
         self.ui = ui
@@ -81,12 +81,15 @@
         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
@@ -222,4 +225,4 @@
         except ValueError:
             self._abort(error.ResponseError(_("unexpected response:"), r))
 
-instance = sshrepository
+instance = sshpeer
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -75,6 +75,10 @@
 
     return statichttpopener
 
+class statichttppeer(localrepo.localpeer):
+    def local(self):
+        return None
+
 class statichttprepository(localrepo.localrepository):
     def __init__(self, ui, path):
         self._url = path
@@ -111,6 +115,7 @@
         self.spath = self.store.path
         self.sopener = self.store.opener
         self.sjoin = self.store.join
+        self.requirements = requirements
 
         self.manifest = manifest.manifest(self.sopener)
         self.changelog = changelog.changelog(self.sopener)
@@ -120,15 +125,20 @@
         self._branchcachetip = None
         self.encodepats = None
         self.decodepats = None
-        self.capabilities.difference_update(["pushkey"])
         self._filecache = {}
 
+    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'))
 
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -447,8 +447,9 @@
                                      % (subrelpath(self), srcurl))
                 parentrepo = self._repo._subparent
                 shutil.rmtree(self._repo.root)
-                other, self._repo = hg.clone(self._repo._subparent.ui, {}, other,
+                other, cloned = hg.clone(self._repo._subparent.ui, {}, other,
                                          self._repo.root, update=False)
+                self._repo = cloned.local()
                 self._initrepo(parentrepo, source, create=True)
             else:
                 self._repo.ui.status(_('pulling subrepo %s from %s\n')
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -9,7 +9,7 @@
 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 pushkey as pushkeymod
 
 # abstract batching support
@@ -148,7 +148,7 @@
 def todict(**args):
     return args
 
-class wirerepository(repo.repository):
+class wirepeer(peer.peerrepository):
 
     def batch(self):
         return remotebatch(self)
diff --git a/tests/notcapable b/tests/notcapable
--- a/tests/notcapable
+++ b/tests/notcapable
@@ -6,13 +6,18 @@
 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
diff --git a/tests/test-wireproto.py b/tests/test-wireproto.py
--- a/tests/test-wireproto.py
+++ b/tests/test-wireproto.py
@@ -9,7 +9,7 @@
         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):
@@ -36,7 +36,7 @@
 wireproto.commands['greet'] = (greet, 'name',)
 
 srv = serverrepo()
-clt = clientrepo(srv)
+clt = clientpeer(srv)
 
 print clt.greet("Foobar")
 b = clt.batch()


More information about the Mercurial-devel mailing list