~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-14 16:54:26 UTC
  • mfrom: (6216.1.1 remove-this-file)
  • Revision ID: pqm@pqm.ubuntu.com-20111014165426-tjix4e6idryf1r2z
(jelmer) Remove an accidentally committed .THIS file. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    revision as _mod_revision,
33
33
    testament as _mod_testament,
34
34
    tsort,
 
35
    gpg,
35
36
    )
36
37
from bzrlib.bundle import serializer
 
38
from bzrlib.i18n import gettext
37
39
""")
38
40
 
39
41
from bzrlib import (
279
281
                raise
280
282
            mutter('abort_write_group failed')
281
283
            log_exception_quietly()
282
 
            note('bzr: ERROR (ignored): %s', exc)
 
284
            note(gettext('bzr: ERROR (ignored): %s'), exc)
283
285
        self._write_group = None
284
286
 
285
287
    def _abort_write_group(self):
339
341
        """
340
342
        self.control_files.break_lock()
341
343
 
342
 
    @needs_read_lock
343
 
    def _eliminate_revisions_not_present(self, revision_ids):
344
 
        """Check every revision id in revision_ids to see if we have it.
345
 
 
346
 
        Returns a set of the present revisions.
347
 
        """
348
 
        result = []
349
 
        graph = self.get_graph()
350
 
        parent_map = graph.get_parent_map(revision_ids)
351
 
        # The old API returned a list, should this actually be a set?
352
 
        return parent_map.keys()
353
 
 
354
344
    @staticmethod
355
 
    def create(a_bzrdir):
356
 
        """Construct the current default format repository in a_bzrdir."""
357
 
        return RepositoryFormat.get_default_format().initialize(a_bzrdir)
 
345
    def create(controldir):
 
346
        """Construct the current default format repository in controldir."""
 
347
        return RepositoryFormat.get_default_format().initialize(controldir)
358
348
 
359
 
    def __init__(self, _format, a_bzrdir, control_files):
 
349
    def __init__(self, _format, controldir, control_files):
360
350
        """instantiate a Repository.
361
351
 
362
352
        :param _format: The format of the repository on disk.
363
 
        :param a_bzrdir: The BzrDir of the repository.
 
353
        :param controldir: The ControlDir of the repository.
364
354
        :param control_files: Control files to use for locking, etc.
365
355
        """
366
356
        # In the future we will have a single api for all stores for
369
359
        super(Repository, self).__init__()
370
360
        self._format = _format
371
361
        # the following are part of the public API for Repository:
372
 
        self.bzrdir = a_bzrdir
 
362
        self.bzrdir = controldir
373
363
        self.control_files = control_files
374
 
        self._transport = control_files._transport
375
 
        self.base = self._transport.base
376
364
        # for tests
377
365
        self._write_group = None
378
366
        # Additional places to query for data.
416
404
        """
417
405
        if self.__class__ is not other.__class__:
418
406
            return False
419
 
        return (self._transport.base == other._transport.base)
 
407
        return (self.control_url == other.control_url)
420
408
 
421
409
    def is_in_write_group(self):
422
410
        """Return True if there is an open write group.
559
547
            def __init__(self):
560
548
                self.first_call = True
561
549
 
562
 
            def __call__(self, bzrdir):
563
 
                # On the first call, the parameter is always the bzrdir
 
550
            def __call__(self, controldir):
 
551
                # On the first call, the parameter is always the controldir
564
552
                # containing the current repo.
565
553
                if not self.first_call:
566
554
                    try:
567
 
                        repository = bzrdir.open_repository()
 
555
                        repository = controldir.open_repository()
568
556
                    except errors.NoRepositoryPresent:
569
557
                        pass
570
558
                    else:
571
559
                        return False, ([], repository)
572
560
                self.first_call = False
573
 
                value = (bzrdir.list_branches(), None)
 
561
                value = (controldir.list_branches(), None)
574
562
                return True, value
575
563
 
576
564
        ret = []
