910
910
def needs_format_conversion(self, format):
911
911
"""See BzrDir.needs_format_conversion()."""
912
if not isinstance(self._format, format.__class__):
912
if (not isinstance(self._format, format.__class__) or
913
self._format.get_format_string() != format.get_format_string()):
913
914
# it is not a meta dir format, conversion is needed.
915
916
# we might want to push this down to the repository?
1372
def supports_transport(self, transport):
1373
# bzr formats can be opened over all known transports
1372
1377
class BzrDirMetaFormat1(BzrDirFormat):
1373
1378
"""Bzr meta control format 1
1511
1516
"""See BzrDirFormat.get_converter()."""
1512
1517
if format is None:
1513
1518
format = BzrDirFormat.get_default_format()
1519
if (type(self) is BzrDirMetaFormat1 and
1520
type(format) is BzrDirMetaFormat1Colo):
1521
return ConvertMetaToColo(format)
1522
if (type(self) is BzrDirMetaFormat1Colo and
1523
type(format) is BzrDirMetaFormat1):
1524
return ConvertMetaRemoveColo(format)
1514
1525
if not isinstance(self, format.__class__):
1515
1526
# converting away from metadir is not implemented
1516
1527
raise NotImplementedError(self.get_converter)
1696
1707
return to_convert
1710
class ConvertMetaToColo(controldir.Converter):
1711
"""Add colocated branch support."""
1713
def __init__(self, target_format):
1714
"""Create a converter.that upgrades a metadir to the colo format.
1716
:param target_format: The final metadir format that is desired.
1718
self.target_format = target_format
1720
def convert(self, to_convert, pb):
1721
"""See Converter.convert()."""
1722
to_convert.transport.put_bytes('branch-format',
1723
self.target_format.get_format_string())
1724
return BzrDir.open_from_transport(to_convert.root_transport)
1727
class ConvertMetaRemoveColo(controldir.Converter):
1728
"""Remove colocated branch support from a bzrdir."""
1730
def __init__(self, target_format):
1731
"""Create a converter.that downgrades a colocated branch metadir
1732
to a regular metadir.
1734
:param target_format: The final metadir format that is desired.
1736
self.target_format = target_format
1738
def convert(self, to_convert, pb):
1739
"""See Converter.convert()."""
1740
to_convert.control_files.lock_write()
1742
branches = to_convert.list_branches()
1743
if len(branches) > 1:
1744
raise errors.BzrError("remove all but a single "
1745
"colocated branch when downgrading")
1747
to_convert.control_files.unlock()
1748
to_convert.transport.put_bytes('branch-format',
1749
self.target_format.get_format_string())
1750
return BzrDir.open_from_transport(to_convert.root_transport)
1699
1753
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)