1 # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 """Subversion-specific errors and conversion of Subversion-specific errors."""
18 from bzrlib.errors import (BzrError, ConnectionError, ConnectionReset,
19 LockError, NotBranchError, PermissionDenied,
20 DependencyNotPresent, NoRepositoryPresent,
21 TransportError, UnexpectedEndOfContainerError)
25 # APR define, not in svn.core
26 SVN_ERR_UNKNOWN_HOSTNAME = 670002
28 class NotSvnBranchPath(NotBranchError):
29 """Error raised when a path was specified that did not exist."""
30 _fmt = """%(path)s is not a valid Subversion branch path.
31 See 'bzr help svn-branching-schemes' for details."""
33 def __init__(self, branch_path, scheme=None):
34 NotBranchError.__init__(self, branch_path)
38 class NoSvnRepositoryPresent(NoRepositoryPresent):
40 def __init__(self, url):
41 BzrError.__init__(self)
45 def convert_error(err):
46 """Convert a Subversion exception to the matching BzrError.
48 :param err: SubversionException.
49 :return: BzrError instance if it could be converted, err otherwise
53 if num == svn.core.SVN_ERR_RA_SVN_CONNECTION_CLOSED:
54 return ConnectionReset(msg=msg)
55 elif num == svn.core.SVN_ERR_WC_LOCKED:
56 return LockError(message=msg)
57 elif num == svn.core.SVN_ERR_RA_NOT_AUTHORIZED:
58 return PermissionDenied('.', msg)
59 elif num == svn.core.SVN_ERR_INCOMPLETE_DATA:
60 return UnexpectedEndOfContainerError()
61 elif num == svn.core.SVN_ERR_RA_SVN_MALFORMED_DATA:
62 return TransportError("Malformed data", msg)
63 elif num == SVN_ERR_UNKNOWN_HOSTNAME:
64 return ConnectionError(msg=msg)
69 def convert_svn_error(unbound):
70 """Decorator that catches particular Subversion exceptions and
71 converts them to Bazaar exceptions.
73 def convert(*args, **kwargs):
75 return unbound(*args, **kwargs)
76 except svn.core.SubversionException, e:
77 raise convert_error(e)
79 convert.__doc__ = unbound.__doc__
80 convert.__name__ = unbound.__name__
84 class NoCheckoutSupport(BzrError):
86 _fmt = 'Subversion version too old for working tree support.'
89 class LocalCommitsUnsupported(BzrError):
91 _fmt = 'Local commits are not supported for lightweight Subversion checkouts.'
94 class InvalidPropertyValue(BzrError):
95 _fmt = 'Invalid property value for Subversion property %(property)s: %(msg)s'
97 def __init__(self, property, msg):
98 BzrError.__init__(self)
99 self.property = property
102 class RebaseNotPresent(DependencyNotPresent):
103 _fmt = "Unable to import bzr-rebase (required for svn-upgrade support): %(error)s"
105 def __init__(self, error):
106 DependencyNotPresent.__init__(self, 'bzr-rebase', error)