/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/repository.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 00:06:46 UTC
  • mfrom: (6673 work)
  • mto: This revision was merged to the branch mainline in revision 6675.
  • Revision ID: jelmer@jelmer.uk-20170610000646-xj6jh277lo4xuo10
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    debug,
28
28
    generate_ids,
29
29
    graph,
30
 
    lockable_files,
31
 
    lockdir,
32
30
    osutils,
33
31
    revision as _mod_revision,
34
32
    testament as _mod_testament,
35
 
    tsort,
36
33
    gpg,
37
34
    )
38
35
from breezy.bundle import serializer
48
45
from .decorators import needs_read_lock, needs_write_lock, only_raises
49
46
from .inter import InterObject
50
47
from .lock import _RelockDebugMixin, LogicalLockResult
 
48
from .sixish import (
 
49
    viewitems,
 
50
    viewvalues,
 
51
    )
51
52
from .trace import (
52
53
    log_exception_quietly, note, mutter, mutter_callsite, warning)
53
54
 
141
142
            raise ValueError('Invalid value for %s: %r' % (context, text))
142
143
 
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):
247
248
# Repositories
248
249
 
249
250
 
250
 
class Repository(_RelockDebugMixin, controldir.ControlComponent):
 
251
class Repository(controldir.ControlComponent, _RelockDebugMixin):
251
252
    """Repository holding history for one or more branches.
252
253
 
253
254
    The repository holds and retrieves historical information including
905
906
        """
906
907
        raise NotImplementedError(self.add_signature_text)
907
908
 
908
 
    def _find_parent_ids_of_revisions(self, revision_ids):
909
 
        """Find all parent ids that are mentioned in the revision graph.
910
 
 
911
 
        :return: set of revisions that are parents of revision_ids which are
912
 
            not part of revision_ids themselves
913
 
        """
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)
919
 
        return parent_ids
920
 
 
921
909
    def iter_files_bytes(self, desired_files):
922
910
        """Iterate through file versions.
923
911
 
1053
1041
            else:
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)
1211
1199
 
1212
1200
 
1213
 
class MetaDirRepository(Repository):
1214
 
    """Repositories in the new meta-dir layout.
1215
 
 
1216
 
    :ivar _transport: Transport for access to repository control files,
1217
 
        typically pointing to .bzr/repository.
1218
 
    """
1219
 
 
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
1223
 
 
1224
 
    def is_shared(self):
1225
 
        """Return True if this repository is flagged as a shared repository."""
1226
 
        return self._transport.has('shared-storage')
1227
 
 
1228
 
    @needs_write_lock
1229
 
    def set_make_working_trees(self, new_value):
1230
 
        """Set the policy flag for making working trees when creating branches.
1231
 
 
1232
 
        This only applies to branches that use this repository.
1233
 
 
1234
 
        The default is 'True'.
1235
 
        :param new_value: True to restore the default, False to disable making
1236
 
                          working trees.
1237
 
        """
1238
 
        if new_value:
1239
 
            try:
1240
 
                self._transport.delete('no-working-trees')
1241
 
            except errors.NoSuchFile:
1242
 
                pass
1243
 
        else:
1244
 
            self._transport.put_bytes('no-working-trees', '',
1245
 
                mode=self.bzrdir._get_file_mode())
1246
 
 
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')
1250
 
 
1251
 
    @needs_write_lock
1252
 
    def update_feature_flags(self, updated_flags):
1253
 
        """Update the feature flags for this branch.
1254
 
 
1255
 
        :param updated_flags: Dictionary mapping feature names to necessities
1256
 
            A necessity can be None to indicate the feature should be removed
1257
 
        """
1258
 
        self._format._update_feature_flags(updated_flags)
1259
 
        self.control_transport.put_bytes('format', self._format.as_string())
1260
 
 
1261
 
 
1262
1201
class RepositoryFormatRegistry(controldir.ControlComponentFormatRegistry):
1263
1202
    """Repository format registry."""
1264
1203
 
1446
1385
            hook(params)
1447
1386
 
1448
1387
 
1449
 
class RepositoryFormatMetaDir(bzrdir.BzrFormat, RepositoryFormat):
1450
 
    """Common base class for the new repositories using the metadir layout."""
1451
 
 
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
1457
 
 
1458
 
    @property
1459
 
    def _matchingbzrdir(self):
1460
 
        matching = bzrdir.BzrDirMetaFormat1()
1461
 
        matching.repository_format = self
1462
 
        return matching
1463
 
 
1464
 
    def __init__(self):
1465
 
        RepositoryFormat.__init__(self)
1466
 
        bzrdir.BzrFormat.__init__(self)
1467
 
 
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
1477
 
 
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
1483
 
        if shared == True:
1484
 
            utf8_files += [('shared-storage', '')]
1485
 
        try:
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())
1493
 
        finally:
1494
 
            control_files.unlock()
1495
 
 
1496
 
    @classmethod
1497
 
    def find_format(klass, a_bzrdir):
1498
 
        """Return the format for the repository object in a_bzrdir.
1499
 
 
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
1502
 
        control directory.
1503
 
        """
1504
 
        try:
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)
1510
 
 
1511
 
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1512
 
            basedir=None):
1513
 
        RepositoryFormat.check_support_status(self,
1514
 
            allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
1515
 
            basedir=basedir)
1516
 
        bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
1517
 
            recommend_upgrade=recommend_upgrade, basedir=basedir)
1518
 
 
1519
 
 
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
1631
1499
                            revision_id and its parents.
1632
1500
        """
1633
1501
        try:
1634
 
            self.target.set_make_working_trees(self.source.make_working_trees())
 
1502
            self.target.set_make_working_trees(
 
1503
                self.source.make_working_trees())
1635
1504
        except NotImplementedError:
1636
1505
            pass
1637
1506
        self.target.fetch(self.source, revision_id=revision_id)
1649
1518
        raise NotImplementedError(self.fetch)
1650
1519
 
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,
1654
1523
            limit=None):
1655
1524
        """Return the revision ids that source has that target does not.
1656
1525
 
1747
1616
    # Filter ghosts, and null:
1748
1617
    if _mod_revision.NULL_REVISION in revision_graph:
1749
1618
        del revision_graph[_mod_revision.NULL_REVISION]
1750
 
    for key, parents in revision_graph.items():
 
1619
    for key, parents in viewitems(revision_graph):
1751
1620
        revision_graph[key] = tuple(parent for parent in parents if parent
1752
1621
            in revision_graph)
1753
1622
    return revision_graph
1792
1661
 
1793
1662
    Each iterator made from this will reflect the current contents of the lists
1794
1663
    at the time the iterator is made.
1795
 
    
 
1664
 
1796
1665
    This is used by Repository's _make_parents_provider implementation so that
1797
1666
    it is safe to do::
1798
1667