1
# Copyright (C) 2019 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; version 3 of the License or
6
# (at your option) a 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
"""Fossil foreign branch support.
19
Currently only tells the user that Fossil is not supported.
22
from __future__ import absolute_import
24
from ... import version_info # noqa: F401
32
class FossilUnsupportedError(errors.UnsupportedFormatError):
34
_fmt = ('Fossil branches are not yet supported. '
35
'To convert Fossil branches to Bazaar branches or vice versa, '
39
class FossilDirFormat(controldir.ControlDirFormat):
40
"""Fossil directory format."""
42
def get_converter(self):
43
raise NotImplementedError(self.get_converter)
45
def get_format_description(self):
46
return "Fossil control directory"
48
def initialize_on_transport(self, transport):
49
raise errors.UninitializableFormat(self)
51
def is_supported(self):
54
def supports_transport(self, transport):
57
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
59
raise FossilUnsupportedError()
61
def open(self, transport):
62
# Raise NotBranchError if there is nothing there
63
RemoteFossilProber().probe_transport(transport)
64
raise NotImplementedError(self.open)
67
class RemoteFossilProber(controldir.Prober):
70
def priority(klass, transport):
74
def probe_transport(klass, transport):
75
from breezy.transport.http import HttpTransport
76
if not isinstance(transport, HttpTransport):
77
raise errors.NotBranchError(path=transport.base)
78
response = transport.request(
79
'POST', transport.base, headers={'Content-Type': 'application/x-fossil'})
80
if response.status == 501:
81
raise errors.NotBranchError(path=transport.base)
82
ct = response.getheader('Content-Type')
84
raise errors.NotBranchError(path=transport.base)
85
if ct.split(';')[0] != 'application/x-fossil':
86
raise errors.NotBranchError(path=transport.base)
87
return FossilDirFormat()
90
def known_formats(cls):
91
return [FossilDirFormat()]
94
controldir.ControlDirFormat.register_prober(RemoteFossilProber)