Clean up cache list.
[jelmer/subvertpy.git] / format.py
1 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
2
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.
7
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.
12
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."""
17
18 from bzrlib.bzrdir import BzrDirFormat, BzrDir, format_registry
19 from bzrlib.lazy_import import lazy_import
20 from bzrlib.lockable_files import TransportLock
21
22 lazy_import(globals(), """
23 import errors
24 import remote
25
26 from bzrlib import errors as bzr_errors
27 """)
28
29 def get_rich_root_format():
30     format = BzrDirFormat.get_default_format()
31     if format.repository_format.rich_root_data:
32         return format
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
37     return format
38
39
40 class SvnRemoteFormat(BzrDirFormat):
41     """Format for the Subversion smart server."""
42     _lock_class = TransportLock
43
44     def __init__(self):
45         super(SvnRemoteFormat, self).__init__()
46         from repository import SvnRepositoryFormat
47         self.repository_format = SvnRepositoryFormat()
48
49     @classmethod
50     def probe_transport(klass, transport):
51         from transport import get_svn_ra_transport
52         import svn.core
53         format = klass()
54
55         try:
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)
62
63         return format
64
65     def _open(self, transport):
66         import svn.core
67         try: 
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)
72             raise
73
74     def get_format_string(self):
75         return 'Subversion Smart Server'
76
77     def get_format_description(self):
78         return 'Subversion Smart Server'
79
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
84         import svn.repos
85
86         if not isinstance(transport, LocalTransport):
87             raise NotImplementedError(self.initialize, 
88                 "Can't create Subversion Repositories/branches on "
89                 "non-local transports")
90
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)
94
95     def is_supported(self):
96         """See BzrDir.is_supported()."""
97         return True
98
99
100 class SvnWorkingTreeDirFormat(BzrDirFormat):
101     """Working Tree implementation that uses Subversion working copies."""
102     _lock_class = TransportLock
103
104     def __init__(self):
105         super(SvnWorkingTreeDirFormat, self).__init__()
106         from repository import SvnRepositoryFormat
107         self.repository_format = SvnRepositoryFormat()
108
109     @classmethod
110     def probe_transport(klass, transport):
111         import svn
112         from bzrlib.transport.local import LocalTransport
113         format = klass()
114
115         if isinstance(transport, LocalTransport) and \
116             transport.has(svn.wc.get_adm_dir()):
117             return format
118
119         raise bzr_errors.NotBranchError(path=transport.base)
120
121     def _open(self, transport):
122         import svn.core
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()
127         try:
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)
132             raise
133
134     def get_format_string(self):
135         return 'Subversion Local Checkout'
136
137     def get_format_description(self):
138         return 'Subversion Local Checkout'
139
140     def initialize_on_transport(self, transport):
141         raise UninitializableFormat(self)
142
143     def get_converter(self, format=None):
144         """See BzrDirFormat.get_converter()."""
145         if format is None:
146             format = get_rich_root_format()
147         raise NotImplementedError(self.get_converter)