45
45
the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
48
def _check_supported(self, format, allow_unsupported):
49
"""Check whether format is a supported format.
51
If allow_unsupported is True, this is a no-op.
53
if not allow_unsupported and not format.is_supported():
54
raise errors.UnsupportedFormatError(format)
50
58
"""Create a new BzrDir at the url 'base'.
125
133
"""Create a working tree at this BzrDir"""
126
134
raise NotImplementedError(self.create_workingtree)
136
def get_branch_transport(self, branch_format):
137
"""Get the transport for use by branch format in this BzrDir.
139
Note that bzr dirs that do not support format strings will raise
140
IncompatibleFormat if the branch format they are given has
141
a format string, and vice verca.
143
If branch_format is None, the transport is returned with no
144
checking. if it is not None, then the returned transport is
145
guaranteed to point to an existing directory ready for use.
147
raise NotImplementedError(self.get_branch_transport)
128
149
def __init__(self, _transport, _format):
129
150
"""Initialize a Bzr control dir object.
160
181
' and "bzr init" again'])
161
182
return format.open(t, _found=True)
163
def open_branch(self):
184
def open_branch(self, unsupported=False):
164
185
"""Open the branch object at this BzrDir if one is present.
187
If unsupported is True, then no longer supported branch formats can
166
190
TODO: static convenience version of this?
210
234
raise NotImplementedError(self.open_workingtree)
213
class BzrDir4(BzrDir):
237
class BzrDirPreSplitOut(BzrDir):
238
"""A common class for the all-in-one formats."""
240
def create_branch(self):
241
"""See BzrDir.create_branch."""
242
from bzrlib.branch import BzrBranchFormat4
243
return BzrBranchFormat4().initialize(self)
245
def get_branch_transport(self, branch_format):
246
"""See BzrDir.get_branch_transport()."""
247
if branch_format is None:
248
return self.transport
250
branch_format.get_format_string()
251
except NotImplementedError:
252
return self.transport
253
raise errors.IncompatibleFormat(branch_format, self._format)
255
def open_branch(self, unsupported=False):
256
"""See BzrDir.open_branch."""
257
from bzrlib.branch import BzrBranchFormat4
258
format = BzrBranchFormat4()
259
self._check_supported(format, unsupported)
260
return format.open(self, _found=True)
263
class BzrDir4(BzrDirPreSplitOut):
214
264
"""A .bzr version 4 control object."""
216
def create_branch(self):
217
"""See BzrDir.create_branch."""
218
from bzrlib.branch import BzrBranchFormat4
219
return BzrBranchFormat4().initialize(self)
221
266
def create_repository(self):
222
267
"""See BzrDir.create_repository."""
223
268
from bzrlib.repository import RepositoryFormat4
224
269
return RepositoryFormat4().initialize(self)
226
def open_branch(self):
227
"""See BzrDir.open_branch."""
228
from bzrlib.branch import BzrBranchFormat4
229
return BzrBranchFormat4().open(self, _found=True)
231
271
def open_repository(self):
232
272
"""See BzrDir.open_repository."""
233
273
from bzrlib.repository import RepositoryFormat4
234
274
return RepositoryFormat4().open(self, _found=True)
237
class BzrDir5(BzrDir):
277
class BzrDir5(BzrDirPreSplitOut):
238
278
"""A .bzr version 5 control object."""
240
def create_branch(self):
241
"""See BzrDir.create_branch."""
242
from bzrlib.branch import BzrBranchFormat4
243
return BzrBranchFormat4().initialize(self)
245
280
def create_repository(self):
246
281
"""See BzrDir.create_repository."""
247
282
from bzrlib.repository import RepositoryFormat5
252
287
from bzrlib.workingtree import WorkingTreeFormat2
253
288
return WorkingTreeFormat2().initialize(self)
255
def open_branch(self):
256
"""See BzrDir.open_branch."""
257
from bzrlib.branch import BzrBranchFormat4
258
return BzrBranchFormat4().open(self, _found=True)
260
290
def open_repository(self):
261
291
"""See BzrDir.open_repository."""
262
292
from bzrlib.repository import RepositoryFormat5
268
298
return WorkingTreeFormat2().open(self, _found=True)
271
class BzrDir6(BzrDir):
301
class BzrDir6(BzrDirPreSplitOut):
272
302
"""A .bzr version 6 control object."""
304
def create_repository(self):
305
"""See BzrDir.create_repository."""
306
from bzrlib.repository import RepositoryFormat6
307
return RepositoryFormat6().initialize(self)
309
def create_workingtree(self):
310
"""See BzrDir.create_workingtree."""
311
from bzrlib.workingtree import WorkingTreeFormat2
312
return WorkingTreeFormat2().initialize(self)
314
def open_repository(self):
315
"""See BzrDir.open_repository."""
316
from bzrlib.repository import RepositoryFormat6
317
return RepositoryFormat6().open(self, _found=True)
319
def open_workingtree(self):
320
"""See BzrDir.create_workingtree."""
321
from bzrlib.workingtree import WorkingTreeFormat2
322
return WorkingTreeFormat2().open(self, _found=True)
325
class BzrDirMeta1(BzrDir):
326
"""A .bzr meta version 1 control object.
328
This is the first control object where the
329
individual formats are really split out.
274
332
def create_branch(self):
275
333
"""See BzrDir.create_branch."""
276
from bzrlib.branch import BzrBranchFormat4
277
return BzrBranchFormat4().initialize(self)
334
from bzrlib.branch import BranchFormat
335
return BranchFormat.get_default_format().initialize(self)
279
337
def create_repository(self):
280
338
"""See BzrDir.create_repository."""
286
344
from bzrlib.workingtree import WorkingTreeFormat2
287
345
return WorkingTreeFormat2().initialize(self)
289
def open_branch(self):
347
def get_branch_transport(self, branch_format):
348
"""See BzrDir.get_branch_transport()."""
349
if branch_format is None:
350
return self.transport.clone('branch')
352
branch_format.get_format_string()
353
except NotImplementedError:
354
raise errors.IncompatibleFormat(branch_format, self._format)
356
self.transport.mkdir('branch')
357
except errors.FileExists:
359
return self.transport.clone('branch')
361
def open_branch(self, unsupported=False):
290
362
"""See BzrDir.open_branch."""
291
from bzrlib.branch import BzrBranchFormat4
292
return BzrBranchFormat4().open(self, _found=True)
363
from bzrlib.branch import BranchFormat
364
format = BranchFormat.find_format(self)
365
self._check_supported(format, unsupported)
366
return format.open(self, _found=True)
294
368
def open_repository(self):
295
369
"""See BzrDir.open_repository."""
490
564
return BzrDir6(transport, self)
567
class BzrDirMetaFormat1(BzrDirFormat):
568
"""Bzr meta control format 1
570
This is the first format with split out working tree, branch and repository
573
- Format 3 working trees
575
- Format 7 repositories
578
def get_format_string(self):
579
"""See BzrDirFormat.get_format_string()."""
580
return "Bazaar-NG meta directory, format 1\n"
582
def _open(self, transport):
583
"""See BzrDirFormat._open."""
584
return BzrDirMeta1(transport, self)
493
587
BzrDirFormat.register_format(BzrDirFormat4())
494
588
BzrDirFormat.register_format(BzrDirFormat5())
589
BzrDirFormat.register_format(BzrDirMetaFormat1())
495
590
__default_format = BzrDirFormat6()
496
591
BzrDirFormat.register_format(__default_format)
497
592
BzrDirFormat.set_default_format(__default_format)