/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 from by-reference-trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
432
432
        """Get the transport for use by workingtree format in this BzrDir.
433
433
 
434
434
        Note that bzr dirs that do not support format strings will raise
435
 
        IncompatibleFormat if the workingtree format they are given has
436
 
        a format string, and vice versa.
 
435
        IncompatibleFormat if the workingtree format they are given has a
 
436
        format string, and vice versa.
437
437
 
438
438
        If workingtree_format is None, the transport is returned with no 
439
439
        checking. if it is not None, then the returned transport is
625
625
        except errors.NoWorkingTree:
626
626
            return False
627
627
 
628
 
    def cloning_metadir(self, basis=None):
629
 
        """Produce a metadir suitable for cloning with"""
 
628
    def _cloning_metadir(self, basis=None):
630
629
        def related_repository(bzrdir):
631
630
            try:
632
631
                branch = bzrdir.open_branch()
644
643
                source_repository = related_repository(self)
645
644
            result_format.repository_format = source_repository._format
646
645
        except errors.NoRepositoryPresent:
647
 
            pass
648
 
        return result_format
649
 
 
650
 
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
 
646
            source_repository = None
 
647
        try:
 
648
            tree = self.open_workingtree()
 
649
        except (errors.NoWorkingTree, errors.NotLocalUrl):
 
650
            result_format.workingtree_format = None
 
651
        else:
 
652
            result_format.workingtree_format = tree._format.__class__()
 
653
        return result_format, source_repository
 
654
 
 
655
    def cloning_metadir(self, basis=None):
 
656
        """Produce a metadir suitable for cloning or sprouting with.
 
