1 # Copyright (C) 2006-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 BzrDir formats."""
18 from bzrlib.bzrdir import BzrDirFormat, BzrDir, format_registry
19 from bzrlib.lazy_import import lazy_import
20 from bzrlib.lockable_files import TransportLock
22 lazy_import(globals(), """
26 from bzrlib import errors as bzr_errors
29 def get_rich_root_format():
30 format = BzrDirFormat.get_default_format()
31 if format.repository_format.rich_root_data:
33 # Default format does not support rich root data,
34 # fall back to dirstate-with-subtree
35 format = format_registry.make_bzrdir('dirstate-with-subtree')
36 assert format.repository_format.rich_root_data
40 class SvnRemoteFormat(BzrDirFormat):
41 """Format for the Subversion smart server."""
42 _lock_class = TransportLock
45 super(SvnRemoteFormat, self).__init__()
46 from repository import SvnRepositoryFormat
47 self.repository_format = SvnRepositoryFormat()
50 def probe_transport(klass, transport):
51 from transport import get_svn_ra_transport
56 transport = get_svn_ra_transport(transport)
57 except svn.core.SubversionException, (_, num):
58 if num in (svn.core.SVN_ERR_RA_ILLEGAL_URL, \
59 svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED, \
60 svn.core.SVN_ERR_BAD_URL):
61 raise bzr_errors.NotBranchError(path=transport.base)
65 def _open(self, transport):
68 return remote.SvnRemoteAccess(transport, self)
69 except svn.core.SubversionException, (_, num):
70 if num == svn.core.SVN_ERR_RA_DAV_REQUEST_FAILED:
71 raise bzr_errors.NotBranchError(transport.base)
74 def get_format_string(self):
75 return 'Subversion Smart Server'
77 def get_format_description(self):
78 return 'Subversion Smart Server'
80 def initialize_on_transport(self, transport):
81 """See BzrDir.initialize_on_transport()."""
82 from transport import get_svn_ra_transport
83 from bzrlib.transport.local import LocalTransport
86 if not isinstance(transport, LocalTransport):
87 raise NotImplementedError(self.initialize,
88 "Can't create Subversion Repositories/branches on "
89 "non-local transports")
91 local_path = transport._local_base.rstrip("/")
92 svn.repos.create(local_path, '', '', None, None)
93 return self.open(get_svn_ra_transport(transport), _found=True)
95 def is_supported(self):
96 """See BzrDir.is_supported()."""
100 class SvnWorkingTreeDirFormat(BzrDirFormat):
101 """Working Tree implementation that uses Subversion working copies."""
102 _lock_class = TransportLock
105 super(SvnWorkingTreeDirFormat, self).__init__()
106 from repository import SvnRepositoryFormat
107 self.repository_format = SvnRepositoryFormat()
110 def probe_transport(klass, transport):
112 from bzrlib.transport.local import LocalTransport
115 if isinstance(transport, LocalTransport) and \
116 transport.has(svn.wc.get_adm_dir()):
119 raise bzr_errors.NotBranchError(path=transport.base)
121 def _open(self, transport):
123 from workingtree import SvnCheckout
124 subr_version = svn.core.svn_subr_version()
125 if subr_version.major == 1 and subr_version.minor < 4:
126 raise errors.NoCheckoutSupport()
128 return SvnCheckout(transport, self)
129 except svn.core.SubversionException, (_, num):
130 if num in (svn.core.SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED,):
131 raise errors.NoSvnRepositoryPresent(transport.base)
134 def get_format_string(self):
135 return 'Subversion Local Checkout'
137 def get_format_description(self):
138 return 'Subversion Local Checkout'
140 def initialize_on_transport(self, transport):
141 raise UninitializableFormat(self)
143 def get_converter(self, format=None):
144 """See BzrDirFormat.get_converter()."""
146 format = get_rich_root_format()
147 raise NotImplementedError(self.get_converter)