/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 r4054

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    do_catching_redirections,
65
65
    get_transport,
66
66
    local,
 
67
    remote as remote_transport,
67
68
    )
68
69
from bzrlib.weave import Weave
69
70
""")
81
82
 
82
83
class BzrDir(object):
83
84
    """A .bzr control diretory.
84
 
    
 
85
 
85
86
    BzrDir instances let you create or open any of the things that can be
86
87
    found within .bzr - checkouts, branches and repositories.
87
 
    
 
88
 
88
89
    :ivar transport:
89
90
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
90
91
    :ivar root_transport:
129
130
        basedir=None):
130
131
        """Give an error or warning on old formats.
131
132
 
132
 
        :param format: may be any kind of format - workingtree, branch, 
 
133
        :param format: may be any kind of format - workingtree, branch,
133
134
        or repository.
134
135
 
135
 
        :param allow_unsupported: If true, allow opening 
136
 
        formats that are strongly deprecated, and which may 
 
136
        :param allow_unsupported: If true, allow opening
 
137
        formats that are strongly deprecated, and which may
137
138
        have limited functionality.
138
139
 
139
140
        :param recommend_upgrade: If true (default), warn
187
188
        """
188
189
        transport.ensure_base()
189
190
        require_stacking = (stacked_on is not None)
190
 
        metadir = self.cloning_metadir(require_stacking)
191
 
        result = metadir.initialize_on_transport(transport)
 
191
        format = self.cloning_metadir(require_stacking)
 
192
        result = format.initialize_on_transport(transport)
192
193
        repository_policy = None
193
194
        try:
194
195
            local_repo = self.find_repository()
228
229
        #   make sure its content is available in the target repository
229
230
        #   clone it.
230
231
        if local_branch is not None:
231
 
            result_branch = local_branch.clone(result, revision_id=revision_id)
232
 
            if repository_policy is not None:
233
 
                repository_policy.configure_branch(result_branch)
234
 
        if result_repo is None or result_repo.make_working_trees():
235
 
            try:
 
232
            result_branch = local_branch.clone(result, revision_id=revision_id,
 
233
                repository_policy=repository_policy)
 
234
        try:
 
235
            # Cheaper to check if the target is not local, than to try making
 
236
            # the tree and fail.
 
237
            result.root_transport.local_abspath('.')
 
238
            if result_repo is None or result_repo.make_working_trees():
236
239
                self.open_workingtree().clone(result)
237
 
            except (errors.NoWorkingTree, errors.NotLocalUrl):
238
 
                pass
 
240
        except (errors.NoWorkingTree, errors.NotLocalUrl):
 
241
            pass
239
242
        return result
240
243
 
241
244
    # TODO: This should be given a Transport, and should chdir up; otherwise
247
250
    @classmethod
248
251
    def create(cls, base, format=None, possible_transports=None):
249
252
        """Create a new BzrDir at the url 'base'.
250
 
        
 
253
 
251
254
        :param format: If supplied, the format of branch to create.  If not
252
255
            supplied, the default is used.
253
 
        :param possible_transports: If supplied, a list of transports that 
 
256
        :param possible_transports: If supplied, a list of transports that
254
257
            can be reused to share a remote connection.
255
258
        """
256
259
        if cls is not BzrDir:
356
359
        """Create a new BzrDir, Branch and Repository at the url 'base'.
357
360
 
358
361
        This will use the current default BzrDirFormat unless one is
359
 
        specified, and use whatever 
 
362
        specified, and use whatever
360
363
        repository format that that uses via bzrdir.create_branch and
361
364
        create_repository. If a shared repository is available that is used
362
365
        preferentially.
450
453
        not.
451
454
 
452
455
        This will use the current default BzrDirFormat unless one is
453
 
        specified, and use whatever 
 
456
        specified, and use whatever
454
457
        repository format that that uses via bzrdir.create_branch and
455
458
        create_repository. If a shared repository is available that is used
456
459
        preferentially. Whatever repository is used, its tree creation policy
458
461
 
459
462
        The created Branch object is returned.
460
463
        If a working tree cannot be made due to base not being a file:// url,
461
 
        no error is raised unless force_new_tree is True, in which case no 
 
464
        no error is raised unless force_new_tree is True, in which case no
462
465
        data is created on disk and NotLocalUrl is raised.
463
466
 
464
467
        :param base: The URL to create the branch at.
465
468
        :param force_new_repo: If True a new repository is always created.
466
 
        :param force_new_tree: If True or False force creation of a tree or 
 
469
        :param force_new_tree: If True or False force creation of a tree or
467
470
                               prevent such creation respectively.
468
471
        :param format: Override for the bzrdir format to create.
469
472
        :param possible_transports: An optional reusable transports list.
491
494
        'base' must be a local path or a file:// url.
492
495
 
493
496
        This will use the current default BzrDirFormat unless one is
494
 
        specified, and use whatever 
 
497
        specified, and use whatever
495
498
        repository format that that uses for bzrdirformat.create_workingtree,
496
499
        create_branch and create_repository.
497
500
 
509
512
    def create_workingtree(self, revision_id=None, from_branch=None,
510
513
        accelerator_tree=None, hardlink=False):
511
514
        """Create a working tree at this BzrDir.
