~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Robert Collins
  • Date: 2006-03-06 12:11:25 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060306121125-4f05992d44e3bda8
Convert Knit repositories to use knits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
        # the following are part of the public API for Repository:
148
148
        self.bzrdir = a_bzrdir
149
149
        self.control_files = control_files
150
 
        # backwards compatible until we fully transition
151
 
        self.revision_store = _revision_store.text_store
152
150
        self._revision_store = _revision_store
153
151
        self.text_store = text_store
154
152
        # backwards compatability
557
555
        return self._revision_store.has_signature(revision_id,
558
556
                                                  self.get_transaction())
559
557
 
 
558
    @needs_read_lock
 
559
    def get_signature_text(self, revision_id):
 
560
        """Return the text for a signature."""
 
561
        return self._revision_store.get_signature_text(revision_id,
 
562
                                                       self.get_transaction())
 
563
 
560
564
 
561
565
class AllInOneRepository(Repository):
562
566
    """Legacy support - the repository behaviour for all-in-one branches."""
980
984
                                              control_files,
981
985
                                              prefixed=False)
982
986
 
983
 
    def _get_revision_store(self, repo_transport, control_files):
984
 
        """See RepositoryFormat._get_revision_store()."""
985
 
        return self._get_text_rev_store(repo_transport,
986
 
                                        control_files,
987
 
                                        'revision-store',
988
 
                                        compressed=False,
989
 
                                        prefixed=True,
990
 
                                        )
991
 
 
992
 
    def open(self, a_bzrdir, _found=False, _override_transport=None):
993
 
        """See RepositoryFormat.open().
994
 
        
995
 
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
996
 
                                    repository at a slightly different url
997
 
                                    than normal. I.e. during 'upgrade'.
998
 
        """
999
 
        if not _found:
1000
 
            format = RepositoryFormat.find_format(a_bzrdir)
1001
 
            assert format.__class__ ==  self.__class__
1002
 
        if _override_transport is not None:
1003
 
            repo_transport = _override_transport
1004
 
        else:
1005
 
            repo_transport = a_bzrdir.get_repository_transport(None)
1006
 
        control_files = LockableFiles(repo_transport, 'lock')
1007
 
        text_store = self._get_text_store(repo_transport, control_files)
1008
 
        control_store = self._get_control_store(repo_transport, control_files)
1009
 
        _revision_store = self._get_revision_store(repo_transport, control_files)
1010
 
        return MetaDirRepository(_format=self,
1011
 
                                 a_bzrdir=a_bzrdir,
1012
 
                                 control_files=control_files,
1013
 
                                 _revision_store=_revision_store,
1014
 
                                 control_store=control_store,
1015
 
                                 text_store=text_store)
1016
 
 
1017
987
    def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):
1018
988
        """Upload the initial blank content."""
1019
989
        control_files = self._create_control_files(a_bzrdir)
1047
1017
        """See RepositoryFormat.get_format_string()."""
1048
1018
        return "Bazaar-NG Repository format 7"
1049
1019
 
 
1020
    def _get_revision_store(self, repo_transport, control_files):
 
1021
        """See RepositoryFormat._get_revision_store()."""
 
1022
        return self._get_text_rev_store(repo_transport,
 
1023
                                        control_files,
 
1024
                                        'revision-store',
 
1025
                                        compressed=False,
 
1026
                                        prefixed=True,
 
1027
                                        )
 
1028
 
1050
1029
    def _get_text_store(self, transport, control_files):
1051
1030
        """See RepositoryFormat._get_text_store()."""
