1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
98
99
returns the sha1 of the serialized inventory.
101
_mod_revision.check_not_reserved_id(revid)
100
102
assert inv.revision_id is None or inv.revision_id == revid, \
101
103
"Mismatch between inventory revision" \
102
104
" id and insertion revid (%r, %r)" % (inv.revision_id, revid)
128
130
If supplied its signature_needed method will be used
129
131
to determine if a signature should be made.
133
_mod_revision.check_not_reserved_id(rev_id)
131
134
if config is not None and config.signature_needed():
133
136
inv = self.get_inventory(rev_id)
240
243
return self.control_files.get_physical_lock_status()
246
def gather_stats(self, revid=None, committers=None):
247
"""Gather statistics from a revision id.
249
:param revid: The revision id to gather statistics from, if None, then
250
no revision specific statistics are gathered.
251
:param committers: Optional parameter controlling whether to grab
252
a count of committers from the revision specific statistics.
253
:return: A dictionary of statistics. Currently this contains:
254
committers: The number of committers if requested.
255
firstrev: A tuple with timestamp, timezone for the penultimate left
256
most ancestor of revid, if revid is not the NULL_REVISION.
257
latestrev: A tuple with timestamp, timezone for revid, if revid is
258
not the NULL_REVISION.
259
revisions: The total revision count in the repository.
260
size: An estimate disk size of the repository in bytes.
263
if revid and committers:
264
result['committers'] = 0
265
if revid and revid != _mod_revision.NULL_REVISION:
267
all_committers = set()
268
revisions = self.get_ancestry(revid)
269
# pop the leading None
271
first_revision = None
273
# ignore the revisions in the middle - just grab first and last
274
revisions = revisions[0], revisions[-1]
275
for revision in self.get_revisions(revisions):
276
if not first_revision:
277
first_revision = revision
279
all_committers.add(revision.committer)
280
last_revision = revision
282
result['committers'] = len(all_committers)
283
result['firstrev'] = (first_revision.timestamp,
284
first_revision.timezone)
285
result['latestrev'] = (last_revision.timestamp,
286
last_revision.timezone)
288
# now gather global repository information
289
if self.bzrdir.root_transport.listable():
290
c, t = self._revision_store.total_size(self.get_transaction())
291
result['revisions'] = c
243
296
def missing_revision_ids(self, other, revision_id=None):
244
297
"""Return the revision ids that other has that this does not.
1133
1186
committer, revprops, revision_id)
1189
class RepositoryFormatRegistry(registry.Registry):
1190
"""Registry of RepositoryFormats.
1194
format_registry = RepositoryFormatRegistry()
1195
"""Registry of formats, indexed by their identifying format string."""
1136
1198
class RepositoryFormat(object):
1137
1199
"""A repository format.
1157
1219
parameterisation.
1160
_default_format = None
1161
"""The default format used for new repositories."""
1164
"""The known formats."""
1166
1222
def __str__(self):
1167
1223
return "<%s>" % self.__class__.__name__
1170
1226
def find_format(klass, a_bzrdir):
1171
"""Return the format for the repository object in a_bzrdir."""
1227
"""Return the format for the repository object in a_bzrdir.
1229
This is used by bzr native formats that have a "format" file in
1230
the repository. Other methods may be used by different types of
1173
1234
transport = a_bzrdir.get_repository_transport(None)
1174
1235
format_string = transport.get("format").read()
1175
return klass._formats[format_string]
1236
return format_registry.get(format_string)
1176
1237
except errors.NoSuchFile:
1177
1238
raise errors.NoRepositoryPresent(a_bzrdir)
1178
1239
except KeyError:
1179
1240
raise errors.UnknownFormatError(format=format_string)
1181
def _get_control_store(self, repo_transport, control_files):
1182
"""Return the control store for this repository."""
1183
raise NotImplementedError(self._get_control_store)
1243
def register_format(klass, format):
1244
format_registry.register(format.get_format_string(), format)
1247
def unregister_format(klass, format):
1248
format_registry.remove(format.get_format_string())
1186
1251
def get_default_format(klass):
1187
1252
"""Return the current default format."""
1188
return klass._default_format
1253
from bzrlib import bzrdir
1254
return bzrdir.format_registry.make_bzrdir('default').repository_format
1256
def _get_control_store(self, repo_transport, control_files):
1257
"""Return the control store for this repository."""
1258
raise NotImplementedError(self._get_control_store)
1190
1260
def get_format_string(self):
1191
1261
"""Return the ASCII format string that identifies this format.
1274
1344
raise NotImplementedError(self.open)
1277
def register_format(klass, format):
1278
klass._formats[format.get_format_string()] = format
1281
@deprecated_method(symbol_versioning.zero_fourteen)
1282
def set_default_format(klass, format):
1283
klass._set_default_format(format)
1286
def _set_default_format(klass, format):
1287
klass._default_format = format
1290
def unregister_format(klass, format):
1291
assert klass._formats[format.get_format_string()] is format
1292
del klass._formats[format.get_format_string()]
1295
1347
class PreSplitOutRepositoryFormat(RepositoryFormat):
1296
1348
"""Base class for the pre split out repository formats."""
1806
1858
# and not independently creatable, so are not registered.
1807
1859
RepositoryFormat.register_format(RepositoryFormat7())
1808
1860
# KEEP in sync with bzrdir.format_registry default
1809
_default_format = RepositoryFormatKnit1()
1810
RepositoryFormat.register_format(_default_format)
1861
RepositoryFormat.register_format(RepositoryFormatKnit1())
1811
1862
RepositoryFormat.register_format(RepositoryFormatKnit2())
1812
RepositoryFormat._set_default_format(_default_format)
1813
1863
_legacy_formats = [RepositoryFormat4(),
1814
1864
RepositoryFormat5(),
1815
1865
RepositoryFormat6()]