/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: 2008-09-02 18:37:02 UTC
  • mfrom: (3678 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3680.
  • Revision ID: john@arbash-meinel.com-20080902183702-16cpowcusfvo7rpv
Merge bzr.dev 3678, resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
                                       preserve_stacking=preserve_stacking)
178
178
 
179
179
    def clone_on_transport(self, transport, revision_id=None,
180
 
                           force_new_repo=False, preserve_stacking=False):
 
180
                           force_new_repo=False, preserve_stacking=False,
 
181
                           stacked_on=None):
181
182
        """Clone this bzrdir and its contents to transport verbatim.
182
183
 
183
184
        :param transport: The transport for the location to produce the clone
191
192
            new branch on top of the other branch's stacked-on branch.
192
193
        """
193
194
        transport.ensure_base()
194
 
        result = self.cloning_metadir().initialize_on_transport(transport)
 
195
        require_stacking = (stacked_on is not None)
 
196
        metadir = self.cloning_metadir(require_stacking)
 
197
        result = metadir.initialize_on_transport(transport)
195
198
        repository_policy = None
196
 
        stack_on = None
197
199
        try:
198
200
            local_repo = self.find_repository()
199
201
        except errors.NoRepositoryPresent:
208
210
                local_repo = local_branch.repository
209
211
            if preserve_stacking:
210
212
                try:
211
 
                    stack_on = local_branch.get_stacked_on_url()
 
213
                    stacked_on = local_branch.get_stacked_on_url()
212
214
                except (errors.UnstackableBranchFormat,
213
215
                        errors.UnstackableRepositoryFormat,
214
216
                        errors.NotStacked):
217
219
        if local_repo:
218
220
            # may need to copy content in
219
221
            repository_policy = result.determine_repository_policy(
220
 
                force_new_repo, stack_on, self.root_transport.base)
 
222
                force_new_repo, stacked_on, self.root_transport.base,
 
223
                require_stacking=require_stacking)
221
224
            make_working_trees = local_repo.make_working_trees()
222
225
            result_repo = repository_policy.acquire_repository(
223
226
                make_working_trees, local_repo.is_shared())
637
640
 
638
641
    def _find_creation_modes(self):
639
642
        """Determine the appropriate modes for files and directories.
640
 
        
 
643
 
641
644
        They're always set to be consistent with the base directory,
642
645
        assuming that this transport allows setting modes.
643
646
        """
656
659
            # directories and files are read-write for this user. This is
657
660
            # mostly a workaround for filesystems which lie about being able to
658
661
            # write to a directory (cygwin & win32)
659
 
            self._dir_mode = (st.st_mode & 07777) | 00700
660
 
            # Remove the sticky and execute bits for files
661
 
            self._file_mode = self._dir_mode & ~07111
 
662
            if (st.st_mode & 07777 == 00000):
 
663
                # FTP allows stat but does not return dir/file modes
 
664
                self._dir_mode = None
 
665
                self._file_mode = None
 
666
            else:
 
667
                self._dir_mode = (st.st_mode & 07777) | 00700
 
668
                # Remove the sticky and execute bits for files
 
669
                self._file_mode = self._dir_mode & ~07111
662
670
 
663
671
    def _get_file_mode(self):
664
672
        """Return Unix mode for newly created files, or None.
988
996
            try:
989
997
                branch = self.open_branch()
990
998
                source_repository = branch.repository
 
999
                result_format._branch_format = branch._format
991
1000
            except errors.NotBranchError:
992
1001
                source_branch = None
993
1002
                source_repository = self.open_repository()
1011
1020
            result_format.workingtree_format = tree._format.__class__()
1012
1021
        return result_format, source_repository
1013
1022
 
1014
 
    def cloning_metadir(self):
 
1023
    def cloning_metadir(self, require_stacking=False):
1015
1024
        """Produce a metadir suitable for cloning or sprouting with.
1016
1025
 
