1 # Copyright (C) 2006 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
17 from bzrlib.bzrdir import BzrDirFormat, BzrDir
18 from bzrlib.errors import NotBranchError, NotLocalUrl
19 from bzrlib.lockable_files import TransportLock
21 from branch import SvnBranch
22 from repository import SvnRepository
23 from transport import SvnRaTransport
25 from svn.core import SubversionException
28 class SvnRemoteAccess(BzrDir):
29 def __init__(self, _transport, _format):
30 assert isinstance(_transport, SvnRaTransport)
32 self.root_transport = self.transport = _transport
33 self._format = _format
35 self.url = _transport.base
36 self.branch_path = _transport.path
38 def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
39 raise NotImplementedError(SvnRemoteAccess.clone)
41 def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
42 # FIXME: honor force_new_repo
43 result = BzrDirFormat.get_default_format().initialize(url)
44 repo = self.open_repository()
45 result_repo = repo.clone(result, revision_id, basis)
46 branch = self.open_branch()
47 branch.sprout(result, revision_id)
48 result.create_workingtree()
51 def open_repository(self):
52 repos = SvnRepository(self, self.transport.root_url)
53 repos._format = self._format
56 # Subversion has all-in-one, so a repository is always present
57 find_repository = open_repository
59 # Working trees never exist on remote Subversion repositories
60 def open_workingtree(self):
61 raise NotLocalUrl(self.url)
63 def create_workingtree(self, revision_id=None):
65 raise NotImplementedError(self.create_workingtree)
67 def open_branch(self, unsupported=True):
68 repos = self.open_repository()
71 branch = SvnBranch(repos, self.branch_path)
72 except SubversionException, (msg, num):
73 if num == svn.core.SVN_ERR_RA_ILLEGAL_URL or \
74 num == svn.core.SVN_ERR_WC_NOT_DIRECTORY or \
75 num == svn.core.SVN_ERR_RA_NO_REPOS_UUID or \
76 num == svn.core.SVN_ERR_RA_SVN_REPOS_NOT_FOUND or \
77 num == svn.core.SVN_ERR_FS_NOT_FOUND or \
78 num == svn.core.SVN_ERR_RA_DAV_REQUEST_FAILED:
79 raise NotBranchError(path=self.url)
85 class SvnFormat(BzrDirFormat):
86 _lock_class = TransportLock
89 def probe_transport(klass, transport):
92 if isinstance(transport, SvnRaTransport):
95 raise NotBranchError(path=transport.base)
97 def _open(self, transport):
98 return SvnRemoteAccess(transport, self)
100 def get_format_string(self):
101 return 'Subversion Smart Server'
103 def get_format_description(self):
104 return 'Subversion Smart Server'
106 def initialize(self, url):
107 raise NotImplementedError(self.initialize)