577
 
        for branches, repository in bzrdir.BzrDir.find_bzrdirs(
 
565
        for branches, repository in controldir.ControlDir.find_bzrdirs(
578
566
                self.user_transport, evaluate=Evaluator()):
579
567
            if branches is not None:
580
568
                ret.extend(branches)
614
602
        For instance, if the repository is at URL/.bzr/repository,
615
603
        Repository.open(URL) -> a Repository instance.
616
604
        """
617
 
        control = bzrdir.BzrDir.open(base)
 
605
        control = controldir.ControlDir.open(base)
618
606
        return control.open_repository()
619
607
 
620
608
    def copy_content_into(self, destination, revision_id=None):
758
746
                repo.unlock()
759
747
 
760
748
    @needs_read_lock
761
 
    def clone(self, a_bzrdir, revision_id=None):
762
 
        """Clone this repository into a_bzrdir using the current format.
 
749
    def clone(self, controldir, revision_id=None):
 
750
        """Clone this repository into controldir using the current format.
763
751
 
764
752
        Currently no check is made that the format of this repository and
765
753
        the bzrdir format are compatible. FIXME RBC 20060201.
768
756
        """
769
757
        # TODO: deprecate after 0.16; cloning this with all its settings is
770
758
        # probably not very useful -- mbp 20070423
771
 
        dest_repo = self._create_sprouting_repo(a_bzrdir, shared=self.is_shared())
 
759
        dest_repo = self._create_sprouting_repo(
 
760
            controldir, shared=self.is_shared())
772
761
        self.copy_content_into(dest_repo, revision_id)
773
762
        return dest_repo
774
763
 
941
930
        parent_ids.discard(_mod_revision.NULL_REVISION)
942
931
        return parent_ids
943
932
 
944
 
    def fileids_altered_by_revision_ids(self, revision_ids):
945
 
        """Find the file ids and versions affected by revisions.
946
 
 
947
 
        :param revisions: an iterable containing revision ids.
948
 
        :return: a dictionary mapping altered file-ids to an iterable of
949
 
            revision_ids. Each altered file-ids has the exact revision_ids
950
 
            that altered it listed explicitly.
951
 
        """
952
 
        raise NotImplementedError(self.fileids_altered_by_revision_ids)
953
 
 
954
933
    def iter_files_bytes(self, desired_files):
955
934
        """Iterate through file versions.
956
935
 
1205
1184
        plaintext = testament.as_short_text()
1206
1185
        self.store_revision_signature(gpg_strategy, plaintext, revision_id)
1207
1186
 
 
1187
    @needs_read_lock
 
1188
    def verify_revision(self, revision_id, gpg_strategy):
 
1189
        """Verify the signature on a revision.
 
1190
        
 
1191
        :param revision_id: the revision to verify
 
1192
        :gpg_strategy: the GPGStrategy object to used
 
1193
        
 
1194
        :return: gpg.SIGNATURE_VALID or a failed SIGNATURE_ value
 
1195
        """
 
1196
        if not self.has_signature_for_revision_id(revision_id):
 
1197
            return gpg.SIGNATURE_NOT_SIGNED, None
 
1198
        signature = self.get_signature_text(revision_id)
 
1199
 
 
1200
        testament = _mod_testament.Testament.from_revision(self, revision_id)
 
1201
        plaintext = testament.as_short_text()
 
1202
 
 
1203
        return gpg_strategy.verify(signature, plaintext)
 
1204
 
1208
1205
    def has_signature_for_revision_id(self, revision_id):
1209
1206
        """Query for a revision signature for revision_id in the repository."""
1210
1207
        raise NotImplementedError(self.has_signature_for_revision_id)
1315
1312
 
1316
1313
    def get_default(self):
1317
1314
        """Return the current default format."""
1318
 
        from bzrlib import bzrdir
1319
 
        return bzrdir.format_registry.make_bzrdir('default').repository_format
 
1315
        return controldir.format_registry.make_bzrdir('default').repository_format
1320
1316
 
1321
1317
 
1322
1318
network_format_registry = registry.FormatRegistry()
1365
1361
    created.
1366
1362
 
1367
1363
    Common instance attributes:
1368
 
    _matchingbzrdir - the bzrdir format that the repository format was
 
1364
    _matchingbzrdir - the controldir format that the repository format was
1369
1365
    originally written to work with. This can be used if manually
1370
1366
    constructing a bzrdir and repository, or more commonly for test suite
1371
1367
    parameterization.
1409
1405
    revision_graph_can_have_wrong_parents = None
1410
1406
    # Does this format support rich root data?
1411
1407
    rich_root_data = None
 
1408
    # Does this format support explicitly versioned directories?
 
1409
    supports_versioned_directories = None
 
1410
    # Can other repositories be nested into one of this format?
 
1411
    supports_nesting_repositories = None
1412
1412
 
1413
1413
    def __repr__(self):
1414
1414
        return "%s()" % self.__class__.__name__
1466
1466
        """Return the short description for this format."""
1467
1467
        raise NotImplementedError(self.get_format_description)
1468
1468
 
1469
 
    def initialize(self, a_bzrdir, shared=False):
1470
 
        """Initialize a repository of this format in a_bzrdir.
 
1469
    def initialize(self, controldir, shared=False):
 
1470
        """Initialize a repository of this format in controldir.
1471
1471
 
1472
 
        :param a_bzrdir: The bzrdir to put the new repository in it.
 
1472
        :param controldir: The controldir to put the new repository in it.
1473
1473
        :param shared: The repository should be initialized as a sharable one.
1474
1474
        :returns: The new repository object.
1475
1475
 
1476
1476
        This may raise UninitializableFormat if shared repository are not
1477
 
        compatible the a_bzrdir.
 
1477
        compatible the controldir.
1478
1478
        """
1479
1479
        raise NotImplementedError(self.initialize)
1480
1480
 
1516
1516
                'Does not support nested trees', target_format,
1517
1517
                from_format=self)