1017
1026
        These operations may produce workingtrees (yes, even though they're
1018
1027
        "cloning" something that doesn't have a tree), so a viable workingtree
1019
1028
        format must be selected.
1020
1029
 
 
1030
        :require_stacking: If True, non-stackable formats will be upgraded
 
1031
            to similar stackable formats.
1021
1032
        :returns: a BzrDirFormat with all component formats either set
1022
 
            appropriately or set to None if that component should not be 
 
1033
            appropriately or set to None if that component should not be
1023
1034
            created.
1024
1035
        """
1025
1036
        format, repository = self._cloning_metadir()
1028
1039
                return format
1029
1040
            tree_format = repository._format._matchingbzrdir.workingtree_format
1030
1041
            format.workingtree_format = tree_format.__class__()
 
1042
        if (require_stacking and not
 
1043
            format.get_branch_format().supports_stacking()):
 
1044
            # We need to make a stacked branch, but the default format for the
 
1045
            # target doesn't support stacking.  So force a branch that *can*
 
1046
            # support stacking.
 
1047
            from bzrlib.branch import BzrBranchFormat7
 
1048
            format._branch_format = BzrBranchFormat7()
 
1049
            mutter("using %r for stacking" % (format._branch_format,))
 
1050
            from bzrlib.repofmt import pack_repo
 
1051
            if format.repository_format.rich_root_data:
 
1052
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
1053
            else:
 
1054
                repo_format = pack_repo.RepositoryFormatKnitPack5()
 
1055
            format.repository_format = repo_format
1031
1056
        return format
1032
1057
 
1033
1058
    def checkout_metadir(self):
1059
1084
        """
1060
1085
        target_transport = get_transport(url, possible_transports)
1061
1086
        target_transport.ensure_base()
1062
 
        cloning_format = self.cloning_metadir()
 
1087
        cloning_format = self.cloning_metadir(stacked)
 
1088
        # Create/update the result branch
1063
1089
        result = cloning_format.initialize_on_transport(target_transport)
1064
1090
        try:
1065
1091
            source_branch = self.open_branch()
1081
1107
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1082
1108
        result_repo = repository_policy.acquire_repository()
1083
1109
        if source_repository is not None:
1084
 
            # XXX: Isn't this redundant with the copy_content_into used below
1085
 
            # after creating the branch? -- mbp 20080724
 
1110
            # Fetch while stacked to prevent unstacked fetch from
 
1111
            # Branch.sprout.
1086
1112
            result_repo.fetch(source_repository, revision_id=revision_id)
1087
1113
 
1088
 
        # Create/update the result branch
1089
 
        format_forced = False
1090
 
        if ((stacked 
1091
 
             or repository_policy._require_stacking 
1092
 
             or repository_policy._stack_on)
1093
 
            and not result._format.get_branch_format().supports_stacking()):
1094
 
            # We need to make a stacked branch, but the default format for the
1095
 
            # target doesn't support stacking.  So force a branch that *can*
1096
 
            # support stacking. 
1097
 
            from bzrlib.branch import BzrBranchFormat7
1098
 
            format = BzrBranchFormat7()
1099
 
            result_branch = format.initialize(result)
1100
 
            mutter("using %r for stacking" % (format,))
1101
 
            format_forced = True
1102
 
        elif source_branch is None:
 
1114
        if source_branch is None:
1103
1115
            # this is for sprouting a bzrdir without a branch; is that
1104
1116
            # actually useful?
 
1117
            # Not especially, but it's part of the contract.
1105
1118
            result_branch = result.create_branch()
1106
1119
        else:
 
1120
            # Force NULL revision to avoid using repository before stacking
 
1121
            # is configured.
1107
1122
            result_branch = source_branch.sprout(
1108
 
                result, revision_id=revision_id)
 
1123
                result, revision_id=_mod_revision.NULL_REVISION)
 
1124
            parent_location = result_branch.get_parent()
1109
1125
        mutter("created new branch %r" % (result_branch,))
1110
1126
        repository_policy.configure_branch(result_branch)
1111
 
        if source_branch is not None and format_forced:
1112
 
            # XXX: this duplicates Branch.sprout(); it probably belongs on an
1113
 
            # InterBranch method? -- mbp 20080724
1114
 
            source_branch.copy_content_into(result_branch,
1115
 
                 revision_id=revision_id)
1116
 
            result_branch.set_parent(self.root_transport.base)
 
1127
        if source_branch is not None:
 
1128
            source_branch.copy_content_into(result_branch, revision_id)
 
1129
            # Override copy_content_into
 
1130
            result_branch.set_parent(parent_location)
1117
1131
 
1118
1132
        # Create/update the result working tree