512
 
        
 
515
 
513
516
        :param revision_id: create it as of this revision id.
514
517
        :param from_branch: override bzrdir branch (for lightweight checkouts)
515
518
        :param accelerator_tree: A tree which can be used for retrieving file
521
524
 
522
525
    def backup_bzrdir(self):
523
526
        """Backup this bzr control directory.
524
 
        
 
527
 
525
528
        :return: Tuple with old path name and new path name
526
529
        """
527
530
        pb = ui.ui_factory.nested_progress_bar()
530
533
            # already exists, but it should instead either remove it or make
531
534
            # a new backup directory.
532
535
            #
533
 
            # FIXME: bug 262450 -- the backup directory should have the same 
 
536
            # FIXME: bug 262450 -- the backup directory should have the same
534
537
            # permissions as the .bzr directory (probably a bug in copy_tree)
535
538
            old_path = self.root_transport.abspath('.bzr')
536
539
            new_path = self.root_transport.abspath('backup.bzr')
651
654
        IncompatibleFormat if the branch format they are given has
652
655
        a format string, and vice versa.
653
656
 
654
 
        If branch_format is None, the transport is returned with no 
 
657
        If branch_format is None, the transport is returned with no
655
658
        checking. If it is not None, then the returned transport is
656
659
        guaranteed to point to an existing directory ready for use.
657
660
        """
700
703
        if not self._mode_check_done:
701
704
            self._find_creation_modes()
702
705
        return self._dir_mode
703
 
        
 
706
 
704
707
    def get_repository_transport(self, repository_format):
705
708
        """Get the transport for use by repository format in this BzrDir.
706
709
 
708
711
        IncompatibleFormat if the repository format they are given has
709
712
        a format string, and vice versa.
710
713
 
711
 
        If repository_format is None, the transport is returned with no 
 
714
        If repository_format is None, the transport is returned with no
712
715
        checking. If it is not None, then the returned transport is
713
716
        guaranteed to point to an existing directory ready for use.
714
717
        """
715
718
        raise NotImplementedError(self.get_repository_transport)
716
 
        
 
719
 
717
720
    def get_workingtree_transport(self, tree_format):
718
721
        """Get the transport for use by workingtree format in this BzrDir.
719
722
 
721
724
        IncompatibleFormat if the workingtree format they are given has a
722
725
        format string, and vice versa.
723
726
 
724
 
        If workingtree_format is None, the transport is returned with no 
 
727
        If workingtree_format is None, the transport is returned with no
725
728
        checking. If it is not None, then the returned transport is
726
729
        guaranteed to point to an existing directory ready for use.
727
730
        """
734
737
 
735
738
    def __init__(self, _transport, _format):
736
739
        """Initialize a Bzr control dir object.
737
 
        
 
740
 
738
741
        Only really common logic should reside here, concrete classes should be
739
742
        made with varying behaviours.
740
743
 
748
751
 
749
752
    def is_control_filename(self, filename):
750
753
        """True if filename is the name of a path which is reserved for bzrdir's.
751
 
        
 
754
 
752
755
        :param filename: A filename within the root transport of this bzrdir.
753
756
 
754
757
        This is true IF and ONLY IF the filename is part of the namespace reserved
757
760
        this in the future - for instance to make bzr talk with svn working
758
761
        trees.
759
762
        """
760
 
        # this might be better on the BzrDirFormat class because it refers to 
761
 
        # all the possible bzrdir disk formats. 
762
 
        # This method is tested via the workingtree is_control_filename tests- 
 
763
        # this might be better on the BzrDirFormat class because it refers to
 
764
        # all the possible bzrdir disk formats.
 
765
        # This method is tested via the workingtree is_control_filename tests-
763
766
        # it was extracted from WorkingTree.is_control_filename. If the method's
764
767
        # contract is extended beyond the current trivial implementation, please
765
768
        # add new tests for it to the appropriate place.
767
770
 
768
771
    def needs_format_conversion(self, format=None):
