1113
1113
(i.e. different from .bzr/branch-format) derive from this class,
1114
1114
as well as the relevant base class for their kind
1115
1115
(BranchFormat, WorkingTreeFormat, RepositoryFormat).
1117
Each format is identified by a "format" or "branch-format" file with a
1118
single line containing the base format name and then an optional list of
1121
Feature flags are supported as of bzr 2.5. Setting feature flags on formats
1122
will render them inaccessible to older versions of bzr.
1124
:ivar features: Dictionary mapping feature names to their necessity
1127
_present_features = set()
1133
def register_feature(cls, name):
1134
"""Register a feature as being present.
1136
:param name: Name of the feature
1139
raise ValueError("spaces are not allowed in feature names")
1140
if name in cls._present_features:
1141
raise errors.FeatureAlreadyRegistered(name)
1142
cls._present_features.add(name)
1145
def unregister_feature(cls, name):
1146
"""Unregister a feature."""
1147
cls._present_features.remove(name)
1149
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1151
for name, necessity in self.features.iteritems():
1152
if name in self._present_features:
1154
if necessity == "optional":
1155
mutter("ignoring optional missing feature %s", name)
1157
elif necessity == "required":
1158
raise errors.MissingFeature(name)
1160
mutter("treating unknown necessity as require for %s",
1162
raise errors.MissingFeature(name)
1119
1165
def get_format_string(cls):
1120
1166
"""Return the ASCII format string that identifies this format."""
1121
1167
raise NotImplementedError(cls.get_format_string)
1124
def from_string(cls, format_string):
1125
if format_string != cls.get_format_string():
1126
raise ValueError("Invalid format header %r" % format_string)
1170
def from_string(cls, text):
1171
format_string = cls.get_format_string()
1172
if not text.startswith(format_string):
1173
raise AssertionError("Invalid format header %r for %r" % (text, cls))
1174
lines = text[len(format_string):].splitlines()
1176
for lineno, line in enumerate(lines):
1178
(necessity, feature) = line.split(" ", 1)
1180
raise errors.ParseFormatError(format=cls, lineno=lineno+2,
1181
line=line, text=text)
1182
ret.features[feature] = necessity
1185
def as_string(self):
1186
"""Return the string representation of this format.
1188
lines = [self.get_format_string()]
1189
lines.extend([("%s %s\n" % (item[1], item[0])) for item in
1190
self.features.iteritems()])
1191
return "".join(lines)
1130
1194
def _find_format(klass, registry, kind, format_string):
1132
cls = registry.get(format_string)
1196
first_line = format_string[:format_string.index("\n")+1]
1198
first_line = format_string
1200
cls = registry.get(first_line)
1133
1201
except KeyError:
1134
raise errors.UnknownFormatError(format=format_string, kind=kind)
1202
raise errors.UnknownFormatError(format=first_line, kind=kind)
1203
return cls.from_string(format_string)
1137
1205
def network_name(self):
1138
1206
"""A simple byte string uniquely identifying this format for RPC calls.
1140
1208
Metadir branch formats use their format string.
1142
return self.get_format_string()
1210
return self.as_string()
1144
1212
def __eq__(self, other):
1145
return (self.__class__ is other.__class__)
1213
return (self.__class__ is other.__class__ and
1214
self.features == other.features)
1148
1217
class BzrProber(controldir.Prober):
1433
1501
compatible with whatever sub formats are supported by self.
1504
other_format.features = dict(self.features)
1437
1506
def supports_transport(self, transport):
1438
1507
# bzr formats can be opened over all known transports
1510
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1512
controldir.ControlDirFormat.check_support_status(self,
1513
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
1515
BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
1516
recommend_upgrade=recommend_upgrade, basedir=basedir)
1442
1519
class BzrDirMetaFormat1(BzrDirFormat):
1443
1520
"""Bzr meta control format 1