/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
7413.9.1 by Jelmer Vernooij
Add basic svn plugin.
1
# Copyright (C) 2019 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; version 3 of the License or
6
# (at your option) a 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
17
"""Subversion foreign branch support.
18
19
Currently only tells the user that Subversion is not supported.
20
"""
21
22
from ... import version_info  # noqa: F401
23
24
from ... import (
25
    controldir,
26
    errors,
27
    transport as _mod_transport,
28
    )
29
30
31
class SubversionUnsupportedError(errors.UnsupportedFormatError):
32
33
    _fmt = ('Subversion branches are not yet supported. '
34
            'To convert Subversion branches to Bazaar branches or vice versa, '
35
            'use the fastimport format.')
36
37
38
class SvnWorkingTreeDirFormat(controldir.ControlDirFormat):
39
    """Subversion directory format."""
40
41
    def get_converter(self):
42
        raise NotImplementedError(self.get_converter)
43
44
    def get_format_description(self):
45
        return "Subversion working directory"
46
47
    def initialize_on_transport(self, transport):
48
        raise errors.UninitializableFormat(self)
49
50
    def is_supported(self):
51
        return False
52
53
    def supports_transport(self, transport):
54
        return False
55
56
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
57
                             basedir=None):
7413.9.2 by Jelmer Vernooij
Fix tests.
58
        raise SubversionUnsupportedError()
7413.9.1 by Jelmer Vernooij
Add basic svn plugin.
59
60
    def open(self, transport):
61
        # Raise NotBranchError if there is nothing there
62
        SvnWorkingTreeProber().probe_transport(transport)
63
        raise NotImplementedError(self.open)
64
65
66
class SvnWorkingTreeProber(controldir.Prober):
67
7413.9.6 by Jelmer Vernooij
Fix priority method.
68
    @classmethod
69
    def priority(klass, transport):
70
        return 100
71
7413.9.1 by Jelmer Vernooij
Add basic svn plugin.
72
    def probe_transport(self, transport):
7413.9.7 by Jelmer Vernooij
Avoid imports.
73
        try:
74
            transport.local_abspath('.')
75
        except errors.NotLocalUrl:
76
            raise errors.NotBranchError(path=transport.base)
77
        else:
78
            if transport.has(".svn"):
79
                return SvnWorkingTreeDirFormat()
80
            raise errors.NotBranchError(path=transport.base)
7413.9.1 by Jelmer Vernooij
Add basic svn plugin.
81
82
    @classmethod
83
    def known_formats(cls):
7413.9.2 by Jelmer Vernooij
Fix tests.
84
        return [SvnWorkingTreeDirFormat()]
7413.9.1 by Jelmer Vernooij
Add basic svn plugin.
85
86
7413.9.3 by Jelmer Vernooij
Support probing remote svn repositories.
87
class SvnRepositoryFormat(controldir.ControlDirFormat):
88
    """Subversion directory format."""
89
90
    def get_converter(self):
91
        raise NotImplementedError(self.get_converter)
92
93
    def get_format_description(self):
94
        return "Subversion repository"
95
96
    def initialize_on_transport(self, transport):
97
        raise errors.UninitializableFormat(self)
98
99
    def is_supported(self):
100
        return False
101
102
    def supports_transport(self, transport):
103
        return False
104
105
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
106
                             basedir=None):
107
        raise SubversionUnsupportedError()
108
109
    def open(self, transport):
110
        # Raise NotBranchError if there is nothing there
111
        SvnRepositoryProber().probe_transport(transport)
112
        raise NotImplementedError(self.open)
113
114
115
class SvnRepositoryProber(controldir.Prober):
116
117
    _supported_schemes = ["http", "https", "file", "svn"]
118
7413.9.5 by Jelmer Vernooij
Set priorities.
119
    @classmethod
120
    def priority(klass, transport):
7413.9.12 by Jelmer Vernooij
Fix svn probing.
121
        if 'svn' in transport.base:
7413.9.9 by Jelmer Vernooij
Bump priority if SVN is in the URL.
122
            return 90
7413.9.5 by Jelmer Vernooij
Set priorities.
123
        return 100
124
7413.9.3 by Jelmer Vernooij
Support probing remote svn repositories.
125
    def probe_transport(self, transport):
126
        try:
127
            url = transport.external_url()
128
        except errors.InProcessTransport:
129
            raise errors.NotBranchError(path=transport.base)
130
131
        scheme = url.split(":")[0]
132
        if scheme.startswith("svn+") or scheme == "svn":
133
            raise SubversionUnsupportedError()
134
135
        if scheme not in self._supported_schemes:
136
            raise errors.NotBranchError(path=transport.base)
137
138
        if scheme == 'file':
139
            # Cheaper way to figure out if there is a svn repo
140
            maybe = False
141
            subtransport = transport
142
            while subtransport:
143
                try:
7413.9.8 by Jelmer Vernooij
Check harder for svn repositories.
144
                    if all([subtransport.has(name)
145
                            for name in ["format", "db", "conf"]]):
7413.9.3 by Jelmer Vernooij
Support probing remote svn repositories.
146
                        maybe = True
147
                        break
148
                except UnicodeEncodeError:
149
                    pass
150
                prevsubtransport = subtransport
151
                subtransport = prevsubtransport.clone("..")
152
                if subtransport.base == prevsubtransport.base:
153
                    break
154
            if not maybe:
155
                raise errors.NotBranchError(path=transport.base)
156
157
        # If this is a HTTP transport, use the existing connection to check
158
        # that the remote end supports version control.
159
        if scheme in ("http", "https"):
160
            priv_transport = getattr(transport, "_decorated", transport)
161
            try:
162
                headers = priv_transport._options('.')
163
            except (errors.InProcessTransport, errors.NoSuchFile,
164
                    errors.InvalidHttpResponse):
165
                raise errors.NotBranchError(path=transport.base)
166
            else:
167
                dav_entries = set()
168
                for key, value in headers:
169
                    if key.upper() == 'DAV':
170
                        dav_entries.update(
171
                            [x.strip() for x in value.split(',')])
172
                if "version-control" not in dav_entries:
173
                    raise errors.NotBranchError(path=transport.base)
174
175
        return SvnRepositoryFormat()
176
177
    @classmethod
178
    def known_formats(cls):
7413.9.14 by Jelmer Vernooij
List not set.
179
        return [SvnRepositoryFormat()]
7413.9.3 by Jelmer Vernooij
Support probing remote svn repositories.
180
181
7413.9.1 by Jelmer Vernooij
Add basic svn plugin.
182
controldir.ControlDirFormat.register_prober(SvnWorkingTreeProber)
7413.9.11 by Jelmer Vernooij
Fix plugin.
183
controldir.ControlDirFormat.register_prober(SvnRepositoryProber)
7413.9.1 by Jelmer Vernooij
Add basic svn plugin.
184
185
186
_mod_transport.register_transport_proto(
187
    'svn+ssh://',
188
    help="Access using the Subversion smart server tunneled over SSH.")
189
_mod_transport.register_transport_proto(
190
    'svn+http://')
191
_mod_transport.register_transport_proto(
192
    'svn+https://')
193
_mod_transport.register_transport_proto(
194
    'svn://',
195
    help="Access using the Subversion smart server.")