657
 
 
658
        These operations may produce workingtrees (yes, even though they're
 
659
        "cloning" something that doesn't have a tree, so a viable workingtree
 
660
        format must be selected.
 
661
        """
 
662
        format, repository = self._cloning_metadir()
 
663
        if format._workingtree_format is None:
 
664
            if repository is None:
 
665
                return format
 
666
            tree_format = repository._format._matchingbzrdir.workingtree_format
 
667
            format.workingtree_format = tree_format.__class__()
 
668
        return format
 
669
 
 
670
    def checkout_metadir(self):
 
671
        return self.cloning_metadir()
 
672
 
 
673
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False,
 
674
               recurse='down'):
651
675
        """Create a copy of this bzrdir prepared for use as a new line of
652
676
        development.
653
677
 
719
743
                        pass
720
744
            finally:
721
745
                wt.unlock()
 
746
        else:
 
747
            wt = None
 
748
        if recurse == 'down':
 
749
            if wt is not None:
 
750
                entries = wt.iter_reference_entries()
 
751
                recurse_branch = wt.branch
 
752
            elif source_branch is not None:
 
753
                entries = source_branch.basis_tree().iter_reference_entries()
 
754
                recurse_branch = source_branch
 
755
            else:
 
756
                entries = []
 
757
            for path, entry in entries:
 
758
                target = urlutils.join(url, urlutils.escape(path))
 
759
                sublocation = source_branch.reference_parent(entry.file_id,
 
760
                                                             path)
 
761
                sublocation.bzrdir.sprout(target, entry.reference_revision,
 
762
                    force_new_repo=force_new_repo, recurse=recurse)
722
763
        return result
723
764
 
724
765
 
938
979
    def create_workingtree(self, revision_id=None):
939
980
        """See BzrDir.create_workingtree."""
940
981
        from bzrlib.workingtree import WorkingTreeFormat
941
 
        return WorkingTreeFormat.get_default_format().initialize(self, revision_id)
 
982
        return self._format.workingtree_format.initialize(self, revision_id)
942
983
 
943
984
    def destroy_workingtree(self):
944
985
        """See BzrDir.destroy_workingtree."""
1450
1491
    _lock_class = lockdir.LockDir
1451
1492
 
1452
1493
    def __init__(self):
 
1494
        self._workingtree_format = None
1453
1495
        self._branch_format = None
1454
1496
 
 
1497
    def __eq__(self, other):
 
1498
        if other.__class__ is not self.__class__:
 
1499
            return False
 
1500
        if other.repository_format != self.repository_format:
 
1501
            return False
 
1502
        if other.workingtree_format != self.workingtree_format:
 
1503
            return False
 
1504
        return True
 
1505
 
 
1506
    def __ne__(self, other):
 
1507
        return not self == other
 
1508
 
1455
1509
    def get_branch_format(self):
1456
1510
        if self._branch_format is None:
1457
1511
            from bzrlib.branch import BranchFormat
1495
1549
 
1496
1550
    repository_format = property(__return_repository_format, __set_repository_format)
1497
1551
 
 
1552
    def __get_workingtree_format(self):
 
1553
        if self._workingtree_format is None:
 
1554
            from bzrlib.workingtree import WorkingTreeFormat
 
1555
            self._workingtree_format = WorkingTreeFormat.get_default_format()
 
1556
        return self._workingtree_format
 
1557
 
 
1558
    def __set_workingtree_format(self, wt_format):
 
1559
        self._workingtree_format = wt_format
 
1560
 
 
1561
    workingtree_format = property(__get_workingtree_format,
 
1562
                                  __set_workingtree_format)
 
1563
 
1498
1564
 
1499
1565
BzrDirFormat.register_format(BzrDirFormat4())
1500
1566
BzrDirFormat.register_format(BzrDirFormat5())
2022
2088
    """
2023
2089
 
2024
2090
    def register_metadir(self, key, repo, help, native=True, deprecated=False,
2025
 
                         branch_format=None):
 
2091
                         branch_format=None, tree='WorkingTreeFormat3'):
2026
2092
        """Register a metadir subformat.
2027
2093
 
2028
2094
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2035
2101
        # formats, once BzrDirMetaFormat1 supports that.
2036
2102
        def helper():
2037
2103
            import bzrlib.branch
 
2104
            import bzrlib.repository
 
2105
            import bzrlib.workingtree
 
2106
            tree_format = getattr(bzrlib.workingtree, tree)
2038
2107
            mod_name, repo_factory_name = repo.rsplit('.', 1)
2039
2108
            try:
2040
2109
                mod = __import__(mod_name, globals(), locals(),
2048
2117
                raise AttributeError('no repository format %r in module %r' 
2049
2118
                    % (repo, mod))
2050
2119
            bd = BzrDirMetaFormat1()
 
2120
            bd.workingtree_format = tree_format()
2051
2121
            bd.repository_format = repo_format_class()
2052
2122
            if branch_format is not None:
2053
2123
                bd.set_branch_format(getattr(bzrlib.branch, branch_format)())
2151
2221
format_registry.register_metadir('metaweave',
2152
2222
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2153
2223
    'Transitional format in 0.8.  Slower than knit.',
2154
 
    deprecated=True,
2155
 
    )
 
2224
    deprecated=True)
2156
2225
format_registry.register_metadir('experimental-knit2',
2157
2226
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
2158
2227
    'Experimental successor to knit.  Use at your own risk.',
2159
 
    branch_format='BzrBranchFormat5')
 
2228
    branch_format='BzrBranchFormat5',
 
2229
    tree='WorkingTreeFormat3'
 
2230
    )
 
2231
format_registry.register_metadir('experimental-knit3',
 
2232
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
 
2233
    'Experimental successor to knit2.  Use at your own risk.', 
 
2234
    branch_format='BzrBranchFormat5',
 
2235
    tree='WorkingTreeFormatAB1')
2160
2236
format_registry.register_metadir('experimental-branch6',
2161
2237
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2162
2238
    'Experimental successor to knit.  Use at your own risk.',
2163
 
    branch_format='BzrBranchFormat6')
 
2239
    branch_format='BzrBranchFormat6',
 
2240
    tree='WorkingTreeFormat3')