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 class ChangesRootLHSHistory(BzrError):
46 _fmt = """changing lhs branch history not possible on repository root"""
49 class MissingPrefix(BzrError):
50 _fmt = """Prefix missing for %(path)s; please create it before pushing. """
52 def __init__(self, path):
53 BzrError.__init__(self)
57 class RevpropChangeFailed(BzrError):
58 _fmt = """Unable to set revision property %(name)s."""
60 def __init__(self, name):
61 BzrError.__init__(self)
65 def convert_error(err):
66 """Convert a Subversion exception to the matching BzrError.
68 :param err: SubversionException.
69 :return: BzrError instance if it could be converted, err otherwise
73 if num == svn.core.SVN_ERR_RA_SVN_CONNECTION_CLOSED:
74 return ConnectionReset(msg=msg)
75 elif num == svn.core.SVN_ERR_WC_LOCKED:
76 return LockError(message=msg)
77 elif num == svn.core.SVN_ERR_RA_NOT_AUTHORIZED:
78 return PermissionDenied('.', msg)
79 elif num == svn.core.SVN_ERR_INCOMPLETE_DATA:
80 return UnexpectedEndOfContainerError()
81 elif num == svn.core.SVN_ERR_RA_SVN_MALFORMED_DATA:
82 return TransportError("Malformed data", msg)
83 elif num == SVN_ERR_UNKNOWN_HOSTNAME:
84 return ConnectionError(msg=msg)
85 elif num > 0 and num < 1000:
86 return OSError(num, msg)
91 def convert_svn_error(unbound):
92 """Decorator that catches particular Subversion exceptions and
93 converts them to Bazaar exceptions.
95 def convert(*args, **kwargs):
97 return unbound(*args, **kwargs)
98 except svn.core.SubversionException, e:
99 raise convert_error(e)
101 convert.__doc__ = unbound.__doc__
102 convert.__name__ = unbound.__name__
106 class NoCheckoutSupport(BzrError):
108 _fmt = 'Subversion version too old for working tree support.'
111 class LocalCommitsUnsupported(BzrError):
113 _fmt = 'Local commits are not supported for lightweight Subversion checkouts.'
116 class InvalidPropertyValue(BzrError):
117 _fmt = 'Invalid property value for Subversion property %(property)s: %(msg)s'
119 def __init__(self, property, msg):
120 BzrError.__init__(self)
121 self.property = property
124 class RebaseNotPresent(DependencyNotPresent):
125 _fmt = "Unable to import bzr-rebase (required for svn-upgrade support): %(error)s"
127 def __init__(self, error):
128 DependencyNotPresent.__init__(self, 'bzr-rebase', error)