~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-02 15:28:44 UTC
  • mfrom: (3650.5.9 push)
  • Revision ID: pqm@pqm.ubuntu.com-20080902152844-dext0kmx4m0u5szy
Clean up push, allowing default stacking policies (abentley)

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())
1198
1201
        preserve_stacking has no effect, since no source branch using this
1199
1202
        family of formats can be stacked, so there is no stacking to preserve.
1200
1203
        """
1201
 
        from bzrlib.workingtree import WorkingTreeFormat2
1202
1204
        self._make_tail(url)
1203
1205
        result = self._format._initialize_for_clone(url)
1204
1206
        self.open_repository().clone(result, revision_id=revision_id)
1205
1207
        from_branch = self.open_branch()
1206
1208
        from_branch.clone(result, revision_id=revision_id)
1207
1209
        try:
1208
 
            self.open_workingtree().clone(result)
 
1210
            tree = self.open_workingtree()
1209
1211
        except errors.NotLocalUrl:
1210
1212
            # make a new one, this format always has to have one.
1211
 
            try:
1212
 
                WorkingTreeFormat2().initialize(result)
1213
 
            except errors.NotLocalUrl:
1214
 
                # but we cannot do it for remote trees.
1215
 
                to_branch = result.open_branch()
1216
 
                WorkingTreeFormat2()._stub_initialize_remote(to_branch)
 
1213
            result._init_workingtree()
 
1214
        else:
 
1215
            tree.clone(result)
1217
1216
        return result
1218
1217
 
1219
1218
    def create_branch(self):
1237
1236
    def create_workingtree(self, revision_id=None, from_branch=None,
1238
1237
                           accelerator_tree=None, hardlink=False):
1239
1238
        """See BzrDir.create_workingtree."""
 
1239
        # The workingtree is sometimes created when the bzrdir is created,
 
1240
        # but not when cloning.
 
1241
 
1240
1242
        # this looks buggy but is not -really-
1241
1243
        # because this format creates the workingtree when the bzrdir is
1242
1244
        # created
1246
1248
        # that can do wonky stuff here, and that only
1247
1249
        # happens for creating checkouts, which cannot be 
1248
1250
        # done on this format anyway. So - acceptable wart.
1249
 
        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()
1250
1255
        if revision_id is not None:
1251
1256
            if revision_id == _mod_revision.NULL_REVISION:
1252
1257
                result.set_parent_ids([])
1254
1259
                result.set_parent_ids([revision_id])
1255
1260
        return result
1256
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
 
1257
1272
    def destroy_workingtree(self):
1258
1273
        """See BzrDir.destroy_workingtree."""
1259
1274
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
1889
1904
        """
1890
1905
        from bzrlib.branch import BzrBranchFormat4
1891
1906
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1892
 
        from bzrlib.workingtree import WorkingTreeFormat2
1893
1907
        result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1894
1908
        RepositoryFormat5().initialize(result, _internal=True)
1895
1909
        if not _cloning:
1896
1910
            branch = BzrBranchFormat4().initialize(result)
1897
 
            try:
1898
 
                WorkingTreeFormat2().initialize(result)
1899
 
            except errors.NotLocalUrl:
1900
 
                # Even though we can't access the working tree, we need to
1901
 
                # create its control files.
1902
 
                WorkingTreeFormat2()._stub_initialize_remote(branch)
 
1911
            result._init_workingtree()
1903
1912
        return result
1904
1913
 
1905
1914
    def _open(self, transport):
1952
1961
        """
1953
1962
        from bzrlib.branch import BzrBranchFormat4
1954
1963
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1955
 
        from bzrlib.workingtree import WorkingTreeFormat2
1956
1964
        result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1957
1965
        RepositoryFormat6().initialize(result, _internal=True)
1958
1966
        if not _cloning:
1959
1967
            branch = BzrBranchFormat4().initialize(result)
1960
 
            try:
1961
 
                WorkingTreeFormat2().initialize(result)
1962
 
            except errors.NotLocalUrl:
1963
 
                # Even though we can't access the working tree, we need to
1964
 
                # create its control files.
1965
 
                WorkingTreeFormat2()._stub_initialize_remote(branch)
 
1968
            result._init_workingtree()
1966
1969
        return result
1967
1970
 
1968
1971
    def _open(self, transport):