769
772
        """Return true if this bzrdir needs convert_format run on it.
770
 
        
771
 
        For instance, if the repository format is out of date but the 
 
773
 
 
774
        For instance, if the repository format is out of date but the
772
775
        branch and working tree are not, this should return True.
773
776
 
774
777
        :param format: Optional parameter indicating a specific desired
780
783
    def open_unsupported(base):
781
784
        """Open a branch which is not supported."""
782
785
        return BzrDir.open(base, _unsupported=True)
783
 
        
 
786
 
784
787
    @staticmethod
785
788
    def open(base, _unsupported=False, possible_transports=None):
786
789
        """Open an existing bzrdir, rooted at 'base' (url).
787
 
        
 
790
 
788
791
        :param _unsupported: a private parameter to the BzrDir class.
789
792
        """
790
793
        t = get_transport(base, possible_transports=possible_transports)
828
831
 
829
832
        If unsupported is True, then no longer supported branch formats can
830
833
        still be opened.
831
 
        
 
834
 
832
835
        TODO: static convenience version of this?
833
836
        """
834
837
        raise NotImplementedError(self.open_branch)
836
839
    @staticmethod
837
840
    def open_containing(url, possible_transports=None):
838
841
        """Open an existing branch which contains url.
839
 
        
 
842
 
840
843
        :param url: url to search from.
841
844
        See open_containing_from_transport for more detail.
842
845
        """
843
846
        transport = get_transport(url, possible_transports)
844
847
        return BzrDir.open_containing_from_transport(transport)
845
 
    
 
848
 
846
849
    @staticmethod
847
850
    def open_containing_from_transport(a_transport):
848
851
        """Open an existing branch which contains a_transport.base.
851
854
 
852
855
        Basically we keep looking up until we find the control directory or
853
856
        run into the root.  If there isn't one, raises NotBranchError.
854
 
        If there is one and it is either an unrecognised format or an unsupported 
 
857
        If there is one and it is either an unrecognised format or an unsupported
855
858
        format, UnknownFormatError or UnsupportedFormatError are raised.
856
859
        If there is one, it is returned, along with the unused portion of url.
857
860
 
858
 
        :return: The BzrDir that contains the path, and a Unicode path 
 
861
        :return: The BzrDir that contains the path, and a Unicode path
859
862
                for the rest of the URL.
860
863
        """
861
864
        # this gets the normalised url back. I.e. '.' -> the full path.
969
972
 
970
973
    def has_branch(self):
971
974
        """Tell if this bzrdir contains a branch.
972
 
        
 
975
 
973
976
        Note: if you're going to open the branch, you should just go ahead
974
 
        and try, and not ask permission first.  (This method just opens the 
975
 
        branch and discards it, and that's somewhat expensive.) 
 
977
        and try, and not ask permission first.  (This method just opens the
 
978
        branch and discards it, and that's somewhat expensive.)
976
979
        """
977
980
        try:
978
981
            self.open_branch()
985
988
 
986
989
        This will still raise an exception if the bzrdir has a workingtree that
987
990
        is remote & inaccessible.
988
 
        
 
991
 
989
992
        Note: if you're going to open the working tree, you should just go ahead
