/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

remove all trailing whitespace from bzr source

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
 
82
82
class BzrDir(object):
83
83
    """A .bzr control diretory.
84
 
    
 
84
 
85
85
    BzrDir instances let you create or open any of the things that can be
86
86
    found within .bzr - checkouts, branches and repositories.
87
 
    
 
87
 
88
88
    :ivar transport:
89
89
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
90
90
    :ivar root_transport:
129
129
        basedir=None):
130
130
        """Give an error or warning on old formats.
131
131
 
132
 
        :param format: may be any kind of format - workingtree, branch, 
 
132
        :param format: may be any kind of format - workingtree, branch,
133
133
        or repository.
134
134
 
135
 
        :param allow_unsupported: If true, allow opening 
136
 
        formats that are strongly deprecated, and which may 
 
135
        :param allow_unsupported: If true, allow opening
 
136
        formats that are strongly deprecated, and which may
137
137
        have limited functionality.
138
138
 
139
139
        :param recommend_upgrade: If true (default), warn
247
247
    @classmethod
248
248
    def create(cls, base, format=None, possible_transports=None):
249
249
        """Create a new BzrDir at the url 'base'.
250
 
        
 
250
 
251
251
        :param format: If supplied, the format of branch to create.  If not
252
252
            supplied, the default is used.
253
 
        :param possible_transports: If supplied, a list of transports that 
 
253
        :param possible_transports: If supplied, a list of transports that
254
254
            can be reused to share a remote connection.
255
255
        """
256
256
        if cls is not BzrDir:
356
356
        """Create a new BzrDir, Branch and Repository at the url 'base'.
357
357
 
358
358
        This will use the current default BzrDirFormat unless one is
359
 
        specified, and use whatever 
 
359
        specified, and use whatever
360
360
        repository format that that uses via bzrdir.create_branch and
361
361
        create_repository. If a shared repository is available that is used
362
362
        preferentially.
450
450
        not.
451
451
 
452
452
        This will use the current default BzrDirFormat unless one is
453
 
        specified, and use whatever 
 
453
        specified, and use whatever
454
454
        repository format that that uses via bzrdir.create_branch and
455
455
        create_repository. If a shared repository is available that is used
456
456
        preferentially. Whatever repository is used, its tree creation policy
458
458
 
459
459
        The created Branch object is returned.
460
460
        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 
 
461
        no error is raised unless force_new_tree is True, in which case no
462
462
        data is created on disk and NotLocalUrl is raised.
463
463
 
464
464
        :param base: The URL to create the branch at.
465
465
        :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 
 
466
        :param force_new_tree: If True or False force creation of a tree or
467
467
                               prevent such creation respectively.
468
468
        :param format: Override for the bzrdir format to create.
469
469
        :param possible_transports: An optional reusable transports list.
491
491
        'base' must be a local path or a file:// url.
492
492
 
493
493
        This will use the current default BzrDirFormat unless one is
494
 
        specified, and use whatever 
 
494
        specified, and use whatever
495
495
        repository format that that uses for bzrdirformat.create_workingtree,
496
496
        create_branch and create_repository.
497
497
 
509
509
    def create_workingtree(self, revision_id=None, from_branch=None,
510
510
        accelerator_tree=None, hardlink=False):
511
511
        """Create a working tree at this BzrDir.
512
 
        
 
512
 
513
513
        :param revision_id: create it as of this revision id.
514
514
        :param from_branch: override bzrdir branch (for lightweight checkouts)
515
515
        :param accelerator_tree: A tree which can be used for retrieving file
521
521
 
522
522
    def backup_bzrdir(self):
523
523
        """Backup this bzr control directory.
524
 
        
 
524
 
525
525
        :return: Tuple with old path name and new path name
526
526
        """
527
527
        self.root_transport.copy_tree('.bzr', 'backup.bzr')
638
638
        IncompatibleFormat if the branch format they are given has
639
639
        a format string, and vice versa.
640
640
 
641
 
        If branch_format is None, the transport is returned with no 
 
641
        If branch_format is None, the transport is returned with no
642
642
        checking. If it is not None, then the returned transport is
643
643
        guaranteed to point to an existing directory ready for use.
644
644
        """
687
687
        if not self._mode_check_done:
688
688
            self._find_creation_modes()
689
689
        return self._dir_mode
690
 
        
 
690
 
691
691
    def get_repository_transport(self, repository_format):
692
692
        """Get the transport for use by repository format in this BzrDir.
693
693
 
695
695
        IncompatibleFormat if the repository format they are given has
696
696
        a format string, and vice versa.
697
697
 