1518
1518
 
1519
 
    def open(self, a_bzrdir, _found=False):
1520
 
        """Return an instance of this format for the bzrdir a_bzrdir.
 
1519
    def open(self, controldir, _found=False):
 
1520
        """Return an instance of this format for a controldir.
1521
1521
 
1522
1522
        _found is a private parameter, do not use it.
1523
1523
        """
1524
1524
        raise NotImplementedError(self.open)
1525
1525
 
1526
 
    def _run_post_repo_init_hooks(self, repository, a_bzrdir, shared):
1527
 
        from bzrlib.bzrdir import BzrDir, RepoInitHookParams
1528
 
        hooks = BzrDir.hooks['post_repo_init']
 
1526
    def _run_post_repo_init_hooks(self, repository, controldir, shared):
 
1527
        from bzrlib.controldir import ControlDir, RepoInitHookParams
 
1528
        hooks = ControlDir.hooks['post_repo_init']
1529
1529
        if not hooks:
1530
1530
            return
1531
 
        params = RepoInitHookParams(repository, self, a_bzrdir, shared)
 
1531
        params = RepoInitHookParams(repository, self, controldir, shared)
1532
1532
        for hook in hooks:
1533
1533
            hook(params)
1534
1534
 
1540
1540
    supports_tree_reference = False
1541
1541
    supports_external_lookups = False
1542
1542
    supports_leaving_lock = True
 
1543
    supports_nesting_repositories = True
1543
1544
 
1544
1545
    @property
1545
1546
    def _matchingbzrdir(self):
1586
1587
# formats which have no format string are not discoverable or independently
1587
1588
# creatable on disk, so are not registered in format_registry.  They're
1588
1589
# all in bzrlib.repofmt.knitreponow.  When an instance of one of these is
1589
 
# needed, it's constructed directly by the BzrDir.  Non-native formats where
 
1590
# needed, it's constructed directly by the ControlDir.  Non-native formats where
1590
1591
# the repository is not separately opened are similar.
1591
1592
 
1592
1593
format_registry.register_lazy(
1790
1791
        # trigger an assertion if not such
1791
1792
        repo._format.get_format_string()
1792
1793
        self.repo_dir = repo.bzrdir
1793
 
        pb.update('Moving repository to repository.backup')
 
1794
        pb.update(gettext('Moving repository to repository.backup'))
1794
1795
        self.repo_dir.transport.move('repository', 'repository.backup')
1795
1796
        backup_transport =  self.repo_dir.transport.clone('repository.backup')
1796
1797
        repo._format.check_conversion_target(self.target_format)
1797
1798
        self.source_repo = repo._format.open(self.repo_dir,
1798
1799
            _found=True,
1799
1800
            _override_transport=backup_transport)
1800
 
        pb.update('Creating new repository')
 
1801
        pb.update(gettext('Creating new repository'))
1801
1802
        converted = self.target_format.initialize(self.repo_dir,
1802
1803
                                                  self.source_repo.is_shared())
1803
1804
        converted.lock_write()
1804
1805
        try:
1805
 
            pb.update('Copying content')
 
1806
            pb.update(gettext('Copying content'))
1806
1807
            self.source_repo.copy_content_into(converted)
1807
1808
        finally:
1808
1809
            converted.unlock()
1809
 
        pb.update('Deleting old repository content')
 
1810
        pb.update(gettext('Deleting old repository content'))
1810
1811
        self.repo_dir.transport.delete_tree('repository.backup')
1811
 
        ui.ui_factory.note('repository converted')
 
1812
        ui.ui_factory.note(gettext('repository converted'))
1812
1813
        pb.finished()
1813
1814
 
1814
1815
 
1880
1881
        for list_part in self.list_parts:
1881
1882
            full_list.extend(list_part)
1882
1883
        return iter(full_list)
 
1884
 
 
1885
    def __repr__(self):
 
1886
        return "%s.%s(%s)" % (self.__module__, self.__class__.__name__,
 
1887
                              self.list_parts)