mercurial/repo.py
changeset 5255 65dc707606ed
parent 4635 63b9d2deed48
child 5455 08d6e8754388
equal deleted inserted replaced
5254:b534c502bfb3 5255:65dc707606ed
     7 # of the GNU General Public License, incorporated herein by reference.
     7 # of the GNU General Public License, incorporated herein by reference.
     8 
     8 
     9 class RepoError(Exception):
     9 class RepoError(Exception):
    10     pass
    10     pass
    11 
    11 
       
    12 class NoCapability(RepoError):
       
    13     pass
       
    14 
    12 class repository(object):
    15 class repository(object):
    13     def capable(self, name):
    16     def capable(self, name):
    14         '''tell whether repo supports named capability.
    17         '''tell whether repo supports named capability.
    15         return False if not supported.
    18         return False if not supported.
    16         if boolean capability, return True.
    19         if boolean capability, return True.
    17         if string capability, return string.'''
    20         if string capability, return string.'''
       
    21         if name in self.capabilities:
       
    22             return True
    18         name_eq = name + '='
    23         name_eq = name + '='
    19         for cap in self.capabilities:
    24         for cap in self.capabilities:
    20             if name == cap:
       
    21                 return True
       
    22             if cap.startswith(name_eq):
    25             if cap.startswith(name_eq):
    23                 return cap[len(name_eq):]
    26                 return cap[len(name_eq):]
    24         return False
    27         return False
       
    28 
       
    29     def requirecap(self, name, purpose):
       
    30         '''raise an exception if the given capability is not present'''
       
    31         if not self.capable(name):
       
    32             raise NoCapability(_('cannot %s; remote repository does not '
       
    33                                  'support the %r capability') %
       
    34                                (purpose, name))