1119
1133
        if isinstance(target_transport, LocalTransport) and (
1172
1186
        """Pre-splitout bzrdirs do not suffer from stale locks."""
1173
1187
        raise NotImplementedError(self.break_lock)
1174
1188
 
1175
 
    def cloning_metadir(self):
 
1189
    def cloning_metadir(self, require_stacking=False):
1176
1190
        """Produce a metadir suitable for cloning with."""
 
1191
        if require_stacking:
 
1192
            return format_registry.make_bzrdir('1.6')
1177
1193
        return self._format.__class__()
1178
1194
 
1179
1195
    def clone(self, url, revision_id=None, force_new_repo=False,
1185
1201
        preserve_stacking has no effect, since no source branch using this
1186
1202
        family of formats can be stacked, so there is no stacking to preserve.
1187
1203
        """
1188
 
        from bzrlib.workingtree import WorkingTreeFormat2
1189
1204
        self._make_tail(url)
1190
1205
        result = self._format._initialize_for_clone(url)
1191
1206
        self.open_repository().clone(result, revision_id=revision_id)
1192
1207
        from_branch = self.open_branch()
1193
1208
        from_branch.clone(result, revision_id=revision_id)
1194
1209
        try:
1195
 
            self.open_workingtree().clone(result)
 
1210
            tree = self.open_workingtree()
1196
1211
        except errors.NotLocalUrl:
1197
1212
            # make a new one, this format always has to have one.
1198
 
            try:
1199
 
                WorkingTreeFormat2().initialize(result)
1200
 
            except errors.NotLocalUrl:
1201
 
                # but we cannot do it for remote trees.
1202
 
                to_branch = result.open_branch()
1203
 
                WorkingTreeFormat2()._stub_initialize_remote(to_branch)
 
1213
            result._init_workingtree()
 
1214
        else:
 
1215
            tree.clone(result)
1204
1216
        return result
1205
1217
 
1206
1218
    def create_branch(self):
1207
1219
        """See BzrDir.create_branch."""
1208
 
        return self.open_branch()
 
1220
        return self._format.get_branch_format().initialize(self)
1209
1221
 
1210
1222
    def destroy_branch(self):
1211
1223
        """See BzrDir.destroy_branch."""
1224
1236
    def create_workingtree(self, revision_id=None, from_branch=None,
1225
1237
                           accelerator_tree=None, hardlink=False):
1226
1238
        """See BzrDir.create_workingtree."""
 
1239
        # The workingtree is sometimes created when the bzrdir is created,
 
1240
        # but not when cloning.
 
1241
 
1227
1242
        # this looks buggy but is not -really-
1228
1243
        # because this format creates the workingtree when the bzrdir is
1229
1244
        # created
1233
1248
        # that can do wonky stuff here, and that only
1234
1249
        # happens for creating checkouts, which cannot be 
1235
1250
        # done on this format anyway. So - acceptable wart.
1236
 
        result = self.open_workingtree(recommend_upgrade=False)
 
1251
        try:
 
1252
            result = self.open_workingtree(recommend_upgrade=False)
 
1253
        except errors.NoSuchFile:
 
1254
            result = self._init_workingtree()
1237
1255
        if revision_id is not None:
1238
1256
            if revision_id == _mod_revision.NULL_REVISION:
1239
1257
                result.set_parent_ids([])
1241
1259
                result.set_parent_ids([revision_id])
1242
1260
        return result
1243
1261
 
 
1262
    def _init_workingtree(self):
 
1263
        from bzrlib.workingtree import WorkingTreeFormat2
 
1264
        try:
 
1265
            return WorkingTreeFormat2().initialize(self)
 
1266
        except errors.NotLocalUrl:
 
1267
            # Even though we can't access the working tree, we need to
 
1268
            # create its control files.
 
1269
            return WorkingTreeFormat2()._stub_initialize_on_transport(
 
1270
                self.transport, self._control_files._file_mode)
 
1271
 
1244
1272
    def destroy_workingtree(self):
1245
1273
        """See BzrDir.destroy_workingtree."""
1246
1274
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
1853
1881
        """See BzrDirFormat.get_format_string()."""
1854
1882
        return "Bazaar-NG branch, format 5\n"
1855
1883
 
 
1884
    def get_branch_format(self):
 
1885
        from bzrlib import branch
 
1886
        return branch.BzrBranchFormat4()
 
1887
 
1856
1888
    def get_format_description(self):
1857
1889
        """See BzrDirFormat.get_format_description()."""
1858
1890
        return "All-in-one format 5"
1872
1904
        """
1873
1905
        from bzrlib.branch import BzrBranchFormat4
1874
1906
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1875
 
        from bzrlib.workingtree import WorkingTreeFormat2
1876
1907
        result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1877
1908
        RepositoryFormat5().initialize(result, _internal=True)
1878
1909
        if not _cloning:
1879
1910
            branch = BzrBranchFormat4().initialize(result)
1880
 
            try:
1881
 
                WorkingTreeFormat2().initialize(result)
1882
 
            except errors.NotLocalUrl:
1883
 
                # Even though we can't access the working tree, we need to
1884
 
                # create its control files.
1885
 
                WorkingTreeFormat2()._stub_initialize_remote(branch)
 
1911
            result._init_workingtree()
1886
1912
        return result
1887
1913
 
1888
1914
    def _open(self, transport):
1916
1942
        """See BzrDirFormat.get_format_description()."""
1917
1943
        return "All-in-one format 6"
1918
1944
 
 
1945
    def get_branch_format(self):
 
1946
        from bzrlib import branch
 
1947
        return branch.BzrBranchFormat4()
 
1948
 
1919
1949
    def get_converter(self, format=None):
1920
1950
        """See BzrDirFormat.get_converter()."""
1921
1951
        # there is one and only one upgrade path here.
1931
1961
        """
1932
1962
        from bzrlib.branch import BzrBranchFormat4
1933
1963
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1934
 
        from bzrlib.workingtree import WorkingTreeFormat2
1935
1964
        result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1936
1965
        RepositoryFormat6().initialize(result, _internal=True)
1937
1966
        if not _cloning:
1938
1967
            branch = BzrBranchFormat4().initialize(result)
1939
 
            try:
1940
 
                WorkingTreeFormat2().initialize(result)
1941
 
            except errors.NotLocalUrl:
1942
 
                # Even though we can't access the working tree, we need to
1943
 
                # create its control files.
1944
 
                WorkingTreeFormat2()._stub_initialize_remote(branch)
 
1968
            result._init_workingtree()
1945
1969
        return result
1946
1970
 
1947
1971
    def _open(self, transport):
2891
2915
 
2892
2916
        Creates the desired repository in the bzrdir we already have.
2893
2917
        """
2894
 
        if self._stack_on or self._require_stacking:
2895
 
            # we may be coming from a format that doesn't support stacking,
2896
 
            # but we require it in the destination, so force creation of a new
2897
 
            # one here.
2898
 
            #
2899
 
            # TODO: perhaps this should be treated as a distinct repository
2900
 
            # acquisition policy?
2901
 
            repository_format = self._bzrdir._format.repository_format
2902
 
            if not repository_format.supports_external_lookups:
2903
 
                # should possibly be controlled by the registry rather than
2904
 
                # hardcoded here.
2905
 
                from bzrlib.repofmt import pack_repo
2906
 
                if repository_format.rich_root_data:
2907
 
                    repository_format = \
2908
 
                        pack_repo.RepositoryFormatKnitPack5RichRoot()
2909
 
                else:
2910
 
                    repository_format = pack_repo.RepositoryFormatKnitPack5()
2911
 
                note("using %r for stacking" % (repository_format,))
2912
 
            repository = repository_format.initialize(self._bzrdir,
2913
 
                shared=shared)
2914
 
        else:
2915
 
            # let bzrdir choose
2916
 
            repository = self._bzrdir.create_repository(shared=shared)
 
2918
        repository = self._bzrdir.create_repository(shared=shared)
2917
2919
        self._add_fallback(repository)
2918
2920
        if make_working_trees is not None:
2919
2921
            repository.set_make_working_trees(make_working_trees)
3033
3035
    branch_format='bzrlib.branch.BzrBranchFormat7',
3034
3036
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3035
3037
    )
3036
 
format_registry.register_metadir('1.6-rich-root',
 
3038
format_registry.register_metadir('1.6.1-rich-root',
3037
3039
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3038
3040
    help='A branch and pack based repository that supports stacking '
3039
3041
         'and rich root data (needed for bzr-svn). ',
3068
3070
    alias=True,
3069
3071
    )
3070
3072
# And the development formats which the will have aliased one of follow:
3071
 
format_registry.register_metadir('development0',
3072
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
3073
 
    help='Trivial rename of pack-0.92 to provide a development format. '
3074
 
        'Please read '
3075
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3076
 
        'before use.',
3077
 
    branch_format='bzrlib.branch.BzrBranchFormat6',
3078
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3079
 
    hidden=True,
3080
 
    experimental=True,
3081
 
    )
3082
 
format_registry.register_metadir('development0-subtree',
3083
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
3084
 
    help='Trivial rename of pack-0.92-subtree to provide a development format. '
3085
 
        'Please read '
3086
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3087
 
        'before use.',
3088
 
    branch_format='bzrlib.branch.BzrBranchFormat6',
3089
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3090
 
    hidden=True,
3091
 
    experimental=True,
3092
 
    )
3093
3073
format_registry.register_metadir('development1',
3094
3074
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
3095
3075
    help='A branch and pack based repository that supports stacking. '