1 # Copyright (C) 2006-2008 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 3 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.errors import UninitializableFormat
20 from bzrlib.lazy_import import lazy_import
21 from bzrlib.lockable_files import TransportLock
25 lazy_import(globals(), """
26 from bzrlib.plugins.svn import errors
27 from bzrlib.plugins.svn import remote
29 from bzrlib import errors as bzr_errors
32 def get_rich_root_format():
33 format = BzrDirFormat.get_default_format()
34 if format.repository_format.rich_root_data:
36 # Default format does not support rich root data,
37 # fall back to rich-root
38 format = format_registry.make_bzrdir('rich-root-pack')
39 assert format.repository_format.rich_root_data
43 class SvnRemoteFormat(BzrDirFormat):
44 """Format for the Subversion smart server."""
45 _lock_class = TransportLock
48 super(SvnRemoteFormat, self).__init__()
49 from repository import SvnRepositoryFormat
50 self.repository_format = SvnRepositoryFormat()
53 def probe_transport(klass, transport):
54 from transport import get_svn_ra_transport
59 transport = get_svn_ra_transport(transport)
60 except svn.core.SubversionException, (_, num):
61 if num in (errors.ERR_RA_ILLEGAL_URL, \
62 errors.ERR_RA_LOCAL_REPOS_OPEN_FAILED, \
64 raise bzr_errors.NotBranchError(path=transport.base)
68 def _open(self, transport):
71 return remote.SvnRemoteAccess(transport, self)
72 except svn.core.SubversionException, (_, num):
73 if num == errors.ERR_RA_DAV_REQUEST_FAILED:
74 raise bzr_errors.NotBranchError(transport.base)
77 def get_format_string(self):
78 return 'Subversion Smart Server'
80 def get_format_description(self):
81 return 'Subversion Smart Server'
83 def initialize_on_transport(self, transport):
84 """See BzrDir.initialize_on_transport()."""
85 from transport import get_svn_ra_transport
86 from bzrlib.transport.local import LocalTransport
89 if not isinstance(transport, LocalTransport):
90 raise NotImplementedError(self.initialize,
91 "Can't create Subversion Repositories/branches on "
92 "non-local transports")
94 local_path = transport._local_base.rstrip("/")
95 svn.repos.create(local_path, '', '', None, None)
96 # All revision property changes
97 revprop_hook = os.path.join(local_path, "hooks", "pre-revprop-change")
98 open(revprop_hook, 'w').write("#!/bin/sh")
99 os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)
100 return self.open(get_svn_ra_transport(transport), _found=True)
102 def is_supported(self):
103 """See BzrDir.is_supported()."""
107 class SvnWorkingTreeDirFormat(BzrDirFormat):
108 """Working Tree implementation that uses Subversion working copies."""
109 _lock_class = TransportLock
112 super(SvnWorkingTreeDirFormat, self).__init__()
113 from repository import SvnRepositoryFormat
114 self.repository_format = SvnRepositoryFormat()
117 def probe_transport(klass, transport):
119 from bzrlib.transport.local import LocalTransport
122 if isinstance(transport, LocalTransport) and \
123 transport.has(svn.wc.get_adm_dir()):
126 raise bzr_errors.NotBranchError(path=transport.base)
128 def _open(self, transport):
130 from workingtree import SvnCheckout
131 subr_version = svn.core.svn_subr_version()
132 if subr_version.major == 1 and subr_version.minor < 4:
133 raise errors.NoCheckoutSupport()
135 return SvnCheckout(transport, self)
136 except svn.core.SubversionException, (_, num):
137 if num in (errors.ERR_RA_LOCAL_REPOS_OPEN_FAILED,):
138 raise errors.NoSvnRepositoryPresent(transport.base)
141 def get_format_string(self):
142 return 'Subversion Local Checkout'
144 def get_format_description(self):
145 return 'Subversion Local Checkout'
147 def initialize_on_transport(self, transport):
148 raise UninitializableFormat(self)
150 def get_converter(self, format=None):
151 """See BzrDirFormat.get_converter()."""
153 format = get_rich_root_format()
154 raise NotImplementedError(self.get_converter)