698
 
        If repository_format is None, the transport is returned with no 
 
698
        If repository_format is None, the transport is returned with no
699
699
        checking. If it is not None, then the returned transport is
700
700
        guaranteed to point to an existing directory ready for use.
701
701
        """
702
702
        raise NotImplementedError(self.get_repository_transport)
703
 
        
 
703
 
704
704
    def get_workingtree_transport(self, tree_format):
705
705
        """Get the transport for use by workingtree format in this BzrDir.
706
706
 
708
708
        IncompatibleFormat if the workingtree format they are given has a
709
709
        format string, and vice versa.
710
710
 
711
 
        If workingtree_format is None, the transport is returned with no 
 
711
        If workingtree_format is None, the transport is returned with no
712
712
        checking. If it is not None, then the returned transport is
713
713
        guaranteed to point to an existing directory ready for use.
714
714
        """
721
721
 
722
722
    def __init__(self, _transport, _format):
723
723
        """Initialize a Bzr control dir object.
724
 
        
 
724
 
725
725
        Only really common logic should reside here, concrete classes should be
726
726
        made with varying behaviours.
727
727
 
735
735
 
736
736
    def is_control_filename(self, filename):
737
737
        """True if filename is the name of a path which is reserved for bzrdir's.
738
 
        
 
738
 
739
739
        :param filename: A filename within the root transport of this bzrdir.
740
740
 
741
741
        This is true IF and ONLY IF the filename is part of the namespace reserved
744
744
        this in the future - for instance to make bzr talk with svn working
745
745
        trees.
746
746
        """
747
 
        # this might be better on the BzrDirFormat class because it refers to 
748
 
        # all the possible bzrdir disk formats. 
749
 
        # This method is tested via the workingtree is_control_filename tests- 
 
747
        # this might be better on the BzrDirFormat class because it refers to
 
748
        # all the possible bzrdir disk formats.
 
749
        # This method is tested via the workingtree is_control_filename tests-
750
750
        # it was extracted from WorkingTree.is_control_filename. If the method's
751
751
        # contract is extended beyond the current trivial implementation, please
752
752
        # add new tests for it to the appropriate place.
754
754
 
755
755
    def needs_format_conversion(self, format=None):
756
756
        """Return true if this bzrdir needs convert_format run on it.
757
 
        
758
 
        For instance, if the repository format is out of date but the 
 
757
 
 
758
        For instance, if the repository format is out of date but the
759
759
        branch and working tree are not, this should return True.
760
760
 
761
761
        :param format: Optional parameter indicating a specific desired
767
767
    def open_unsupported(base):
768
768
        """Open a branch which is not supported."""
769
769
        return BzrDir.open(base, _unsupported=True)
770
 
        
 
770
 
771
771
    @staticmethod
772
772
    def open(base, _unsupported=False, possible_transports=None):
773
773
        """Open an existing bzrdir, rooted at 'base' (url).
774
 
        
 
774
 
775
775
        :param _unsupported: a private parameter to the BzrDir class.
776
776
        """
777
777
        t = get_transport(base, possible_transports=possible_transports)
815
815
 
816
816
        If unsupported is True, then no longer supported branch formats can
817
817
        still be opened.
818
 
        
 
818
 
819
819
        TODO: static convenience version of this?
820
820
        """
821
821
        raise NotImplementedError(self.open_branch)
823
823
    @staticmethod
824
824
    def open_containing(url, possible_transports=None):
825
825
        """Open an existing branch which contains url.
826
 
        
 
826
 
827
827
        :param url: url to search from.
828
828
        See open_containing_from_transport for more detail.
829
829
        """
830
830
        transport = get_transport(url, possible_transports)
831
831
        return BzrDir.open_containing_from_transport(transport)
832
 
    
 
832
 
833
833
    @staticmethod
834
834
    def open_containing_from_transport(a_transport):
835
835
        """Open an existing branch which contains a_transport.base.
838
838
 
839
839
        Basically we keep looking up until we find the control directory or
840
840
        run into the root.  If there isn't one, raises NotBranchError.
841
 
        If there is one and it is either an unrecognised format or an unsupported 
 
841
        If there is one and it is either an unrecognised format or an unsupported
842
842
        format, UnknownFormatError or UnsupportedFormatError are raised.
843
843
        If there is one, it is returned, along with the unused portion of url.
844
844
 
845
 
        :return: The BzrDir that contains the path, and a Unicode path 
 
845
        :return: The BzrDir that contains the path, and a Unicode path
846
846
                for the rest of the URL.
847
847
        """
