mercurial/repo.py
author Matt Mackall <mpm@selenic.com>
Thu, 11 Oct 2007 00:46:52 -0500
changeset 5449 17a4b20eda7b
parent 5259 65dc707606ed
child 5455 08d6e8754388
permissions -rw-r--r--
chunkiter: handle large reads more efficiently - for large reads, don't attempt to read more than necessary - if we've gathered the exact number of bytes needed, avoid a string copy

# repo.py - repository base classes for mercurial
#
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

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 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))