comparison mercurial/peer.py @ 17192:1ac628cd7113

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.
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
date Fri, 13 Jul 2012 21:47:06 +0200
parents mercurial/repo.py@5884812686f7
children 1d710fe5ee0e
comparison
equal deleted inserted replaced
17191:5884812686f7 17192:1ac628cd7113
1 # peer.py - repository base classes for mercurial
2 #
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
5 #
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
8
9 from i18n import _
10 import error
11
12 class peerrepository(object):
13
14 def capable(self, name):
15 '''tell whether repo supports named capability.
16 return False if not supported.
17 if boolean capability, return True.
18 if string capability, return string.'''
19 caps = self._capabilities()
20 if name in caps:
21 return True
22 name_eq = name + '='
23 for cap in caps:
24 if cap.startswith(name_eq):
25 return cap[len(name_eq):]
26 return False
27
28 def requirecap(self, name, purpose):
29 '''raise an exception if the given capability is not present'''
30 if not self.capable(name):
31 raise error.CapabilityError(
32 _('cannot %s; remote repository does not '
33 'support the %r capability') % (purpose, name))
34
35 def local(self):
36 '''return peer as a localrepo, or None'''
37 return None
38
39 def peer(self):
40 return self
41
42 def peer(self):
43 return self
44
45 def cancopy(self):
46 return False
47
48 def close(self):
49 pass