Mercurial > public > mercurial-scm > hg-stable
diff mercurial/repo.py @ 5259:65dc707606ed
Push capability checking into protocol-level code.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Mon, 27 Aug 2007 14:48:08 -0700 |
parents | 63b9d2deed48 |
children | 08d6e8754388 |
line wrap: on
line diff
--- a/mercurial/repo.py Mon Aug 27 14:16:04 2007 -0700 +++ b/mercurial/repo.py Mon Aug 27 14:48:08 2007 -0700 @@ -9,16 +9,26 @@ class RepoError(Exception): pass +class NoCapability(RepoError): + pass + class repository(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: + return True name_eq = name + '=' for cap in self.capabilities: - if name == cap: - return True 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 NoCapability(_('cannot %s; remote repository does not ' + 'support the %r capability') % + (purpose, name))