~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: v.ladeuil+lp at free
  • Date: 2007-01-09 15:44:23 UTC
  • mfrom: (2227 +trunk)
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070109154423-lyvr5gmkwv6e0v6h
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    registry,
47
47
    revision as _mod_revision,
48
48
    repository as _mod_repository,
 
49
    symbol_versioning,
49
50
    urlutils,
50
51
    xml4,
51
52
    xml5,
207
208
 
208
209
    # TODO: Should take a Transport
209
210
    @classmethod
210
 
    def create(cls, base):
 
211
    def create(cls, base, format=None):
211
212
        """Create a new BzrDir at the url 'base'.
212
213
        
213
214
        This will call the current default formats initialize with base
214
215
        as the only parameter.
215
216
 
216
 
        If you need a specific format, consider creating an instance
217
 
        of that and calling initialize().
 
217
        :param format: If supplied, the format of branch to create.  If not
 
218
            supplied, the default is used.
218
219
        """
219
220
        if cls is not BzrDir:
220
 
            raise AssertionError("BzrDir.create always creates the default format, "
221
 
                    "not one of %r" % cls)
 
221
            raise AssertionError("BzrDir.create always creates the default"
 
222
                " format, not one of %r" % cls)
222
223
        head, tail = urlutils.split(base)
223
224
        if tail and tail != '.':
224
225
            t = get_transport(head)
226
227
                t.mkdir(tail)
227
228
            except errors.FileExists:
228
229
                pass
229
 
        return BzrDirFormat.get_default_format().initialize(safe_unicode(base))
 
230
        if format is None:
 
231
            format = BzrDirFormat.get_default_format()
 
232
        return format.initialize(safe_unicode(base))
230
233
 
231
234
    def create_branch(self):
232
235
        """Create a branch in this BzrDir.
237
240
        raise NotImplementedError(self.create_branch)
238
241
 
239
242
    @staticmethod
240
 
    def create_branch_and_repo(base, force_new_repo=False):
 
243
    def create_branch_and_repo(base, force_new_repo=False, format=None):
241
244
        """Create a new BzrDir, Branch and Repository at the url 'base'.
242
245
 
243
246
        This will use the current default BzrDirFormat, and use whatever 
250
253
        :param base: The URL to create the branch at.
251
254
        :param force_new_repo: If True a new repository is always created.
252
255
        """
253
 
        bzrdir = BzrDir.create(base)
 
256
        bzrdir = BzrDir.create(base, format)
254
257
        bzrdir._find_or_create_repository(force_new_repo)
255
258
        return bzrdir.create_branch()
256
259
 
294
297
            t = get_transport(safe_unicode(base))
295
298
            if not isinstance(t, LocalTransport):
296
299
                raise errors.NotLocalUrl(base)
297
 
        if format is None:
298
 
            bzrdir = BzrDir.create(base)
299
 
        else:
300
 
            bzrdir = format.initialize(base)
 
300
        bzrdir = BzrDir.create(base, format)
301
301
        repo = bzrdir._find_or_create_repository(force_new_repo)
302
302
        result = bzrdir.create_branch()
303
303
        if force_new_tree or (repo.make_working_trees() and 
309
309
        return result
310
310
        
311
311
    @staticmethod
312
 
    def create_repository(base, shared=False):
 
312
    def create_repository(base, shared=False, format=None):
313
313
        """Create a new BzrDir and Repository at the url 'base'.
314
314
 
315
 
        This will use the current default BzrDirFormat, and use whatever 
316
 
        repository format that that uses for bzrdirformat.create_repository.
 
315
        If no format is supplied, this will default to the current default
 
316
        BzrDirFormat by default, and use whatever repository format that that
 
317
        uses for bzrdirformat.create_repository.
317
318
 
318
319
        :param shared: Create a shared repository rather than a standalone
319
320
                       repository.
323
324
        it should take no parameters and construct whatever repository format
324
325
        that child class desires.
325
326
        """
326
 
        bzrdir = BzrDir.create(base)
 
327
        bzrdir = BzrDir.create(base, format)
327
328
        return bzrdir.create_repository(shared)
328
329
 
329
330
    @staticmethod
330
 
    def create_standalone_workingtree(base):
 
331
    def create_standalone_workingtree(base, format=None):
331
332
        """Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
332
333
 
333
334
        'base' must be a local path or a file:// url.
342
343
        if not isinstance(t, LocalTransport):
343
344
            raise errors.NotLocalUrl(base)
344
345
        bzrdir = BzrDir.create_branch_and_repo(safe_unicode(base),
345
 
                                               force_new_repo=True).bzrdir
 
346
                                               force_new_repo=True,
 
347
                                               format=format).bzrdir
346
348
        return bzrdir.create_workingtree()
347
349
 
348
350
    def create_workingtree(self, revision_id=None):
1246
1248
        klass._control_formats.append(format)
1247
1249
 
1248
1250
    @classmethod
 
1251
    @symbol_versioning.deprecated_method(symbol_versioning.zero_fourteen)
1249
1252
    def set_default_format(klass, format):
 
1253
        klass._set_default_format(format)
 
1254
 
 
1255
    @classmethod
 
1256
    def _set_default_format(klass, format):
 
1257
        """Set default format (for testing behavior of defaults only)"""
1250
1258
        klass._default_format = format
1251
1259
 
1252
1260
    def __str__(self):
1490
1498
BzrDirFormat.register_format(BzrDirFormat6())
1491
1499
__default_format = BzrDirMetaFormat1()
1492
1500
BzrDirFormat.register_format(__default_format)
1493
 
BzrDirFormat.set_default_format(__default_format)
 
1501
BzrDirFormat._default_format = __default_format
1494
1502
 
1495
1503
 
1496
1504
class BzrDirTestProviderAdapter(object):
2037
2045
        registry.Registry.register(self, 'default', self.get(key), 
2038
2046
            self.get_help(key), info=self.get_info(key))
2039
2047
 
 
2048
    def set_default_repository(self, key):
 
2049
        """Set the FormatRegistry default and Repository default.
 
2050
        
 
2051
        This is a transitional method while Repository.set_default_format
 
2052
        is deprecated.
 
2053
        """
 
2054
        if 'default' in self:
 
2055
            self.remove('default')
 
2056
        self.set_default(key)
 
2057
        format = self.get('default')()
 
2058
        assert isinstance(format, BzrDirMetaFormat1)
 
2059
        from bzrlib import repository
 
2060
        repository.RepositoryFormat._set_default_format(
 
2061
            format.repository_format)
 
2062
 
2040
2063
    def make_bzrdir(self, key):
2041
2064
        return self.get(key)()
2042
2065