/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):
330
341
        """
331
342
        raise NotImplementedError(self.create_workingtree)
332
343
 
 
344
    def destroy_workingtree(self):
 
345
        """Destroy the working tree at this BzrDir.
 
346
 
 
347
        Formats that do not support this may raise UnsupportedOperation.
 
348
        """
 
349
        raise NotImplementedError(self.destroy_workingtree)
 
350
 
 
351
    def destroy_workingtree_metadata(self):
 
352
        """Destroy the control files for the working tree at this BzrDir.
 
353
 
 
354
        The contents of working tree files are not affected.
 
355
        Formats that do not support this may raise UnsupportedOperation.
 
356
        """
 
357
        raise NotImplementedError(self.destroy_workingtree_metadata)
 
358
 
333
359
    def find_repository(self):
334
360
        """Find the repository that should be used for a_bzrdir.
335
361
 
461
487
        _unsupported is a private parameter to the BzrDir class.
462
488
        """
463
489
        t = get_transport(base)
464
 
        # mutter("trying to open %r with transport %r", base, t)
465
 
        format = BzrDirFormat.find_format(t)
 
490
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
 
491
 
 
492
    @staticmethod
 
493
    def open_from_transport(transport, _unsupported=False):
 
494
        """Open a bzrdir within a particular directory.
 
495
 
 
496
        :param transport: Transport containing the bzrdir.
 
497
        :param _unsupported: private.
 
498
        """
 
499
        format = BzrDirFormat.find_format(transport)
466
500
        BzrDir._check_supported(format, _unsupported)
467
 
        return format.open(t, _found=True)
 
501
        return format.open(transport, _found=True)
468
502
 
469
503
    def open_branch(self, unsupported=False):
470
504
        """Open the branch object at this BzrDir if one is present.
504
538
        url = a_transport.base
505
539
        while True:
506
540
            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))
 
541
                result = BzrDir.open_from_transport(a_transport)
 
542
                return result, urlutils.unescape(a_transport.relpath(url))
510
543
            except errors.NotBranchError, e:
511
 
                ## mutter('not a branch in: %r %s', a_transport.base, e)
512
544
                pass
513
545
            new_t = a_transport.clone('..')
514
546
            if new_t.base == a_transport.base:
564
596
        except errors.NoWorkingTree:
565
597
            return False
566
598
 
 
599
    def cloning_metadir(self, basis=None):
 
600
        """Produce a metadir suitable for cloning with"""
 
601
        def related_repository(bzrdir):
 
602
            try:
 
603
                branch = bzrdir.open_branch()
 
604
                return branch.repository
 
605
            except errors.NotBranchError:
 
606
                source_branch = None
 
607
                return bzrdir.open_repository()
 
608
        result_format = self._format.__class__()
 
609
        try:
 
610
            try:
 
611
                source_repository = related_repository(self)
 
612
            except errors.NoRepositoryPresent:
 
613
                if basis is None:
 
614
                    raise
 
615
                source_repository = related_repository(self)
 
616
            result_format.repository_format = source_repository._format
 
617
        except errors.NoRepositoryPresent:
 
618
            pass
 
619
        return result_format
 
620
 
567
621
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
568
622
        """Create a copy of this bzrdir prepared for use as a new line of
569
623
        development.
579
633
            itself to download less data.
580
634
        """
581
635
        self._make_tail(url)
582
 
        result = self._format.initialize(url)
 
636
        cloning_format = self.cloning_metadir(basis)
 
637
        result = cloning_format.initialize(url)
583
638
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
584
639
        try:
585
640
            source_branch = self.open_branch()
693
748
                result.set_parent_ids([revision_id])
694
749
        return result
695
750
 
 
751
    def destroy_workingtree(self):
 
752
        """See BzrDir.destroy_workingtree."""
 
753
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
 
754
 
 
755
    def destroy_workingtree_metadata(self):
 
756
        """See BzrDir.destroy_workingtree_metadata."""
 
757
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
 
758
                                          self)
 
759
 
696
760
    def get_branch_transport(self, branch_format):
697
761
        """See BzrDir.get_branch_transport()."""
698
762
        if branch_format is None:
838
902
        from bzrlib.workingtree import WorkingTreeFormat
839
903
        return WorkingTreeFormat.get_default_format().initialize(self, revision_id)
840
904
 
 
905
    def destroy_workingtree(self):
 
906
        """See BzrDir.destroy_workingtree."""
 
907
        wt = self.open_workingtree()
 
908
        repository = wt.branch.repository
 
909
        empty = repository.revision_tree(bzrlib.revision.NULL_REVISION)
 
910
        wt.revert([], old_tree=empty)
 
911
        self.destroy_workingtree_metadata()
 
912
 
 
913
    def destroy_workingtree_metadata(self):
 
914
        self.transport.delete_tree('checkout')
 
915
 
841
916
    def _get_mkdir_mode(self):
842
917
        """Figure out the mode to use when creating a bzrdir subdir."""
843
918
        temp_control = LockableFiles(self.transport, '', TransportLock)
1057
1132
        """
1058
1133
        return True
1059
1134
 
 
1135
    def same_model(self, target_format):
 
1136
        return (self.repository_format.rich_root_data == 
 
1137
            target_format.rich_root_data)
 
1138
 
1060
1139
    @classmethod
1061
1140
    def known_formats(klass):
1062
1141
        """Return all the known formats.
1178
1257
    def __return_repository_format(self):
1179
1258
        """Circular import protection."""
1180
1259
        from bzrlib.repository import RepositoryFormat4
1181
 
        return RepositoryFormat4(self)
 
1260
        return RepositoryFormat4()
1182
1261
    repository_format = property(__return_repository_format)
1183
1262
 
1184
1263
 
1238
1317
    def __return_repository_format(self):
1239
1318
        """Circular import protection."""
1240
1319
        from bzrlib.repository import RepositoryFormat5
1241
 
        return RepositoryFormat5(self)
 
1320
        return RepositoryFormat5()
1242
1321
    repository_format = property(__return_repository_format)
1243
1322
 
1244
1323
 
1297
1376
    def __return_repository_format(self):
1298
1377
        """Circular import protection."""
1299
1378
        from bzrlib.repository import RepositoryFormat6
1300
 
        return RepositoryFormat6(self)
 
1379
        return RepositoryFormat6()
1301
1380
    repository_format = property(__return_repository_format)
1302
1381
 
1303
1382
 
1542
1621
        assert rev_id not in self.converted_revs
1543
1622
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
1544
1623
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
 
1624
        inv.revision_id = rev_id
1545
1625
        rev = self.revisions[rev_id]
1546
1626
        if rev.inventory_sha1:
1547
1627
            assert rev.inventory_sha1 == sha_string(old_inv_xml), \
1570
1650
            entries = inv.iter_entries()
1571
1651
            entries.next()
1572
1652
            for path, ie in entries:
1573
 
                assert hasattr(ie, 'revision'), \
 
1653
                assert getattr(ie, 'revision', None) is not None, \
1574
1654
                    'no revision on {%s} in {%s}' % \
1575
1655
                    (file_id, rev.revision_id)
1576
1656
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)