/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 bzrlib/repository.py

Upgraded to the latest bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    lockdir,
35
35
    osutils,
36
36
    registry,
 
37
    remote,
37
38
    revision as _mod_revision,
38
39
    symbol_versioning,
39
40
    transactions,
231
232
    def is_locked(self):
232
233
        return self.control_files.is_locked()
233
234
 
234
 
    def lock_write(self):
235
 
        self.control_files.lock_write()
 
235
    def lock_write(self, token=None):
 
236
        """Lock this repository for writing.
 
237
        
 
238
        :param token: if this is already locked, then lock_write will fail
 
239
            unless the token matches the existing lock.
 
240
        :returns: a token if this instance supports tokens, otherwise None.
 
241
        :raises TokenLockingNotSupported: when a token is given but this
 
242
            instance doesn't support using token locks.
 
243
        :raises MismatchedToken: if the specified token doesn't match the token
 
244
            of the existing lock.
 
245
 
 
246
        A token should be passed in if you know that you have locked the object
 
247
        some other way, and need to synchronise this object's state with that
 
248
        fact.
 
249
 
 
250
        XXX: this docstring is duplicated in many places, e.g. lockable_files.py
 
251
        """
 
252
        return self.control_files.lock_write(token=token)
236
253
 
237
254
    def lock_read(self):
238
255
        self.control_files.lock_read()
240
257
    def get_physical_lock_status(self):
241
258
        return self.control_files.get_physical_lock_status()
242
259
 
 
260
    def leave_lock_in_place(self):
 
261
        """Tell this repository not to release the physical lock when this
 
262
        object is unlocked.
 
263
        
 
264
        If lock_write doesn't return a token, then this method is not supported.
 
265
        """
 
266
        self.control_files.leave_in_place()
 
267
 
 
268
    def dont_leave_lock_in_place(self):
 
269
        """Tell this repository to release the physical lock when this
 
270
        object is unlocked, even if it didn't originally acquire it.
 
271
 
 
272
        If lock_write doesn't return a token, then this method is not supported.
 
273
        """
 
274
        self.control_files.dont_leave_in_place()
 
275
 
243
276
    @needs_read_lock
244
277
    def gather_stats(self, revid=None, committers=None):
245
278
        """Gather statistics from a revision id.
311
344
        control = bzrdir.BzrDir.open(base)
312
345
        return control.open_repository()
313
346
 
314
 
    def copy_content_into(self, destination, revision_id=None, basis=None):
 
347
    def copy_content_into(self, destination, revision_id=None):
315
348
        """Make a complete copy of the content in self into destination.
316
349
        
317
350
        This is a destructive operation! Do not use it on existing 
318
351
        repositories.
319
352
        """
320
353
        revision_id = osutils.safe_revision_id(revision_id)
321
 
        return InterRepository.get(self, destination).copy_content(revision_id, basis)
 
354
        return InterRepository.get(self, destination).copy_content(revision_id)
322
355
 
323
356
    def fetch(self, source, revision_id=None, pb=None):
324
357
        """Fetch the content required to construct revision_id from source.
326
359
        If revision_id is None all content is copied.
327
360
        """
328
361
        revision_id = osutils.safe_revision_id(revision_id)
329
 
        return InterRepository.get(source, self).fetch(revision_id=revision_id,
330
 
                                                       pb=pb)
 
362
        inter = InterRepository.get(source, self)
 
363
        try:
 
364
            return inter.fetch(revision_id=revision_id, pb=pb)
 
365
        except NotImplementedError:
 
366
            raise errors.IncompatibleRepositories(source, self)
331
367
 
332
368
    def get_commit_builder(self, branch, parents, config, timestamp=None, 
333
369
                           timezone=None, committer=None, revprops=None, 
351
387
        self.control_files.unlock()
352
388
 
353
389
    @needs_read_lock
354
 
    def clone(self, a_bzrdir, revision_id=None, basis=None):
 
390
    def clone(self, a_bzrdir, revision_id=None):
355
391
        """Clone this repository into a_bzrdir using the current format.
