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, remote
28 from bzrlib import errors as bzr_errors
31 def get_rich_root_format():
32 format = BzrDirFormat.get_default_format()
33 if format.repository_format.rich_root_data:
35 # Default format does not support rich root data,
36 # fall back to rich-root
37 format = format_registry.make_bzrdir('rich-root-pack')
38 assert format.repository_format.rich_root_data
42 class SvnRemoteFormat(BzrDirFormat):
43 """Format for the Subversion smart server."""
44 _lock_class = TransportLock
47 super(SvnRemoteFormat, self).__init__()
48 from repository import SvnRepositoryFormat
49 self.repository_format = SvnRepositoryFormat()
52 def probe_transport(klass, transport):
53 from transport import get_svn_ra_transport
54 from bzrlib.plugins.svn import core
58 transport = get_svn_ra_transport(transport)
59 except core.SubversionException, (_, num):
60 if num in (errors.ERR_RA_ILLEGAL_URL, \
61 errors.ERR_RA_LOCAL_REPOS_OPEN_FAILED, \
63 raise bzr_errors.NotBranchError(path=transport.base)
67 def _open(self, transport):
68 from bzrlib.plugins.svn.core import SubversionException
70 return remote.SvnRemoteAccess(transport, self)
71 except SubversionException, (_, num):
72 if num == errors.ERR_RA_DAV_REQUEST_FAILED:
73 raise bzr_errors.NotBranchError(transport.base)
76 def get_format_string(self):
77 return 'Subversion Smart Server'
79 def get_format_description(self):
80 return 'Subversion Smart Server'
82 def initialize_on_transport(self, transport):
83 """See BzrDir.initialize_on_transport()."""
84 from transport import get_svn_ra_transport
85 from bzrlib.transport.local import LocalTransport
86 from bzrlib.plugins.svn import repos
88 if not isinstance(transport, LocalTransport):
89 raise NotImplementedError(self.initialize,
90 "Can't create Subversion Repositories/branches on "
91 "non-local transports")
93 local_path = transport._local_base.rstrip("/")
94 repos.create(local_path)
95 # All revision property changes
96 revprop_hook = os.path.join(local_path, "hooks", "pre-revprop-change")
97 open(revprop_hook, 'w').write("#!/bin/sh")
98 os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)
99 return self.open(get_svn_ra_transport(transport), _found=True)
101 def is_supported(self):
102 """See BzrDir.is_supported()."""
106 class SvnWorkingTreeDirFormat(BzrDirFormat):
107 """Working Tree implementation that uses Subversion working copies."""
108 _lock_class = TransportLock
111 super(SvnWorkingTreeDirFormat, self).__init__()
112 from repository import SvnRepositoryFormat
113 self.repository_format = SvnRepositoryFormat()
116 def probe_transport(klass, transport):
117 from bzrlib.transport.local import LocalTransport
118 from bzrlib.plugins.svn import wc
121 if isinstance(transport, LocalTransport) and \
122 transport.has(wc.get_adm_dir()):
125 raise bzr_errors.NotBranchError(path=transport.base)
127 def _open(self, transport):
128 from bzrlib.plugins.svn.core import SubversionException
129 from workingtree import SvnCheckout
131 return SvnCheckout(transport, self)
132 except SubversionException, (_, num):
133 if num in (errors.ERR_RA_LOCAL_REPOS_OPEN_FAILED,):
134 raise errors.NoSvnRepositoryPresent(transport.base)
137 def get_format_string(self):
138 return 'Subversion Local Checkout'
140 def get_format_description(self):
141 return 'Subversion Local Checkout'
143 def initialize_on_transport(self, transport):
144 raise UninitializableFormat(self)
146 def get_converter(self, format=None):
147 """See BzrDirFormat.get_converter()."""
149 format = get_rich_root_format()
150 raise NotImplementedError(self.get_converter)