141
142
raise ValueError('Invalid value for %s: %r' % (context, text))
143
144
def _validate_revprops(self, revprops):
144
for key, value in revprops.iteritems():
145
for key, value in viewitems(revprops):
145
146
# We know that the XML serializers do not round trip '\r'
146
147
# correctly, so refuse to accept them
147
148
if not isinstance(value, basestring):
906
907
raise NotImplementedError(self.add_signature_text)
908
def _find_parent_ids_of_revisions(self, revision_ids):
909
"""Find all parent ids that are mentioned in the revision graph.
911
:return: set of revisions that are parents of revision_ids which are
912
not part of revision_ids themselves
914
parent_map = self.get_parent_map(revision_ids)
915
parent_ids = set(itertools.chain.from_iterable(
916
parent_map.itervalues()))
917
parent_ids.difference_update(revision_ids)
918
parent_ids.discard(_mod_revision.NULL_REVISION)
921
909
def iter_files_bytes(self, desired_files):
922
910
"""Iterate through file versions.
1054
1042
query_keys.append((revision_id ,))
1055
1043
vf = self.revisions.without_fallbacks()
1056
for ((revision_id,), parent_keys) in \
1057
vf.get_parent_map(query_keys).iteritems():
1044
for (revision_id,), parent_keys in viewitems(
1045
vf.get_parent_map(query_keys)):
1058
1046
if parent_keys:
1059
1047
result[revision_id] = tuple([parent_revid
1060
1048
for (parent_revid,) in parent_keys])
1210
1198
raise errors.NonAsciiRevisionId(method, self)
1213
class MetaDirRepository(Repository):
1214
"""Repositories in the new meta-dir layout.
1216
:ivar _transport: Transport for access to repository control files,
1217
typically pointing to .bzr/repository.
1220
def __init__(self, _format, a_bzrdir, control_files):
1221
super(MetaDirRepository, self).__init__(_format, a_bzrdir, control_files)
1222
self._transport = control_files._transport
1224
def is_shared(self):
1225
"""Return True if this repository is flagged as a shared repository."""
1226
return self._transport.has('shared-storage')
1229
def set_make_working_trees(self, new_value):
1230
"""Set the policy flag for making working trees when creating branches.
1232
This only applies to branches that use this repository.
1234
The default is 'True'.
1235
:param new_value: True to restore the default, False to disable making
1240
self._transport.delete('no-working-trees')
1241
except errors.NoSuchFile:
1244
self._transport.put_bytes('no-working-trees', '',
1245
mode=self.bzrdir._get_file_mode())
1247
def make_working_trees(self):
1248
"""Returns the policy for making working trees on new branches."""
1249
return not self._transport.has('no-working-trees')
1252
def update_feature_flags(self, updated_flags):
1253
"""Update the feature flags for this branch.
1255
:param updated_flags: Dictionary mapping feature names to necessities
1256
A necessity can be None to indicate the feature should be removed
1258
self._format._update_feature_flags(updated_flags)
1259
self.control_transport.put_bytes('format', self._format.as_string())
1262
1201
class RepositoryFormatRegistry(controldir.ControlComponentFormatRegistry):
1263
1202
"""Repository format registry."""
1449
class RepositoryFormatMetaDir(bzrdir.BzrFormat, RepositoryFormat):
1450
"""Common base class for the new repositories using the metadir layout."""
1452
rich_root_data = False
1453
supports_tree_reference = False
1454
supports_external_lookups = False
1455
supports_leaving_lock = True
1456
supports_nesting_repositories = True
1459
def _matchingbzrdir(self):
1460
matching = bzrdir.BzrDirMetaFormat1()
1461
matching.repository_format = self
1465
RepositoryFormat.__init__(self)
1466
bzrdir.BzrFormat.__init__(self)
1468
def _create_control_files(self, a_bzrdir):
1469
"""Create the required files and the initial control_files object."""
1470
# FIXME: RBC 20060125 don't peek under the covers
1471
# NB: no need to escape relative paths that are url safe.
1472
repository_transport = a_bzrdir.get_repository_transport(self)
1473
control_files = lockable_files.LockableFiles(repository_transport,
1474
'lock', lockdir.LockDir)
1475
control_files.create_lock()
1476
return control_files
1478
def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):
1479
"""Upload the initial blank content."""
1480
control_files = self._create_control_files(a_bzrdir)
1481
control_files.lock_write()
1482
transport = control_files._transport
1484
utf8_files += [('shared-storage', '')]
1486
transport.mkdir_multi(dirs, mode=a_bzrdir._get_dir_mode())
1487
for (filename, content_stream) in files:
1488
transport.put_file(filename, content_stream,
1489
mode=a_bzrdir._get_file_mode())
1490
for (filename, content_bytes) in utf8_files:
1491
transport.put_bytes_non_atomic(filename, content_bytes,
1492
mode=a_bzrdir._get_file_mode())
1494
control_files.unlock()
1497
def find_format(klass, a_bzrdir):
1498
"""Return the format for the repository object in a_bzrdir.
1500
This is used by brz native formats that have a "format" file in
1501
the repository. Other methods may be used by different types of
1505
transport = a_bzrdir.get_repository_transport(None)
1506
format_string = transport.get_bytes("format")
1507
except errors.NoSuchFile:
1508
raise errors.NoRepositoryPresent(a_bzrdir)
1509
return klass._find_format(format_registry, 'repository', format_string)
1511
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1513
RepositoryFormat.check_support_status(self,
1514
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
1516
bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
1517
recommend_upgrade=recommend_upgrade, basedir=basedir)
1520
1388
# formats which have no format string are not discoverable or independently
1521
1389
# creatable on disk, so are not registered in format_registry. They're
1522
1390
# all in breezy.repofmt.knitreponow. When an instance of one of these is
1649
1518
raise NotImplementedError(self.fetch)
1651
1520
@needs_read_lock
1652
def search_missing_revision_ids(self,
1653
find_ghosts=True, revision_ids=None, if_present_ids=None,
1521
def search_missing_revision_ids(
1522
self, find_ghosts=True, revision_ids=None, if_present_ids=None,
1655
1524
"""Return the revision ids that source has that target does not.