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