356
392
 
357
393
        Currently no check is made that the format of this repository and
369
405
                dest_repo = self._format.initialize(a_bzrdir, shared=self.is_shared())
370
406
            except errors.UninitializableFormat:
371
407
                dest_repo = a_bzrdir.open_repository()
372
 
        self.copy_content_into(dest_repo, revision_id, basis)
 
408
        self.copy_content_into(dest_repo, revision_id)
373
409
        return dest_repo
374
410
 
375
411
    @needs_read_lock
1175
1211
 
1176
1212
        :param a_bzrdir: The bzrdir to put the new repository in it.
1177
1213
        :param shared: The repository should be initialized as a sharable one.
1178
 
 
 
1214
        :returns: The new repository object.
 
1215
        
1179
1216
        This may raise UninitializableFormat if shared repository are not
1180
1217
        compatible the a_bzrdir.
1181
1218
        """
 
1219
        raise NotImplementedError(self.initialize)
1182
1220
 
1183
1221
    def is_supported(self):
1184
1222
        """Is this format supported?
1204
1242
    """Common base class for the new repositories using the metadir layout."""
1205
1243
 
1206
1244
    rich_root_data = False
1207
 
    support_tree_reference = False
 
1245
    supports_tree_reference = False
1208
1246
    _matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1209
1247
 
1210
1248
    def __init__(self):
1280
1318
    _optimisers = []
1281
1319
    """The available optimised InterRepository types."""
1282
1320
 
1283
 
    def copy_content(self, revision_id=None, basis=None):
 
1321
    def copy_content(self, revision_id=None):
1284
1322
        raise NotImplementedError(self.copy_content)
1285
1323
 
1286
1324
    def fetch(self, revision_id=None, pb=None):
1338
1376
 
1339
1377
    @staticmethod
1340
1378
    def is_compatible(source, target):
1341
 
        if not isinstance(source, Repository):
1342
 
            return False
1343
 
        if not isinstance(target, Repository):
1344
 
            return False
1345
 
        if source._format.rich_root_data != target._format.rich_root_data:
 
1379
        if source.supports_rich_root() != target.supports_rich_root():
1346
1380
            return False
1347
1381
        if source._serializer != target._serializer:
1348
1382
            return False
1349
 
        else:
1350
 
            return True 
 
1383
        return True
1351
1384
 
1352
1385
    @needs_write_lock
1353
 
    def copy_content(self, revision_id=None, basis=None):
 
1386
    def copy_content(self, revision_id=None):
1354
1387
        """Make a complete copy of the content in self into destination.
1355
1388
        
1356
1389
        This is a destructive operation! Do not use it on existing 
1358
1391
 
1359
1392
        :param revision_id: Only copy the content needed to construct
1360
1393
                            revision_id and its parents.
1361
 
        :param basis: Copy the needed data preferentially from basis.
1362
1394
        """
1363
1395
        try:
1364
1396
            self.target.set_make_working_trees(self.source.make_working_trees())
1367
1399
        # TODO: jam 20070210 This is fairly internal, so we should probably
1368
1400
        #       just assert that revision_id is not unicode.
1369
1401
        revision_id = osutils.safe_revision_id(revision_id)
1370
 
        # grab the basis available data
1371
 
        if basis is not None:
1372
 
            self.target.fetch(basis, revision_id=revision_id)
1373
1402
        # but don't bother fetching if we have the needed data now.
1374
1403
        if (revision_id not in (None, _mod_revision.NULL_REVISION) and 
1375
1404
            self.target.has_revision(revision_id)):
1424
1453
            return False
1425
1454
    
1426
1455
    @needs_write_lock
1427
 
    def copy_content(self, revision_id=None, basis=None):
 
1456
    def copy_content(self, revision_id=None):
1428
1457
        """See InterRepository.copy_content()."""
1429
1458
        # weave specific optimised path:
1430
1459
        # TODO: jam 20070210 Internal, should be an assert, not translate
1431
1460
        revision_id = osutils.safe_revision_id(revision_id)
1432
 
        if basis is not None:
