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 repository import SvnRepository
19 from branch import SvnBranch
20 from libsvn._core import SubversionException
21 from bzrlib.errors import NotBranchError, NotLocalUrl
22 from bzrlib.lockable_files import TransportLock
24 from transport import SvnTransport
26 class SvnRemoteAccess(BzrDir):
27 def __init__(self, _transport, _format):
28 self.root_transport = self.transport = _transport
29 self._format = _format
31 assert isinstance(_transport, SvnTransport)
33 self.url = _transport.base
34 self.branch_path = _transport.path
36 def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
37 raise NotImplementedError(SvnRemoteAccess.clone)
39 def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
40 # FIXME: honor force_new_repo
41 result = BzrDirFormat.get_default_format().initialize(url)
42 repo = self.open_repository()
43 result_repo = repo.clone(result, revision_id, basis)
44 branch = self.open_branch()
45 branch.sprout(result,revision_id)
46 result.create_workingtree()
49 def open_repository(self):
50 repos = SvnRepository(self, self.transport.root_url)
51 repos._format = self._format
54 # Subversion has all-in-one, so a repository is always present
55 find_repository = open_repository
57 # Working trees never exist on Subversion repositories
58 def open_workingtree(self):
59 raise NotLocalUrl(self.url)
61 def create_workingtree(self):
62 raise NotImplementedError(SvnRemoteAccess.create_workingtree)
64 def open_branch(self, unsupported=True):
65 repos = self.open_repository()
68 branch = SvnBranch(repos, self.branch_path)
69 except SubversionException, (msg, num):
70 if num == svn.core.SVN_ERR_RA_ILLEGAL_URL or \
71 num == svn.core.SVN_ERR_WC_NOT_DIRECTORY or \
72 num == svn.core.SVN_ERR_RA_NO_REPOS_UUID or \
73 num == svn.core.SVN_ERR_RA_SVN_REPOS_NOT_FOUND or \
74 num == svn.core.SVN_ERR_FS_NOT_FOUND or \
75 num == svn.core.SVN_ERR_RA_DAV_REQUEST_FAILED:
76 raise NotBranchError(path=self.url)
82 class SvnFormat(BzrDirFormat):
83 _lock_class = TransportLock
85 def _open(self, transport):
86 return SvnRemoteAccess(transport, self)
88 def get_format_string(self):
89 return 'Subversion Smart Server'
91 def get_format_description(self):
92 return 'Subversion Smart Server'
94 def initialize(self,url):
95 raise NotImplementedError(SvnFormat.initialize)