1270
1270
def needs_format_conversion(self, format):
1271
1271
"""See BzrDir.needs_format_conversion()."""
1272
if not isinstance(self._format, format.__class__):
1272
if (not isinstance(self._format, format.__class__) or
1273
self._format.get_format_string() != format.get_format_string()):
1273
1274
# it is not a meta dir format, conversion is needed.
1275
1276
# we might want to push this down to the repository?
1871
1872
"""See BzrDirFormat.get_converter()."""
1872
1873
if format is None:
1873
1874
format = BzrDirFormat.get_default_format()
1875
if (type(self) is BzrDirMetaFormat1 and
1876
type(format) is BzrDirMetaFormat1Colo):
1877
return ConvertMetaToColo(format)
1878
if (type(self) is BzrDirMetaFormat1Colo and
1879
type(format) is BzrDirMetaFormat1):
1880
return ConvertMetaRemoveColo(format)
1874
1881
if not isinstance(self, format.__class__):
1875
1882
# converting away from metadir is not implemented
1876
1883
raise NotImplementedError(self.get_converter)
2056
2063
return to_convert
2066
class ConvertMetaToColo(controldir.Converter):
2067
"""Add colocated branch support."""
2069
def __init__(self, target_format):
2070
"""Create a converter.that upgrades a metadir to the colo format.
2072
:param target_format: The final metadir format that is desired.
2074
self.target_format = target_format
2076
def convert(self, to_convert, pb):
2077
"""See Converter.convert()."""
2078
to_convert.transport.put_bytes('branch-format',
2079
self.target_format.get_format_string())
2080
return BzrDir.open_from_transport(to_convert.root_transport)
2083
class ConvertMetaRemoveColo(controldir.Converter):
2084
"""Remove colocated branch support from a bzrdir."""
2086
def __init__(self, target_format):
2087
"""Create a converter.that downgrades a colocated branch metadir
2088
to a regular metadir.
2090
:param target_format: The final metadir format that is desired.
2092
self.target_format = target_format
2094
def convert(self, to_convert, pb):
2095
"""See Converter.convert()."""
2096
to_convert.control_files.lock_write()
2098
branches = to_convert.list_branches()
2099
if len(branches) > 1:
2100
raise errors.BzrError("remove all but a single "
2101
"colocated branch when downgrading")
2103
to_convert.control_files.unlock()
2104
to_convert.transport.put_bytes('branch-format',
2105
self.target_format.get_format_string())
2106
return BzrDir.open_from_transport(to_convert.root_transport)
2059
2109
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)