1433
 
            # copy the basis in, then fetch remaining data.
1434
 
            basis.copy_content_into(self.target, revision_id)
1435
 
            # the basis copy_content_into could miss-set this.
 
1461
        try:
 
1462
            self.target.set_make_working_trees(self.source.make_working_trees())
 
1463
        except NotImplementedError:
 
1464
            pass
 
1465
        # FIXME do not peek!
 
1466
        if self.source.control_files._transport.listable():
 
1467
            pb = ui.ui_factory.nested_progress_bar()
1436
1468
            try:
1437
 
                self.target.set_make_working_trees(self.source.make_working_trees())
1438
 
            except NotImplementedError:
1439
 
                pass
 
1469
                self.target.weave_store.copy_all_ids(
 
1470
                    self.source.weave_store,
 
1471
                    pb=pb,
 
1472
                    from_transaction=self.source.get_transaction(),
 
1473
                    to_transaction=self.target.get_transaction())
 
1474
                pb.update('copying inventory', 0, 1)
 
1475
                self.target.control_weaves.copy_multi(
 
1476
                    self.source.control_weaves, ['inventory'],
 
1477
                    from_transaction=self.source.get_transaction(),
 
1478
                    to_transaction=self.target.get_transaction())
 
1479
                self.target._revision_store.text_store.copy_all_ids(
 
1480
                    self.source._revision_store.text_store,
 
1481
                    pb=pb)
 
1482
            finally:
 
1483
                pb.finished()
 
1484
        else:
1440
1485
            self.target.fetch(self.source, revision_id=revision_id)
1441
 
        else:
1442
 
            try:
1443
 
                self.target.set_make_working_trees(self.source.make_working_trees())
1444
 
            except NotImplementedError:
1445
 
                pass
1446
 
            # FIXME do not peek!
1447
 
            if self.source.control_files._transport.listable():
1448
 
                pb = ui.ui_factory.nested_progress_bar()
1449
 
                try:
1450
 
                    self.target.weave_store.copy_all_ids(
1451
 
                        self.source.weave_store,
1452
 
                        pb=pb,
1453
 
                        from_transaction=self.source.get_transaction(),
1454
 
                        to_transaction=self.target.get_transaction())
1455
 
                    pb.update('copying inventory', 0, 1)
1456
 
                    self.target.control_weaves.copy_multi(
1457
 
                        self.source.control_weaves, ['inventory'],
1458
 
                        from_transaction=self.source.get_transaction(),
1459
 
                        to_transaction=self.target.get_transaction())
1460
 
                    self.target._revision_store.text_store.copy_all_ids(
1461
 
                        self.source._revision_store.text_store,
1462
 
                        pb=pb)
1463
 
                finally:
1464
 
                    pb.finished()
1465
 
            else:
1466
 
                self.target.fetch(self.source, revision_id=revision_id)
1467
1486
 
1468
1487
    @needs_write_lock
1469
1488
    def fetch(self, revision_id=None, pb=None):
1597
1616
 
1598
1617
    @staticmethod
1599
1618
    def is_compatible(source, target):
1600
 
        if not isinstance(source, Repository):
1601
 
            return False
1602
 
        if not isinstance(target, Repository):
1603
 
            return False
1604
 
        if not source._format.rich_root_data and target._format.rich_root_data:
 
1619
        if not source.supports_rich_root() and target.supports_rich_root():
1605
1620
            return True
1606
1621
        else:
1607
1622
            return False
1619
1634
        return f.count_copied, f.failed_revisions
1620
1635
 
1621
1636
    @needs_write_lock
1622
 
    def copy_content(self, revision_id=None, basis=None):
 
1637
    def copy_content(self, revision_id=None):
1623
1638
        """Make a complete copy of the content in self into destination.
1624
1639
        
1625
1640
        This is a destructive operation! Do not use it on existing 
1627
1642
 
1628
1643
        :param revision_id: Only copy the content needed to construct
1629
1644
                            revision_id and its parents.
1630
 
        :param basis: Copy the needed data preferentially from basis.
1631
1645
        """
