/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/bzrdir.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
# TODO: remove unittest dependency; put that stuff inside the test suite
24
24
 
 
25
# TODO: The Format probe_transport seems a bit redundant with just trying to
 
26
# open the bzrdir. -- mbp
 
27
#
 
28
# TODO: Can we move specific formats into separate modules to make this file
 
29
# smaller?
 
30
 
25
31
from copy import deepcopy
26
32
from cStringIO import StringIO
27
33
import os
87
93
        """Return true if this bzrdir is one whose format we can convert from."""
88
94
        return True
89
95
 
 
96
    def check_conversion_target(self, target_format):
 
97
        target_repo_format = target_format.repository_format
 
98
        source_repo_format = self._format.repository_format
 
99
        source_repo_format.check_conversion_target(target_repo_format)
 
100
 
90
101
    @staticmethod
91
102
    def _check_supported(format, allow_unsupported):
92
103
        """Check whether format is a supported format.
293
304
        This will use the current default BzrDirFormat, and use whatever 
294
305
        repository format that that uses for bzrdirformat.create_repository.
295
306
 
296
 
        ;param shared: Create a shared repository rather than a standalone
 
307
        :param shared: Create a shared repository rather than a standalone
297
308
                       repository.
298
309
        The Repository object is returned.
299
310
 
314
325
        repository format that that uses for bzrdirformat.create_workingtree,
315
326
        create_branch and create_repository.
316
327
 
317
 
        The WorkingTree object is returned.
 
328
        :return: The WorkingTree object.
318
329
        """
319
330
        t = get_transport(safe_unicode(base))
320
331
        if not isinstance(t, LocalTransport):
461
472
        _unsupported is a private parameter to the BzrDir class.
462
473
        """
463
474
        t = get_transport(base)
464
 
        # mutter("trying to open %r with transport %r", base, t)
465
 
        format = BzrDirFormat.find_format(t)
 
475
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
 
476
 
 
477
    @staticmethod
 
478
    def open_from_transport(transport, _unsupported=False):
 
479
        """Open a bzrdir within a particular directory.
 
480
 
 
481
        :param transport: Transport containing the bzrdir.
 
482
        :param _unsupported: private.
 
483
        """
 
484
        format = BzrDirFormat.find_format(transport)
466
485
        BzrDir._check_supported(format, _unsupported)
467
 
        return format.open(t, _found=True)
 
486
        return format.open(transport, _found=True)
468
487
 
469
488
    def open_branch(self, unsupported=False):
470
489
        """Open the branch object at this BzrDir if one is present.
504
523
        url = a_transport.base
505
524
        while True:
506
525
            try:
507
 
                format = BzrDirFormat.find_format(a_transport)
508
 
                BzrDir._check_supported(format, False)
509
 
                return format.open(a_transport), urlutils.unescape(a_transport.relpath(url))
 
526
                result = BzrDir.open_from_transport(a_transport)
 
527
                return result, urlutils.unescape(a_transport.relpath(url))
510
528
            except errors.NotBranchError, e:
511
 
                ## mutter('not a branch in: %r %s', a_transport.base, e)
512
529
                pass
513
530
            new_t = a_transport.clone('..')
514
531
            if new_t.base == a_transport.base:
564
581
        except errors.NoWorkingTree:
565
582
            return False
566
583
 
 
584
    def cloning_metadir(self, basis=None):
 
585
        """Produce a metadir suitable for cloning with"""
 
586
        def related_repository(bzrdir):
 
587
            try:
 
588
                branch = bzrdir.open_branch()
 
589
                return branch.repository
 
590
            except errors.NotBranchError:
 
591
                source_branch = None
 
592
                return bzrdir.open_repository()
 
593
        result_format = self._format.__class__()
 
594
        try:
 
595
            try:
 
596
                source_repository = related_repository(self)
 
597
            except errors.NoRepositoryPresent:
 
598
                if basis is None:
 
599
                    raise
 
600
                source_repository = related_repository(self)
 
601
            result_format.repository_format = source_repository._format
 
602
        except errors.NoRepositoryPresent:
 
603
            pass
 
604
        return result_format
 
605
 
567
606
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
568
607
        """Create a copy of this bzrdir prepared for use as a new line of
569
608
        development.
579
618
            itself to download less data.
580
619
        """
581
620
        self._make_tail(url)
582
 
        result = self._format.initialize(url)
 
621
        cloning_format = self.cloning_metadir(basis)
 
622
        result = cloning_format.initialize(url)
583
623
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
584
624
        try:
585
625
            source_branch = self.open_branch()
1057
1097
        """
1058
1098
        return True
1059
1099
 
 
1100
    def same_model(self, target_format):
 
1101
        return (self.repository_format.rich_root_data == 
 
1102
            target_format.rich_root_data)
 
1103
 
1060
1104
    @classmethod
1061
1105
    def known_formats(klass):
1062
1106
        """Return all the known formats.
1178
1222
    def __return_repository_format(self):
1179
1223
        """Circular import protection."""
1180
1224
        from bzrlib.repository import RepositoryFormat4
1181
 
        return RepositoryFormat4(self)
 
1225
        return RepositoryFormat4()
1182
1226
    repository_format = property(__return_repository_format)
1183
1227
 
1184
1228
 
1238
1282
    def __return_repository_format(self):
1239
1283
        """Circular import protection."""
1240
1284
        from bzrlib.repository import RepositoryFormat5
1241
 
        return RepositoryFormat5(self)
 
1285
        return RepositoryFormat5()
1242
1286
    repository_format = property(__return_repository_format)
1243
1287
 
1244
1288
 
1297
1341
    def __return_repository_format(self):
1298
1342
        """Circular import protection."""
1299
1343
        from bzrlib.repository import RepositoryFormat6
1300
 
        return RepositoryFormat6(self)
 
1344
        return RepositoryFormat6()
1301
1345
    repository_format = property(__return_repository_format)
1302
1346
 
1303
1347
 
1542
1586
        assert rev_id not in self.converted_revs
1543
1587
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
1544
1588
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
 
1589
        inv.revision_id = rev_id
1545
1590
        rev = self.revisions[rev_id]
1546
1591
        if rev.inventory_sha1:
1547
1592
            assert rev.inventory_sha1 == sha_string(old_inv_xml), \
1570
1615
            entries = inv.iter_entries()
1571
1616
            entries.next()
1572
1617
            for path, ie in entries:
1573
 
                assert hasattr(ie, 'revision'), \
 
1618
                assert getattr(ie, 'revision', None) is not None, \
1574
1619
                    'no revision on {%s} in {%s}' % \
1575
1620
                    (file_id, rev.revision_id)
1576
1621
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)