/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

  • Committer: John Arbash Meinel
  • Date: 2006-10-06 05:53:44 UTC
  • mfrom: (2063 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006055344-e73b97b7c6ca6e72
[merge] bzr.dev 2063

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
directories.
21
21
"""
22
22
 
 
23
# TODO: remove unittest dependency; put that stuff inside the test suite
 
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
 
23
31
from cStringIO import StringIO
24
32
import os
25
33
 
90
98
        """Return true if this bzrdir is one whose format we can convert from."""
91
99
        return True
92
100
 
 
101
    def check_conversion_target(self, target_format):
 
102
        target_repo_format = target_format.repository_format
 
103
        source_repo_format = self._format.repository_format
 
104
        source_repo_format.check_conversion_target(target_repo_format)
 
105
 
93
106
    @staticmethod
94
107
    def _check_supported(format, allow_unsupported):
95
108
        """Check whether format is a supported format.
296
309
        This will use the current default BzrDirFormat, and use whatever 
297
310
        repository format that that uses for bzrdirformat.create_repository.
298
311
 
299
 
        ;param shared: Create a shared repository rather than a standalone
 
312
        :param shared: Create a shared repository rather than a standalone
300
313
                       repository.
301
314
        The Repository object is returned.
302
315
 
317
330
        repository format that that uses for bzrdirformat.create_workingtree,
318
331
        create_branch and create_repository.
319
332
 
320
 
        The WorkingTree object is returned.
 
333
        :return: The WorkingTree object.
321
334
        """
322
335
        t = get_transport(safe_unicode(base))
323
336
        if not isinstance(t, LocalTransport):
333
346
        """
334
347
        raise NotImplementedError(self.create_workingtree)
335
348
 
 
349
    def destroy_workingtree(self):
 
350
        """Destroy the working tree at this BzrDir.
 
351
 
 
352
        Formats that do not support this may raise UnsupportedOperation.
 
353
        """
 
354
        raise NotImplementedError(self.destroy_workingtree)
 
355
 
 
356
    def destroy_workingtree_metadata(self):
 
357
        """Destroy the control files for the working tree at this BzrDir.
 
358
 
 
359
        The contents of working tree files are not affected.
 
360
        Formats that do not support this may raise UnsupportedOperation.
 
361
        """
 
362
        raise NotImplementedError(self.destroy_workingtree_metadata)
 
363
 
336
364
    def find_repository(self):
337
365
        """Find the repository that should be used for a_bzrdir.
338
366
 
464
492
        _unsupported is a private parameter to the BzrDir class.
465
493
        """
466
494
        t = get_transport(base)
467
 
        # mutter("trying to open %r with transport %r", base, t)
468
 
        format = BzrDirFormat.find_format(t)
 
495
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
 
496
 
 
497
    @staticmethod
 
498
    def open_from_transport(transport, _unsupported=False):
 
499
        """Open a bzrdir within a particular directory.
 
500
 
 
501
        :param transport: Transport containing the bzrdir.
 
502
        :param _unsupported: private.
 
503
        """
 
504
        format = BzrDirFormat.find_format(transport)
469
505
        BzrDir._check_supported(format, _unsupported)
470
 
        return format.open(t, _found=True)
 
506
        return format.open(transport, _found=True)
471
507
 
472
508
    def open_branch(self, unsupported=False):
473
509
        """Open the branch object at this BzrDir if one is present.
507
543
        url = a_transport.base
508
544
        while True:
509
545
            try:
510
 
                format = BzrDirFormat.find_format(a_transport)
511
 
                BzrDir._check_supported(format, False)
512
 
                return format.open(a_transport), urlutils.unescape(a_transport.relpath(url))
 
546
                result = BzrDir.open_from_transport(a_transport)
 
547
                return result, urlutils.unescape(a_transport.relpath(url))
513
548
            except errors.NotBranchError, e:
514
 
                ## mutter('not a branch in: %r %s', a_transport.base, e)
515
549
                pass
516
550
            new_t = a_transport.clone('..')
517
551
            if new_t.base == a_transport.base:
567
601
        except errors.NoWorkingTree:
568
602
            return False
569
603
 
 
604
    def cloning_metadir(self, basis=None):
 
605
        """Produce a metadir suitable for cloning with"""
 
606
        def related_repository(bzrdir):
 
607
            try:
 
608
                branch = bzrdir.open_branch()
 
609
                return branch.repository
 
610
            except errors.NotBranchError:
 
611
                source_branch = None
 
612
                return bzrdir.open_repository()
 
613
        result_format = self._format.__class__()
 
614
        try:
 
615
            try:
 
616
                source_repository = related_repository(self)
 
617
            except errors.NoRepositoryPresent:
 
618
                if basis is None:
 
619
                    raise
 
620
                source_repository = related_repository(self)
 
621
            result_format.repository_format = source_repository._format
 
622
        except errors.NoRepositoryPresent:
 
623
            pass
 
624
        return result_format
 
625
 
570
626
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
571
627
        """Create a copy of this bzrdir prepared for use as a new line of
572
628
        development.
582
638
            itself to download less data.
583
639
        """
584
640
        self._make_tail(url)
585
 
        result = self._format.initialize(url)
 
641
        cloning_format = self.cloning_metadir(basis)
 
642
        result = cloning_format.initialize(url)
586
643
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
587
644
        try:
588
645
            source_branch = self.open_branch()
697
754
                result.set_parent_ids([revision_id])
698
755
        return result
699
756
 
 
757
    def destroy_workingtree(self):
 
758
        """See BzrDir.destroy_workingtree."""
 
759
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
 
760
 
 
761
    def destroy_workingtree_metadata(self):
 
762
        """See BzrDir.destroy_workingtree_metadata."""
 
763
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
 
764
                                          self)
 
765
 
700
766
    def get_branch_transport(self, branch_format):
701
767
        """See BzrDir.get_branch_transport()."""
702
768
        if branch_format is None:
842
908
        from bzrlib.workingtree import WorkingTreeFormat
843
909
        return WorkingTreeFormat.get_default_format().initialize(self, revision_id)
844
910
 
 
911
    def destroy_workingtree(self):
 
912
        """See BzrDir.destroy_workingtree."""
 
913
        wt = self.open_workingtree()
 
914
        repository = wt.branch.repository
 
915
        empty = repository.revision_tree(bzrlib.revision.NULL_REVISION)
 
916
        wt.revert([], old_tree=empty)
 
917
        self.destroy_workingtree_metadata()
 
918
 
 
919
    def destroy_workingtree_metadata(self):
 
920
        self.transport.delete_tree('checkout')
 
921
 
845
922
    def _get_mkdir_mode(self):
846
923
        """Figure out the mode to use when creating a bzrdir subdir."""
847
924
        temp_control = lockable_files.LockableFiles(self.transport, '',
1063
1140
        """
1064
1141
        return True
1065
1142
 
 
1143
    def same_model(self, target_format):
 
1144
        return (self.repository_format.rich_root_data == 
 
1145
            target_format.rich_root_data)
 
1146
 
1066
1147
    @classmethod
1067
1148
    def known_formats(klass):
1068
1149
        """Return all the known formats.
1184
1265
    def __return_repository_format(self):
1185
1266
        """Circular import protection."""
1186
1267
        from bzrlib.repository import RepositoryFormat4
1187
 
        return RepositoryFormat4(self)
 
1268
        return RepositoryFormat4()
1188
1269
    repository_format = property(__return_repository_format)
1189
1270
 
1190
1271
 
1244
1325
    def __return_repository_format(self):
1245
1326
        """Circular import protection."""
1246
1327
        from bzrlib.repository import RepositoryFormat5
1247
 
        return RepositoryFormat5(self)
 
1328
        return RepositoryFormat5()
1248
1329
    repository_format = property(__return_repository_format)
1249
1330
 
1250
1331
 
1303
1384
    def __return_repository_format(self):
1304
1385
        """Circular import protection."""
1305
1386
        from bzrlib.repository import RepositoryFormat6
1306
 
        return RepositoryFormat6(self)
 
1387
        return RepositoryFormat6()
1307
1388
    repository_format = property(__return_repository_format)
1308
1389
 
1309
1390
 
1549
1630
        assert rev_id not in self.converted_revs
1550
1631
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
1551
1632
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
 
1633
        inv.revision_id = rev_id
1552
1634
        rev = self.revisions[rev_id]
1553
1635
        if rev.inventory_sha1:
1554
1636
            assert rev.inventory_sha1 == sha_string(old_inv_xml), \