848
848
        # this gets the normalised url back. I.e. '.' -> the full path.
956
956
 
957
957
    def has_branch(self):
958
958
        """Tell if this bzrdir contains a branch.
959
 
        
 
959
 
960
960
        Note: if you're going to open the branch, you should just go ahead
961
 
        and try, and not ask permission first.  (This method just opens the 
962
 
        branch and discards it, and that's somewhat expensive.) 
 
961
        and try, and not ask permission first.  (This method just opens the
 
962
        branch and discards it, and that's somewhat expensive.)
963
963
        """
964
964
        try:
965
965
            self.open_branch()
972
972
 
973
973
        This will still raise an exception if the bzrdir has a workingtree that
974
974
        is remote & inaccessible.
975
 
        
 
975
 
976
976
        Note: if you're going to open the working tree, you should just go ahead
977
 
        and try, and not ask permission first.  (This method just opens the 
978
 
        workingtree and discards it, and that's somewhat expensive.) 
 
977
        and try, and not ask permission first.  (This method just opens the
 
978
        workingtree and discards it, and that's somewhat expensive.)
979
979
        """
980
980
        try:
981
981
            self.open_workingtree(recommend_upgrade=False)
985
985
 
986
986
    def _cloning_metadir(self):
987
987
        """Produce a metadir suitable for cloning with.
988
 
        
 
988
 
989
989
        :returns: (destination_bzrdir_format, source_repository)
990
990
        """
991
991
        result_format = self._format.__class__()
1241
1241
        # and that will have set it for us, its only
1242
1242
        # specific uses of create_workingtree in isolation
1243
1243
        # that can do wonky stuff here, and that only
1244
 
        # happens for creating checkouts, which cannot be 
 
1244
        # happens for creating checkouts, which cannot be
1245
1245
        # done on this format anyway. So - acceptable wart.
1246
1246
        try:
1247
1247
            result = self.open_workingtree(recommend_upgrade=False)
1270
1270
 
1271
1271
    def destroy_workingtree_metadata(self):
1272
1272
        """See BzrDir.destroy_workingtree_metadata."""
1273
 
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
 
1273
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
1274
1274
                                          self)
1275
1275
 
1276
1276
    def get_branch_transport(self, branch_format):
1345
1345
 
1346
1346
class BzrDir4(BzrDirPreSplitOut):
1347
1347
    """A .bzr version 4 control object.
1348
 
    
 
1348
 
1349
1349
    This is a deprecated format and may be removed after sept 2006.
1350
1350
    """
1351
1351
 
1406
1406
 
1407
1407
class BzrDirMeta1(BzrDir):
1408
1408
    """A .bzr meta version 1 control object.
1409
 
    
1410
 
    This is the first control object where the 
 
1409
 
 
1410
    This is the first control object where the
1411
1411
    individual aspects are really split out: there are separate repository,
1412
1412
    workingtree and branch subdirectories and any subset of the three can be
1413
1413
    present within a BzrDir.
1580
1580
     * a format string,
1581
1581
     * an open routine.
1582
1582
 
1583
 
    Formats are placed in a dict by their format string for reference 
 
1583
    Formats are placed in a dict by their format string for reference
1584
1584
    during bzrdir opening. These should be subclasses of BzrDirFormat
1585
1585
    for consistency.
1586
1586
 
1587
1587
    Once a format is deprecated, just deprecate the initialize and open
1588
 
    methods on the format class. Do not deprecate the object, as the 
 
1588
    methods on the format class. Do not deprecate the object, as the
1589
1589
    object will be created every system load.
1590
1590
    """
1591
1591
 
1597
1597
 
1598
1598
    _control_formats = []
1599
1599
    """The registered control formats - .bzr, ....
1600
 
    
 
1600
 
1601
1601
    This is a list of BzrDirFormat objects.
1602
1602
    """
1603
1603
 
1662
1662
        current default format. In the case of plugins we can/should provide
1663
1663
        some means for them to extend the range of returnable converters.
1664
1664
 
1665
 
        :param format: Optional format to override the default format of the 
 
1665
        :param format: Optional format to override the default format of the
1666
1666
                       library.
1667
1667
        """
1668
1668
        raise NotImplementedError(self.get_converter)
1669
1669
 
1670
1670
    def initialize(self, url, possible_transports=None):
1671
1671
        """Create a bzr control dir at this url and return an opened copy.
1672
 
        
 
1672
 
1673
1673
        Subclasses should typically override initialize_on_transport
1674
1674
        instead of this method.
1675
1675
        """
1714
1714
        """Is this format supported?
1715
1715
 
1716
1716
        Supported formats must be initializable and openable.
1717
 
        Unsupported formats may not support initialization or committing or 
 
1717
        Unsupported formats may not support initialization or committing or
1718
1718
        some other features depending on the reason for not being supported.
1719
1719
        """
1720
1720
        return True
1721
1721
 
1722
1722
    def same_model(self, target_format):
1723
 
        return (self.repository_format.rich_root_data == 
 
1723
        return (self.repository_format.rich_root_data ==
1724
1724
            target_format.rich_root_data)
1725
1725
 
1726
1726
    @classmethod
1727
1727
    def known_formats(klass):
1728
1728
        """Return all the known formats.
1729
 
        
 
1729
 
1730
1730
        Concrete formats should override _known_formats.
1731
1731
        """
1732
 
        # There is double indirection here to make sure that control 
1733
 
        # formats used by more than one dir format will only be probed 
 
1732
        # There is double indirection here to make sure that control
 
1733
        # formats used by more than one dir format will only be probed
1734
1734
        # once. This can otherwise be quite expensive for remote connections.
1735
1735
        result = set()
1736
1736
        for format in klass._control_formats:
1737
1737
            result.update(format._known_formats())
1738
1738
        return result
1739
 
    
 
1739
 
1740
1740
    @classmethod
1741
1741
    def _known_formats(klass):
1742
1742
        """Return the known format instances for this control format."""
1744
1744
 
1745
1745
    def open(self, transport, _found=False):
1746
1746
        """Return an instance of this format for the dir transport points at.
1747
 
        
 
1747
 
1748
1748
        _found is a private parameter, do not use it.
1749
1749
        """
1750
1750
        if not _found:
1751
1751
            found_format = BzrDirFormat.find_format(transport)
1752
1752
            if not isinstance(found_format, self.__class__):
1753
1753
                raise AssertionError("%s was asked to open %s, but it seems to need "
1754
 
                        "format %s" 
 
1754
                        "format %s"
1755
1755
                        % (self, transport, found_format))
1756
1756
        return self._open(transport)
1757
1757
 
1772
1772
        """Register a format that does not use '.bzr' for its control dir.
1773
1773
 
1774
1774
        TODO: This should be pulled up into a 'ControlDirFormat' base class
1775
 
        which BzrDirFormat can inherit from, and renamed to register_format 
 
1775
        which BzrDirFormat can inherit from, and renamed to register_format
1776
1776
        there. It has been done without that for now for simplicity of
1777
1777
        implementation.
1778
1778
        """
1834
1834
        """See BzrDirFormat.get_converter()."""
1835
1835
        # there is one and only one upgrade path here.
1836
1836
        return ConvertBzrDir4To5()
1837
 
        
 
1837
 
1838
1838
    def initialize_on_transport(self, transport):
1839
1839
        """Format 4 branches cannot be created."""
1840
1840
        raise errors.UninitializableFormat(self)
1843
1843
        """Format 4 is not supported.
1844
1844
 
1845
1845
        It is not supported because the model changed from 4 to 5 and the
1846
 
        conversion logic is expensive - so doing it on the fly was not 
 
1846
        conversion logic is expensive - so doing it on the fly was not
1847
1847
        feasible.
1848
1848
        """
1849
1849
        return False
1864
1864
 
1865
1865
    This format is a combined format for working tree, branch and repository.
1866
1866
    It has:
1867
 
     - Format 2 working trees [always] 
1868
 
     - Format 4 branches [always] 
 
1867
     - Format 2 working trees [always]
 
1868
     - Format 4 branches [always]
1869
1869
     - Format 5 repositories [always]
1870
1870
       Unhashed stores in the repository.
1871
1871
    """
1891
1891
 
1892
1892
    def _initialize_for_clone(self, url):
1893
1893
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1894
 
        
 
1894
 
1895
1895
    def initialize_on_transport(self, transport, _cloning=False):
1896
1896
        """Format 5 dirs always have working tree, branch and repository.
1897
 
        
 
1897
 
1898
1898
        Except when they are being cloned.
1899
1899
        """
1900
1900
        from bzrlib.branch import BzrBranchFormat4
1922
1922
 
1923
1923
    This format is a combined format for working tree, branch and repository.
1924
1924
    It has:
1925
 
     - Format 2 working trees [always] 
1926
 
     - Format 4 branches [always] 
 
1925
     - Format 2 working trees [always]
 
1926
     - Format 4 branches [always]
1927
1927
     - Format 6 repositories [always]
1928
1928
    """
1929
1929
 
1945
1945
        """See BzrDirFormat.get_converter()."""
1946
1946
        # there is one and only one upgrade path here.
1947
1947
        return ConvertBzrDir6ToMeta()
1948
 
        
 
1948
 
1949
1949
    def _initialize_for_clone(self, url):
1950
1950
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1951
1951
 
1952
1952
    def initialize_on_transport(self, transport, _cloning=False):
1953
1953
        """Format 6 dirs always have working tree, branch and repository.
1954
 
        
 
1954
 
1955
1955
        Except when they are being cloned.
1956
1956
        """
1957
1957
        from bzrlib.branch import BzrBranchFormat4
2116
2116
        self.absent_revisions = set()
2117
2117
        self.text_count = 0
2118
2118
        self.revisions = {}
2119
 
        
 
2119
 
2120
2120
    def convert(self, to_convert, pb):
2121
2121
        """See Converter.convert()."""
2122
2122
        self.bzrdir = to_convert
2228
2228
                revision_store.add_lines(key, None, osutils.split_lines(text))
2229
2229
        finally:
2230
2230
            self.pb.clear()
2231
 
            
 
2231
 
2232
2232
    def _load_one_rev(self, rev_id):
2233
2233
        """Load a revision object into memory.
2234
2234
 
2308
2308
        text_changed = False
2309
2309
        parent_candiate_entries = ie.parent_candidates(parent_invs)
2310
2310
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2311
 
        # XXX: Note that this is unordered - and this is tolerable because 
 
2311
        # XXX: Note that this is unordered - and this is tolerable because
2312
2312
        # the previous code was also unordered.
2313
2313
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2314
2314
            in heads)
2331
2331
        # a call to:. This needs the path figured out. rather than a work_tree
2332
2332
        # a v4 revision_tree can be given, or something that looks enough like
2333
2333
        # one to give the file content to the entry if it needs it.
2334
 
        # and we need something that looks like a weave store for snapshot to 
 
2334
        # and we need something that looks like a weave store for snapshot to
2335
2335
        # save against.
2336
2336
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
2337
2337
        if len(previous_revisions) == 1:
2453
2453
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
2454
2454
        self.make_lock('repository')
2455
2455
        # we hard code the formats here because we are converting into
2456
 
        # the meta format. The meta format upgrader can take this to a 
 
2456
        # the meta format. The meta format upgrader can take this to a
2457
2457
        # future format within each component.
2458
2458
        self.put_format('repository', RepositoryFormat7())
2459
2459
        for entry in repository_names:
2613
2613
 
2614
2614
    def get_format_description(self):
2615
2615
        return 'bzr remote bzrdir'
2616
 
    
 
2616
 
2617
2617
    @classmethod
2618
2618
    def probe_transport(klass, transport):
2619
2619
        """Return a RemoteBzrDirFormat object if it looks possible."""
2681
2681
 
2682
2682
class BzrDirFormatRegistry(registry.Registry):
2683
2683
    """Registry of user-selectable BzrDir subformats.
2684
 
    
 
2684
 
2685
2685
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2686
2686
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
2687
2687
    """
2746
2746
    def register(self, key, factory, help, native=True, deprecated=False,
2747
2747
                 hidden=False, experimental=False, alias=False):
2748
2748
        """Register a BzrDirFormat factory.
2749
 
        
 
2749
 
2750
2750
        The factory must be a callable that takes one parameter: the key.
2751
2751
        It must produce an instance of the BzrDirFormat when called.
2752
2752
 
2769
2769
 
2770
2770
    def set_default(self, key):
2771
2771
        """Set the 'default' key to be a clone of the supplied key.
2772
 
        
 
2772
 
2773
2773
        This method must be called once and only once.
2774
2774
        """
2775
2775
        registry.Registry.register(self, 'default', self.get(key),
2778
2778
 
2779
2779
    def set_default_repository(self, key):
2780
2780
        """Set the FormatRegistry default and Repository default.
2781
 
        
 
2781
 
2782
2782
        This is a transitional method while Repository.set_default_format
2783
2783
        is deprecated.
2784
2784
        """
2807
2807
        def wrapped(key, help, info):
2808
2808
            if info.native:
2809
2809
                help = '(native) ' + help
2810
 
            return ':%s:\n%s\n\n' % (key, 
2811
 
                    textwrap.fill(help, initial_indent='    ', 
 
2810
            return ':%s:\n%s\n\n' % (key,
 
2811
                    textwrap.fill(help, initial_indent='    ',
2812
2812
                    subsequent_indent='    '))
2813
2813
        if default_realkey is not None:
2814
2814
            output += wrapped(default_realkey, '(default) %s' % default_help,