~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
46
46
    """
47
47
 
 
48
    def _check_supported(self, format, allow_unsupported):
 
49
        """Check whether format is a supported format.
 
50
 
 
51
        If allow_unsupported is True, this is a no-op.
 
52
        """
 
53
        if not allow_unsupported and not format.is_supported():
 
54
            raise errors.UnsupportedFormatError(format)
 
55
 
48
56
    @staticmethod
49
57
    def create(base):
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)
127
135
 
 
136
    def get_branch_transport(self, branch_format):
 
137
        """Get the transport for use by branch format in this BzrDir.
 
138
 
 
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.
 
142
 
 
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.
 
146
        """
 
147
        raise NotImplementedError(self.get_branch_transport)
 
148
        
128
149
    def __init__(self, _transport, _format):
129
150
        """Initialize a Bzr control dir object.
130
151
        
160
181
                     ' and "bzr init" again'])
161
182
        return format.open(t, _found=True)
162
183
 
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.
 
186
 
 
187
        If unsupported is True, then no longer supported branch formats can
 
188
        still be opened.
165
189
        
166
190
        TODO: static convenience version of this?
167
191
        """
210
234
        raise NotImplementedError(self.open_workingtree)
211
235
 
212
236
 
213
 
class BzrDir4(BzrDir):
 
237
class BzrDirPreSplitOut(BzrDir):
 
238
    """A common class for the all-in-one formats."""
 
239
 
 
240
    def create_branch(self):
 
241
        """See BzrDir.create_branch."""
 
242
        from bzrlib.branch import BzrBranchFormat4
 
243
        return BzrBranchFormat4().initialize(self)
 
244
 
 
245
    def get_branch_transport(self, branch_format):
 
246
        """See BzrDir.get_branch_transport()."""
 
247
        if branch_format is None:
 
248
            return self.transport
 
249
        try:
 
250
            branch_format.get_format_string()
 
251
        except NotImplementedError:
 
252
            return self.transport
 
253
        raise errors.IncompatibleFormat(branch_format, self._format)
 
254
 
 
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)
 
261
 
 
262
 
 
263
class BzrDir4(BzrDirPreSplitOut):
214
264
    """A .bzr version 4 control object."""
215
265
 
216
 
    def create_branch(self):
217
 
        """See BzrDir.create_branch."""
218
 
        from bzrlib.branch import BzrBranchFormat4
219
 
        return BzrBranchFormat4().initialize(self)
220
 
 
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)
225
270
 
226
 
    def open_branch(self):
227
 
        """See BzrDir.open_branch."""
228
 
        from bzrlib.branch import BzrBranchFormat4
229
 
        return BzrBranchFormat4().open(self, _found=True)
230
 
 
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)
235
275
 
236
276
 
237
 
class BzrDir5(BzrDir):
 
277
class BzrDir5(BzrDirPreSplitOut):
238
278
    """A .bzr version 5 control object."""
239
279
 
240
 
    def create_branch(self):
241
 
        """See BzrDir.create_branch."""
242
 
        from bzrlib.branch import BzrBranchFormat4
243
 
        return BzrBranchFormat4().initialize(self)
244
 
 
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)
254
289
 
255
 
    def open_branch(self):
256
 
        """See BzrDir.open_branch."""
257
 
        from bzrlib.branch import BzrBranchFormat4
258
 
        return BzrBranchFormat4().open(self, _found=True)
259
 
 
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)
269
299
 
270
300
 
271
 
class BzrDir6(BzrDir):
 
301
class BzrDir6(BzrDirPreSplitOut):
272
302
    """A .bzr version 6 control object."""
273
303
 
 
304
    def create_repository(self):
 
305
        """See BzrDir.create_repository."""
 
306
        from bzrlib.repository import RepositoryFormat6
 
307
        return RepositoryFormat6().initialize(self)
 
308
 
 
309
    def create_workingtree(self):
 
310
        """See BzrDir.create_workingtree."""
 
311
        from bzrlib.workingtree import WorkingTreeFormat2
 
312
        return WorkingTreeFormat2().initialize(self)
 
313
 
 
314
    def open_repository(self):
 
315
        """See BzrDir.open_repository."""
 
316
        from bzrlib.repository import RepositoryFormat6
 
317
        return RepositoryFormat6().open(self, _found=True)
 
318
 
 
319
    def open_workingtree(self):
 
320
        """See BzrDir.create_workingtree."""
 
321
        from bzrlib.workingtree import WorkingTreeFormat2
 
322
        return WorkingTreeFormat2().open(self, _found=True)
 
323
 
 
324
 
 
325
class BzrDirMeta1(BzrDir):
 
326
    """A .bzr meta version 1 control object.
 
327
    
 
328
    This is the first control object where the 
 
329
    individual formats are really split out.
 
330
    """
 
331
 
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)
278
336
 
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)
288
346
 
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')
 
351
        try:
 
352
            branch_format.get_format_string()
 
353
        except NotImplementedError:
 
354
            raise errors.IncompatibleFormat(branch_format, self._format)
 
355
        try:
 
356
            self.transport.mkdir('branch')
 
357
        except errors.FileExists:
 
358
            pass
 
359
        return self.transport.clone('branch')
 
360
 
 
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)
293
367
 
294
368
    def open_repository(self):
295
369
        """See BzrDir.open_repository."""
490
564
        return BzrDir6(transport, self)
491
565
 
492
566
 
 
567
class BzrDirMetaFormat1(BzrDirFormat):
 
568
    """Bzr meta control format 1
 
569
 
 
570
    This is the first format with split out working tree, branch and repository
 
571
    disk storage.
 
572
    It has:
 
573
     - Format 3 working trees
 
574
     - Format 5 branches
 
575
     - Format 7 repositories
 
576
    """
 
577
 
 
578
    def get_format_string(self):
 
579
        """See BzrDirFormat.get_format_string()."""
 
580
        return "Bazaar-NG meta directory, format 1\n"
 
581
 
 
582
    def _open(self, transport):
 
583
        """See BzrDirFormat._open."""
 
584
        return BzrDirMeta1(transport, self)
 
585
 
 
586
 
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)