1632
1646
        try:
1633
1647
            self.target.set_make_working_trees(self.source.make_working_trees())
1635
1649
            pass
1636
1650
        # TODO: jam 20070210 Internal, assert, don't translate
1637
1651
        revision_id = osutils.safe_revision_id(revision_id)
1638
 
        # grab the basis available data
1639
 
        if basis is not None:
1640
 
            self.target.fetch(basis, revision_id=revision_id)
1641
1652
        # but don't bother fetching if we have the needed data now.
1642
1653
        if (revision_id not in (None, _mod_revision.NULL_REVISION) and 
1643
1654
            self.target.has_revision(revision_id)):
1679
1690
        return f.count_copied, f.failed_revisions
1680
1691
 
1681
1692
 
 
1693
class InterRemoteRepository(InterRepository):
 
1694
    """Code for converting between RemoteRepository objects.
 
1695
 
 
1696
    This just gets an non-remote repository from the RemoteRepository, and calls
 
1697
    InterRepository.get again.
 
1698
    """
 
1699
 
 
1700
    def __init__(self, source, target):
 
1701
        if isinstance(source, remote.RemoteRepository):
 
1702
            source._ensure_real()
 
1703
            real_source = source._real_repository
 
1704
        else:
 
1705
            real_source = source
 
1706
        if isinstance(target, remote.RemoteRepository):
 
1707
            target._ensure_real()
 
1708
            real_target = target._real_repository
 
1709
        else:
 
1710
            real_target = target
 
1711
        self.real_inter = InterRepository.get(real_source, real_target)
 
1712
 
 
1713
    @staticmethod
 
1714
    def is_compatible(source, target):
 
1715
        if isinstance(source, remote.RemoteRepository):
 
1716
            return True
 
1717
        if isinstance(target, remote.RemoteRepository):
 
1718
            return True
 
1719
        return False
 
1720
 
 
1721
    def copy_content(self, revision_id=None):
 
1722
        self.real_inter.copy_content(revision_id=revision_id)
 
1723
 
 
1724
    def fetch(self, revision_id=None, pb=None):
 
1725
        self.real_inter.fetch(revision_id=revision_id, pb=pb)
 
1726
 
 
1727
    @classmethod
 
1728
    def _get_repo_format_to_test(self):
 
1729
        return None
 
1730
 
 
1731
 
1682
1732
InterRepository.register_optimiser(InterSameDataRepository)
1683
1733
InterRepository.register_optimiser(InterWeaveRepo)
1684
1734
InterRepository.register_optimiser(InterKnitRepo)
1685
1735
InterRepository.register_optimiser(InterModel1and2)
1686
1736
InterRepository.register_optimiser(InterKnit1and2)
 
1737
InterRepository.register_optimiser(InterRemoteRepository)
1687
1738
 
1688
1739
 
1689
1740
class RepositoryTestProviderAdapter(object):
1695
1746
    to make it easy to identify.
1696
1747
    """
1697
1748
 
1698
 
    def __init__(self, transport_server, transport_readonly_server, formats):
 
1749
    def __init__(self, transport_server, transport_readonly_server, formats,
 
1750
                 vfs_transport_factory=None):
1699
1751
        self._transport_server = transport_server
1700
1752
        self._transport_readonly_server = transport_readonly_server
 
1753
        self._vfs_transport_factory = vfs_transport_factory
1701
1754
        self._formats = formats
1702
1755
    
1703
1756
    def adapt(self, test):
1707
1760
            new_test = deepcopy(test)
1708
1761
            new_test.transport_server = self._transport_server
1709
1762
            new_test.transport_readonly_server = self._transport_readonly_server
 
1763
            # Only override the test's vfs_transport_factory if one was
 
1764
            # specified, otherwise just leave the default in place.
 
1765
            if self._vfs_transport_factory:
 
1766
                new_test.vfs_transport_factory = self._vfs_transport_factory
1710
1767
            new_test.bzrdir_format = bzrdir_format
1711
1768
            new_test.repository_format = repository_format
1712
1769
            def make_new_test_id():