990
 
        and try, and not ask permission first.  (This method just opens the 
991
 
        workingtree and discards it, and that's somewhat expensive.) 
 
993
        and try, and not ask permission first.  (This method just opens the
 
994
        workingtree and discards it, and that's somewhat expensive.)
992
995
        """
993
996
        try:
994
997
            self.open_workingtree(recommend_upgrade=False)
998
1001
 
999
1002
    def _cloning_metadir(self):
1000
1003
        """Produce a metadir suitable for cloning with.
1001
 
        
 
1004
 
1002
1005
        :returns: (destination_bzrdir_format, source_repository)
1003
1006
        """
1004
1007
        result_format = self._format.__class__()
1061
1064
    def sprout(self, url, revision_id=None, force_new_repo=False,
1062
1065
               recurse='down', possible_transports=None,
1063
1066
               accelerator_tree=None, hardlink=False, stacked=False,
1064
 
               source_branch=None):
 
1067
               source_branch=None, create_tree_if_local=True):
1065
1068
        """Create a copy of this bzrdir prepared for use as a new line of
1066
1069
        development.
1067
1070
 
1082
1085
            where possible.
1083
1086
        :param stacked: If true, create a stacked branch referring to the
1084
1087
            location of this control directory.
 
1088
        :param create_tree_if_local: If true, a working-tree will be created
 
1089
            when working locally.
1085
1090
        """
1086
1091
        target_transport = get_transport(url, possible_transports)
1087
1092
        target_transport.ensure_base()
1134
1139
            result_branch.set_parent(parent_location)
1135
1140
 
1136
1141
        # Create/update the result working tree
1137
 
        if isinstance(target_transport, local.LocalTransport) and (
1138
 
            result_repo is None or result_repo.make_working_trees()):
 
1142
        if (create_tree_if_local and
 
1143
            isinstance(target_transport, local.LocalTransport) and
 
1144
            (result_repo is None or result_repo.make_working_trees())):
1139
1145
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1140
1146
                hardlink=hardlink)
1141
1147
            wt.lock_write()
1254
1260
        # and that will have set it for us, its only
1255
1261
        # specific uses of create_workingtree in isolation
1256
1262
        # that can do wonky stuff here, and that only
1257
 
        # happens for creating checkouts, which cannot be 
 
1263
        # happens for creating checkouts, which cannot be
1258
1264
        # done on this format anyway. So - acceptable wart.
1259
1265
        try:
1260
1266
            result = self.open_workingtree(recommend_upgrade=False)
1283
1289
 
1284
1290
    def destroy_workingtree_metadata(self):
1285
1291
        """See BzrDir.destroy_workingtree_metadata."""
1286
 
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
 
1292
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
1287
1293
                                          self)
1288
1294
 
1289
1295
    def get_branch_transport(self, branch_format):
1335
1341
 
1336
1342
    def sprout(self, url, revision_id=None, force_new_repo=False,
1337
1343
               possible_transports=None, accelerator_tree=None,
1338
 
               hardlink=False, stacked=False):
 
1344
               hardlink=False, stacked=False, create_tree_if_local=True):
1339
1345
        """See BzrDir.sprout()."""
1340
1346
        if stacked:
1341
1347
            raise errors.UnstackableBranchFormat(
1342
1348
                self._format, self.root_transport.base)
 
1349
        if not create_tree_if_local:
 
1350
            raise errors.MustHaveWorkingTree(
 
1351
                self._format, self.root_transport.base)
1343
1352
        from bzrlib.workingtree import WorkingTreeFormat2
1344
1353
        self._make_tail(url)
1345
1354
        result = self._format._initialize_for_clone(url)
1351
1360
            self.open_branch().sprout(result, revision_id=revision_id)
1352
1361
        except errors.NotBranchError:
1353
1362
            pass
 
1363
 
1354
1364
        # we always want a working tree
1355
1365
        WorkingTreeFormat2().initialize(result,
1356
1366
                                        accelerator_tree=accelerator_tree,
1360
1370
 
1361
1371
class BzrDir4(BzrDirPreSplitOut):
1362
1372
    """A .bzr version 4 control object.
1363
 
    
 
1373
 
1364
1374
    This is a deprecated format and may be removed after sept 2006.
1365
1375
    """
1366
1376
 
1424
1434
 
1425
1435
class BzrDirMeta1(BzrDir):
1426
1436
    """A .bzr meta version 1 control object.
1427
 
    
1428
 
    This is the first control object where the 
 
1437
 
 
1438
    This is the first control object where the
1429
1439
    individual aspects are really split out: there are separate repository,
1430
1440
    workingtree and branch subdirectories and any subset of the three can be
1431
1441
    present within a BzrDir.
1601
1611
     * a format string,
1602
1612
     * an open routine.
1603
1613
 
1604
 
    Formats are placed in a dict by their format string for reference 
 
1614
    Formats are placed in a dict by their format string for reference
1605
1615
    during bzrdir opening. These should be subclasses of BzrDirFormat
1606
1616
    for consistency.
1607
1617
 
1608
1618
    Once a format is deprecated, just deprecate the initialize and open
1609
 
    methods on the format class. Do not deprecate the object, as the 
 
1619
    methods on the format class. Do not deprecate the object, as the
1610
1620
    object will be created every system load.
1611
1621
    """
1612
1622
 
1618
1628
 
1619
1629
    _control_formats = []
1620
1630
    """The registered control formats - .bzr, ....
1621
 
    
 
1631
 
1622
1632
    This is a list of BzrDirFormat objects.
1623
1633
    """
1624
1634
 
1683
1693
        current default format. In the case of plugins we can/should provide
1684
1694
        some means for them to extend the range of returnable converters.
1685
1695
 
1686
 
        :param format: Optional format to override the default format of the 
 
1696
        :param format: Optional format to override the default format of the
1687
1697
                       library.
1688
1698
        """
1689
1699
        raise NotImplementedError(self.get_converter)
1690
1700
 
1691
1701
    def initialize(self, url, possible_transports=None):
1692
1702
        """Create a bzr control dir at this url and return an opened copy.
1693
 
        
 
1703
 
1694
1704
        Subclasses should typically override initialize_on_transport
1695
1705
        instead of this method.
1696
1706
        """
1699
1709
 
1700
1710
    def initialize_on_transport(self, transport):
1701
1711
        """Initialize a new bzrdir in the base directory of a Transport."""
1702
 
        # Since we don't have a .bzr directory, inherit the
 
1712
        try:
 
1713
            # can we hand off the request to the smart server rather than using
 
1714
            # vfs calls?
 
1715
            client_medium = transport.get_smart_medium()
 
1716
        except errors.NoSmartMedium:
 
1717
            return self._initialize_on_transport_vfs(transport)
 
1718
        else:
 
1719
            # Current RPC's only know how to create bzr metadir1 instances, so
 
1720
            # we still delegate to vfs methods if the requested format is not a
 
1721
            # metadir1
 
1722
            if type(self) != BzrDirMetaFormat1:
 
1723
                return self._initialize_on_transport_vfs(transport)
 
1724
            remote_format = RemoteBzrDirFormat()
 
1725
            self._supply_sub_formats_to(remote_format)
 
1726
            return remote_format.initialize_on_transport(transport)
 
1727
 
 
1728
    def _initialize_on_transport_vfs(self, transport):
 
1729
        """Initialize a new bzrdir using VFS calls.
 
1730
 
 
1731
        :param transport: The transport to create the .bzr directory in.
 
1732
        :return: A
 
1733
        """
 
1734
        # Since we are creating a .bzr directory, inherit the
1703
1735
        # mode from the root directory
1704
1736
        temp_control = lockable_files.LockableFiles(transport,
1705
1737
                            '', lockable_files.TransportLock)
1735
1767
        """Is this format supported?
1736
1768
 
1737
1769
        Supported formats must be initializable and openable.
1738
 
        Unsupported formats may not support initialization or committing or 
 
1770
        Unsupported formats may not support initialization or committing or
1739
1771
        some other features depending on the reason for not being supported.
1740
1772
        """
1741
1773
        return True
1742
1774
 
1743
1775
    def same_model(self, target_format):
1744
 
        return (self.repository_format.rich_root_data == 
 
1776
        return (self.repository_format.rich_root_data ==
1745
1777
            target_format.rich_root_data)
1746
1778
 
1747
1779
    @classmethod
1748
1780
    def known_formats(klass):
1749
1781
        """Return all the known formats.
1750
 
        
 
1782
 
1751
1783
        Concrete formats should override _known_formats.
1752
1784
        """
1753
 
        # There is double indirection here to make sure that control 
1754
 
        # formats used by more than one dir format will only be probed 
 
1785
        # There is double indirection here to make sure that control
 
1786
        # formats used by more than one dir format will only be probed
1755
1787
        # once. This can otherwise be quite expensive for remote connections.
1756
1788
        result = set()
1757
1789
        for format in klass._control_formats:
1758
1790
            result.update(format._known_formats())
1759
1791
        return result
1760
 
    
 
1792
 
1761
1793
    @classmethod
1762
1794
    def _known_formats(klass):
1763
1795
        """Return the known format instances for this control format."""
1765
1797
 
1766
1798
    def open(self, transport, _found=False):
1767
1799
        """Return an instance of this format for the dir transport points at.
1768
 
        
 
1800
 
1769
1801
        _found is a private parameter, do not use it.
1770
1802
        """
1771
1803
        if not _found:
1772
1804
            found_format = BzrDirFormat.find_format(transport)
1773
1805
            if not isinstance(found_format, self.__class__):
1774
1806
                raise AssertionError("%s was asked to open %s, but it seems to need "
1775
 
                        "format %s" 
 
1807
                        "format %s"
1776
1808
                        % (self, transport, found_format))
 
1809
            # Allow subclasses - use the found format.
 
1810
            self._supply_sub_formats_to(found_format)
 
1811
            return found_format._open(transport)
1777
1812
        return self._open(transport)
1778
1813
 
1779
1814
    def _open(self, transport):
1793
1828
        """Register a format that does not use '.bzr' for its control dir.
1794
1829
 
1795
1830
        TODO: This should be pulled up into a 'ControlDirFormat' base class
1796
 
        which BzrDirFormat can inherit from, and renamed to register_format 
 
1831
        which BzrDirFormat can inherit from, and renamed to register_format
1797
1832
        there. It has been done without that for now for simplicity of
1798
1833
        implementation.
1799
1834
        """
1817
1852
 
1818
1853
    def __str__(self):
1819
1854
        # Trim the newline
1820
 
        return self.get_format_string().rstrip()
 
1855
        return self.get_format_description().rstrip()
 
1856
 
 
1857
    def _supply_sub_formats_to(self, other_format):
 
1858
        """Give other_format the same values for sub formats as this has.
 
1859
 
 
1860
        This method is expected to be used when parameterising a
 
1861
        RemoteBzrDirFormat instance with the parameters from a
 
1862
        BzrDirMetaFormat1 instance.
 
1863
 
 
1864
        :param other_format: other_format is a format which should be
 
1865
            compatible with whatever sub formats are supported by self.
 
1866
        :return: None.
 
1867
        """
1821
1868
 
1822
1869
    @classmethod
1823
1870
    def unregister_format(klass, format):
1855
1902
        """See BzrDirFormat.get_converter()."""
1856
1903
        # there is one and only one upgrade path here.
1857
1904
        return ConvertBzrDir4To5()
1858
 
        
 
1905
 
1859
1906
    def initialize_on_transport(self, transport):
1860
1907
        """Format 4 branches cannot be created."""
1861
1908
        raise errors.UninitializableFormat(self)
1864
1911
        """Format 4 is not supported.
1865
1912
 
1866
1913
        It is not supported because the model changed from 4 to 5 and the
1867
 
        conversion logic is expensive - so doing it on the fly was not 
 
1914
        conversion logic is expensive - so doing it on the fly was not
1868
1915
        feasible.
1869
1916
        """
1870
1917
        return False
1885
1932
 
1886
1933
    This format is a combined format for working tree, branch and repository.
1887
1934
    It has:
1888
 
     - Format 2 working trees [always] 
1889
 
     - Format 4 branches [always] 
 
1935
     - Format 2 working trees [always]
 
1936
     - Format 4 branches [always]
1890
1937
     - Format 5 repositories [always]
1891
1938
       Unhashed stores in the repository.
1892
1939
    """
1912
1959
 
1913
1960
    def _initialize_for_clone(self, url):
1914
1961
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1915
 
        
 
1962
 
1916
1963
    def initialize_on_transport(self, transport, _cloning=False):
1917
1964
        """Format 5 dirs always have working tree, branch and repository.
1918
 
        
 
1965
 
1919
1966
        Except when they are being cloned.
1920
1967
        """
1921
1968
        from bzrlib.branch import BzrBranchFormat4
1943
1990
 
1944
1991
    This format is a combined format for working tree, branch and repository.
1945
1992
    It has:
1946
 
     - Format 2 working trees [always] 
1947
 
     - Format 4 branches [always] 
 
1993
     - Format 2 working trees [always]
 
1994
     - Format 4 branches [always]
1948
1995
     - Format 6 repositories [always]
1949
1996
    """
1950
1997
 
1966
2013
        """See BzrDirFormat.get_converter()."""
1967
2014
        # there is one and only one upgrade path here.
1968
2015
        return ConvertBzrDir6ToMeta()
1969
 
        
 
2016
 
1970
2017
    def _initialize_for_clone(self, url):
1971
2018
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1972
2019
 
1973
2020
    def initialize_on_transport(self, transport, _cloning=False):
1974
2021
        """Format 6 dirs always have working tree, branch and repository.
1975
 
        
 
2022
 
1976
2023
        Except when they are being cloned.
1977
2024
        """
1978
2025
        from bzrlib.branch import BzrBranchFormat4
2039
2086
            # target doesn't support stacking.  So force a branch that *can*
2040
2087
            # support stacking.
2041
2088
            from bzrlib.branch import BzrBranchFormat7
2042
 
            self._branch_format = BzrBranchFormat7()
2043
 
            mutter("using %r for stacking" % (self._branch_format,))
 
2089
            branch_format = BzrBranchFormat7()
 
2090
            self.set_branch_format(branch_format)
 
2091
            mutter("using %r for stacking" % (branch_format,))
2044
2092
            from bzrlib.repofmt import pack_repo
2045
2093
            if self.repository_format.rich_root_data:
2046
2094
                bzrdir_format_name = '1.6.1-rich-root'
2081
2129
        from bzrlib.repository import RepositoryFormat
2082
2130
        return RepositoryFormat.get_default_format()
2083
2131
 
2084
 
    def __set_repository_format(self, value):
 
2132
    def _set_repository_format(self, value):
2085
2133
        """Allow changing the repository format for metadir formats."""
2086
2134
        self._repository_format = value
2087
2135
 
2088
 
    repository_format = property(__return_repository_format, __set_repository_format)
 
2136
    repository_format = property(__return_repository_format,
 
2137
        _set_repository_format)
 
2138
 
 
2139
    def _supply_sub_formats_to(self, other_format):
 
2140
        """Give other_format the same values for sub formats as this has.
 
2141
 
 
2142
        This method is expected to be used when parameterising a
 
2143
        RemoteBzrDirFormat instance with the parameters from a
 
2144
        BzrDirMetaFormat1 instance.
 
2145
 
 
2146
        :param other_format: other_format is a format which should be
 
2147
            compatible with whatever sub formats are supported by self.
 
2148
        :return: None.
 
2149
        """
 
2150
        if getattr(self, '_repository_format', None) is not None:
 
2151
            other_format.repository_format = self.repository_format
 
2152
        if self._branch_format is not None:
 
2153
            other_format._branch_format = self._branch_format
 
2154
        if self._workingtree_format is not None:
 
2155
            other_format.workingtree_format = self.workingtree_format
2089
2156
 
2090
2157
    def __get_workingtree_format(self):
2091
2158
        if self._workingtree_format is None:
2137
2204
        self.absent_revisions = set()
2138
2205
        self.text_count = 0
2139
2206
        self.revisions = {}
2140
 
        
 
2207
 
2141
2208
    def convert(self, to_convert, pb):
2142
2209
        """See Converter.convert()."""
2143
2210
        self.bzrdir = to_convert
2249
2316
                revision_store.add_lines(key, None, osutils.split_lines(text))
2250
2317
        finally:
2251
2318
            self.pb.clear()
2252
 
            
 
2319
 
2253
2320
    def _load_one_rev(self, rev_id):
2254
2321
        """Load a revision object into memory.
2255
2322
 
2329
2396
        text_changed = False
2330
2397
        parent_candiate_entries = ie.parent_candidates(parent_invs)
2331
2398
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2332
 
        # XXX: Note that this is unordered - and this is tolerable because 
 
2399
        # XXX: Note that this is unordered - and this is tolerable because
2333
2400
        # the previous code was also unordered.
2334
2401
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2335
2402
            in heads)
2352
2419
        # a call to:. This needs the path figured out. rather than a work_tree
2353
2420
        # a v4 revision_tree can be given, or something that looks enough like
2354
2421
        # one to give the file content to the entry if it needs it.
2355
 
        # and we need something that looks like a weave store for snapshot to 
 
2422
        # and we need something that looks like a weave store for snapshot to
2356
2423
        # save against.
2357
2424
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
2358
2425
        if len(previous_revisions) == 1:
2474
2541
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
2475
2542
        self.make_lock('repository')
2476
2543
        # we hard code the formats here because we are converting into
2477
 
        # the meta format. The meta format upgrader can take this to a 
 
2544
        # the meta format. The meta format upgrader can take this to a
2478
2545
        # future format within each component.
2479
2546
        self.put_format('repository', RepositoryFormat7())
2480
2547
        for entry in repository_names:
2634
2701
 
2635
2702
    def get_format_description(self):
2636
2703
        return 'bzr remote bzrdir'
2637
 
    
 
2704
 
 
2705
    def get_format_string(self):
 
2706
        raise NotImplementedError(self.get_format_string)
 
2707
 
2638
2708
    @classmethod
2639
2709
    def probe_transport(klass, transport):
2640
2710
        """Return a RemoteBzrDirFormat object if it looks possible."""
2672
2742
        response = client.call('BzrDirFormat.initialize', path)
2673
2743
        if response[0] != 'ok':
2674
2744
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2675
 
        return remote.RemoteBzrDir(transport)
 
2745
        format = RemoteBzrDirFormat()
 
2746
        self._supply_sub_formats_to(format)
 
2747
        return remote.RemoteBzrDir(transport, format)
2676
2748
 
2677
2749
    def _open(self, transport):
2678
 
        return remote.RemoteBzrDir(transport)
 
2750
        return remote.RemoteBzrDir(transport, self)
2679
2751
 
2680
2752
    def __eq__(self, other):
2681
2753
        if not isinstance(other, RemoteBzrDirFormat):
2682
2754
            return False
2683
2755
        return self.get_format_description() == other.get_format_description()
2684
2756
 
2685
 
    @property
2686
 
    def repository_format(self):
2687
 
        # Using a property to avoid early loading of remote
2688
 
        return remote.RemoteRepositoryFormat()
 
2757
    def __return_repository_format(self):
 
2758
        # Always return a RemoteRepositoryFormat object, but if a specific bzr
 
2759
        # repository format has been asked for, tell the RemoteRepositoryFormat
 
2760
        # that it should use that for init() etc.
 
2761
        result =  remote.RemoteRepositoryFormat()
 
2762
        custom_format = getattr(self, '_repository_format', None)
 
2763
        if custom_format:
 
2764
            # We will use the custom format to create repositories over the
 
2765
            # wire; expose its details like rich_root_data for code to query
 
2766
            if isinstance(custom_format, remote.RemoteRepositoryFormat):
 
2767
                result._custom_format = custom_format._custom_format
 
2768
            else:
 
2769
                result._custom_format = custom_format
 
2770
            result.rich_root_data = custom_format.rich_root_data
 
2771
        return result
 
2772
 
 
2773
    def get_branch_format(self):
 
2774
        result = BzrDirMetaFormat1.get_branch_format(self)
 
2775
        if not isinstance(result, remote.RemoteBranchFormat):
 
2776
            new_result = remote.RemoteBranchFormat()
 
2777
            new_result._custom_format = result
 
2778
            # cache the result
 
2779
            self.set_branch_format(new_result)
 
2780
            result = new_result
 
2781
        return result
 
2782
 
 
2783
    repository_format = property(__return_repository_format,
 
2784
        BzrDirMetaFormat1._set_repository_format) #.im_func)
2689
2785
 
2690
2786
 
2691
2787
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2702
2798
 
2703
2799
class BzrDirFormatRegistry(registry.Registry):
2704
2800
    """Registry of user-selectable BzrDir subformats.
2705
 
    
 
2801
 
2706
2802
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2707
2803
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
2708
2804
    """
2767
2863
    def register(self, key, factory, help, native=True, deprecated=False,
2768
2864
                 hidden=False, experimental=False, alias=False):
2769
2865
        """Register a BzrDirFormat factory.
2770
 
        
 
2866
 
2771
2867
        The factory must be a callable that takes one parameter: the key.
2772
2868
        It must produce an instance of the BzrDirFormat when called.
2773
2869
 
2790
2886
 
2791
2887
    def set_default(self, key):
2792
2888
        """Set the 'default' key to be a clone of the supplied key.
2793
 
        
 
2889
 
2794
2890
        This method must be called once and only once.
2795
2891
        """
2796
2892
        registry.Registry.register(self, 'default', self.get(key),
2799
2895
 
2800
2896
    def set_default_repository(self, key):
2801
2897
        """Set the FormatRegistry default and Repository default.
2802
 
        
 
2898
 
2803
2899
        This is a transitional method while Repository.set_default_format
2804
2900
        is deprecated.
2805
2901
        """
2828
2924
        def wrapped(key, help, info):
2829
2925
            if info.native:
2830
2926
                help = '(native) ' + help
2831
 
            return ':%s:\n%s\n\n' % (key, 
2832
 
                    textwrap.fill(help, initial_indent='    ', 
 
2927
            return ':%s:\n%s\n\n' % (key,
 
2928
                    textwrap.fill(help, initial_indent='    ',
2833
2929
                    subsequent_indent='    '))
2834
2930
        if default_realkey is not None:
2835
2931
            output += wrapped(default_realkey, '(default) %s' % default_help,
3014
3110
# appear in chronological order and format descriptions can build
3015
3111
# on previous ones.
3016
3112
format_registry = BzrDirFormatRegistry()
 
3113
# The pre-0.8 formats have their repository format network name registered in
 
3114
# repository.py. MetaDir formats have their repository format network name
 
3115
# inferred from their disk format string.
3017
3116
format_registry.register('weave', BzrDirFormat6,
3018
3117
    'Pre-0.8 format.  Slower than knit and does not'
3019
3118
    ' support checkouts or shared repositories.',
3125
3224
    branch_format='bzrlib.branch.BzrBranchFormat7',
3126
3225
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3127
3226
    )
3128
 
format_registry.register_metadir('1.12-preview',
 
3227
format_registry.register_metadir('development-wt5',
3129
3228
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3130
3229
    help='A working-tree format that supports views and content filtering.',
3131
3230
    branch_format='bzrlib.branch.BzrBranchFormat7',
3132
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
3231
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3133
3232
    experimental=True,
3134
3233
    )
3135
 
format_registry.register_metadir('1.12-preview-rich-root',
 
3234
format_registry.register_metadir('development-wt5-rich-root',
3136
3235
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3137
 
    help='A variant of 1.12-preview that supports rich-root data '
 
3236
    help='A variant of development-wt5 that supports rich-root data '
3138
3237
         '(needed for bzr-svn).',
3139
3238
    branch_format='bzrlib.branch.BzrBranchFormat7',
3140
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
3239
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3141
3240
    experimental=True,
3142
3241
    )
3143
3242
# The following two formats should always just be aliases.