1052
1031
        return self._get_versioned_file_store('weaves',
1094
1073
        text_store = self._get_text_store(repo_transport, control_files)
1095
1074
        control_store = self._get_control_store(repo_transport, control_files)
1096
1075
        _revision_store = self._get_revision_store(repo_transport, control_files)
1097
 
        return KnitRepository(_format=self,
1098
 
                              a_bzrdir=a_bzrdir,
1099
 
                              control_files=control_files,
1100
 
                              _revision_store=_revision_store,
1101
 
                              control_store=control_store,
1102
 
                              text_store=text_store)
 
1076
        return MetaDirRepository(_format=self,
 
1077
                                 a_bzrdir=a_bzrdir,
 
1078
                                 control_files=control_files,
 
1079
                                 _revision_store=_revision_store,
 
1080
                                 control_store=control_store,
 
1081
                                 text_store=text_store)
1103
1082
 
1104
1083
 
1105
1084
class RepositoryFormatKnit1(MetaDirRepositoryFormat):
1119
1098
        """See RepositoryFormat.get_format_string()."""
1120
1099
        return "Bazaar-NG Knit Repository Format 1"
1121
1100
 
 
1101
    def _get_revision_store(self, repo_transport, control_files):
 
1102
        """See RepositoryFormat._get_revision_store()."""
 
1103
        from bzrlib.store.revision.knit import KnitRevisionStore
 
1104
        versioned_file_store = VersionedFileStore(
 
1105
            repo_transport.clone('revision-store'),
 
1106
            file_mode = control_files._file_mode,
 
1107
            prefixed=False,
 
1108
            versionedfile_class=KnitVersionedFile)
 
1109
        return KnitRevisionStore(versioned_file_store)
 
1110
 
1122
1111
    def _get_text_store(self, transport, control_files):
1123
1112
        """See RepositoryFormat._get_text_store()."""
1124
1113
        return self._get_versioned_file_store('knits',
1156
1145
            bzrlib.transactions.PassThroughTransaction())
1157
1146
        return self.open(a_bzrdir=a_bzrdir, _found=True)
1158
1147
 
 
1148
    def open(self, a_bzrdir, _found=False, _override_transport=None):
 
1149
        """See RepositoryFormat.open().
 
1150
        
 
1151
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
 
1152
                                    repository at a slightly different url
 
1153
                                    than normal. I.e. during 'upgrade'.
 
1154
        """
 
1155
        if not _found:
 
1156
            format = RepositoryFormat.find_format(a_bzrdir)
 
1157
            assert format.__class__ ==  self.__class__
 
1158
        if _override_transport is not None:
 
1159
            repo_transport = _override_transport
 
1160
        else:
 
1161
            repo_transport = a_bzrdir.get_repository_transport(None)
 
1162
        control_files = LockableFiles(repo_transport, 'lock')
 
1163
        text_store = self._get_text_store(repo_transport, control_files)
 
1164
        control_store = self._get_control_store(repo_transport, control_files)
 
1165
        _revision_store = self._get_revision_store(repo_transport, control_files)
 
1166
        return KnitRepository(_format=self,
 
1167
                              a_bzrdir=a_bzrdir,
 
1168
                              control_files=control_files,
 
1169
                              _revision_store=_revision_store,
 
1170
                              control_store=control_store,
 
1171
                              text_store=text_store)
 
1172
 
1159
1173
 
1160
1174
# formats which have no format string are not discoverable
1161
1175
# and not independently creatable, so are not registered.
1201
1215
        # grab the basis available data
1202
1216
        if basis is not None:
1203
1217
            self.target.fetch(basis, revision_id=revision_id)
1204
 
        # but dont both fetching if we have the needed data now.
 
1218
        # but dont bother fetching if we have the needed data now.
1205
1219
        if (revision_id not in (None, NULL_REVISION) and 
1206
1220
            self.target.has_revision(revision_id)):
1207
1221
            return
1232
1246
        Returns the copied revision count and the failed revisions in a tuple:
1233
1247
        (copied, failures).
1234
1248
        """
1235
 
        from bzrlib.fetch import RepoFetcher
 
1249
        from bzrlib.fetch import GenericRepoFetcher
1236
1250
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
1237
1251
               self.source, self.source._format, self.target, self.target._format)
1238
 
        f = RepoFetcher(to_repository=self.target,
1239
 
                        from_repository=self.source,
1240
 
                        last_revision=revision_id,
1241
 
                        pb=pb)
 
1252
        f = GenericRepoFetcher(to_repository=self.target,
 
1253
                               from_repository=self.source,
 
1254
                               last_revision=revision_id,
 
1255
                               pb=pb)
1242
1256
        return f.count_copied, f.failed_revisions
1243
1257
 
1244
1258
    def lock_read(self):
1340
1354
                self.target.control_weaves.copy_multi(
1341
1355
                    self.source.control_weaves, ['inventory'],
1342
1356
                    from_transaction=self.source.get_transaction())
1343
 
                self.target.revision_store._text_store.copy_all_ids(
 
1357
                self.target._revision_store.text_store.copy_all_ids(
1344
1358
                    self.source._revision_store.text_store,
1345
1359
                    pb=pb)
1346
1360
            else:
1349
1363
    @needs_write_lock
1350
1364
    def fetch(self, revision_id=None, pb=None):
1351
1365
        """See InterRepository.fetch()."""
1352
 
        from bzrlib.fetch import RepoFetcher
 
1366
        from bzrlib.fetch import GenericRepoFetcher
1353
1367
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
1354
1368
               self.source, self.source._format, self.target, self.target._format)
1355
 
        f = RepoFetcher(to_repository=self.target,
1356
 
                        from_repository=self.source,
1357
 
                        last_revision=revision_id,
1358
 
                        pb=pb)
 
1369
        f = GenericRepoFetcher(to_repository=self.target,
 
1370
                               from_repository=self.source,
 
1371
                               last_revision=revision_id,
 
1372
                               pb=pb)
1359
1373
        return f.count_copied, f.failed_revisions
1360
1374
 
1361
1375
    @needs_read_lock
1399
1413
            return self.source._eliminate_revisions_not_present(required_topo_revisions)
1400
1414
 
1401
1415
 
 
1416
class InterKnitRepo(InterRepository):
 
1417
    """Optimised code paths between Knit based repositories."""
 
1418
 
 
1419
    _matching_repo_format = RepositoryFormatKnit1()
 
1420
    """Repository format for testing with."""
 
1421
 
 
1422
    @staticmethod
 
1423
    def is_compatible(source, target):
 
1424
        """Be compatible with known Knit formats.
 
1425
        
 
1426
        We dont test for the stores being of specific types becase that
 
1427
        could lead to confusing results, and there is no need to be 
 
1428
        overly general.
 
1429
        """
 
1430
        try:
 
1431
            return (isinstance(source._format, (RepositoryFormatKnit1)) and
 
1432
                    isinstance(target._format, (RepositoryFormatKnit1)))
 
1433
        except AttributeError:
 
1434
            return False
 
1435
 
 
1436
    @needs_write_lock
 
1437
    def fetch(self, revision_id=None, pb=None):
 
1438
        """See InterRepository.fetch()."""
 
1439
        from bzrlib.fetch import KnitRepoFetcher
 
1440
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
 
1441
               self.source, self.source._format, self.target, self.target._format)
 
1442
        f = KnitRepoFetcher(to_repository=self.target,
 
1443
                            from_repository=self.source,
 
1444
                            last_revision=revision_id,
 
1445
                            pb=pb)
 
1446
        return f.count_copied, f.failed_revisions
 
1447
 
 
1448
    @needs_read_lock
 
1449
    def missing_revision_ids(self, revision_id=None):
 
1450
        """See InterRepository.missing_revision_ids()."""
 
1451
        if revision_id is not None:
 
1452
            source_ids = self.source.get_ancestry(revision_id)
 
1453
            assert source_ids.pop(0) == None
 
1454
        else:
 
1455
            source_ids = self.source._all_possible_ids()
 
1456
        source_ids_set = set(source_ids)
 
1457
        # source_ids is the worst possible case we may need to pull.
 
1458
        # now we want to filter source_ids against what we actually
 
1459
        # have in target, but dont try to check for existence where we know
 
1460
        # we do not have a revision as that would be pointless.
 
1461
        target_ids = set(self.target._all_possible_ids())
 
1462
        possibly_present_revisions = target_ids.intersection(source_ids_set)
 
1463
        actually_present_revisions = set(self.target._eliminate_revisions_not_present(possibly_present_revisions))
 
1464
        required_revisions = source_ids_set.difference(actually_present_revisions)
 
1465
        required_topo_revisions = [rev_id for rev_id in source_ids if rev_id in required_revisions]
 
1466
        if revision_id is not None:
 
1467
            # we used get_ancestry to determine source_ids then we are assured all
 
1468
            # revisions referenced are present as they are installed in topological order.
 
1469
            # and the tip revision was validated by get_ancestry.
 
1470
            return required_topo_revisions
 
1471
        else:
 
1472
            # if we just grabbed the possibly available ids, then 
 
1473
            # we only have an estimate of whats available and need to validate
 
1474
            # that against the revision records.
 
1475
            return self.source._eliminate_revisions_not_present(required_topo_revisions)
 
1476
 
1402
1477
InterRepository.register_optimiser(InterWeaveRepo)
 
1478
InterRepository.register_optimiser(InterKnitRepo)
1403
1479
 
1404
1480
 
1405
1481
class RepositoryTestProviderAdapter(object):