121
|
1 # repo.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, incorporated herein by reference.
|
|
8
|
|
9 from i18n import _
|
|
10 import error
|
|
11
|
|
12 class repository(object):
|
|
13 def capable(self, name):
|
|
14 '''tell whether repo supports named capability.
|
|
15 return False if not supported.
|
|
16 if boolean capability, return True.
|
|
17 if string capability, return string.'''
|
|
18 if name in self.capabilities:
|
|
19 return True
|
|
20 name_eq = name + '='
|
|
21 for cap in self.capabilities:
|
|
22 if cap.startswith(name_eq):
|
|
23 return cap[len(name_eq):]
|
|
24 return False
|
|
25
|
|
26 def requirecap(self, name, purpose):
|
|
27 '''raise an exception if the given capability is not present'''
|
|
28 if not self.capable(name):
|
|
29 raise error.CapabilityError(
|
|
30 _('cannot %s; remote repository does not '
|
|
31 'support the %r capability') % (purpose, name))
|
|
32
|
|
33 def local(self):
|
|
34 return False
|
|
35
|
|
36 def cancopy(self):
|
|
37 return self.local()
|
|
38
|
|
39 def rjoin(self, path):
|
|
40 url = self.url()
|
|
41 if url.endswith('/'):
|
|
42 return url + path
|
|
43 return url + '/' + path
|