/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

Add RepositoryFormats and allow bzrdir.open or create _repository to be used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    BzrDir instances let you create or open any of the things that can be
41
41
    found within .bzr - checkouts, branches and repositories.
42
42
    
43
 
    base
44
 
        base directory this is located under.
 
43
    transport
 
44
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
45
45
    """
46
46
 
47
47
    @staticmethod
48
48
    def create(base):
49
 
        """Create a new BzrDir at the url 'bzr'.
 
49
        """Create a new BzrDir at the url 'base'.
50
50
        
51
51
        This will call the current default formats initialize with base
52
52
        as the only parameter.
56
56
        """
57
57
        return BzrDirFormat.get_default_format().initialize(safe_unicode(base))
58
58
 
 
59
    @staticmethod
 
60
    def create_repository(base):
 
61
        """Create a new BzrDir and Repository at the url 'base'.
 
62
 
 
63
        This will use the current default BzrDirFormat, and use whatever 
 
64
        repository format that that uses for bzrdirformat.create_repository.
 
65
 
 
66
        The Repository object is returned.
 
67
 
 
68
        This must be overridden as an instance method in child classes, where
 
69
        it should take no parameters and construct whatever repository format
 
70
        that child class desires.
 
71
        """
 
72
        bzrdir = BzrDir.create(base)
 
73
        return bzrdir.create_repository()
 
74
 
59
75
    def __init__(self, _transport, _format):
60
76
        """Initialize a Bzr control dir object.
61
77
        
66
82
        _transport: the transport this dir is based at.
67
83
        """
68
84
        self._format = _format
69
 
        self._transport = _transport
 
85
        self.transport = _transport
70
86
 
71
87
    @staticmethod
72
88
    def open_unsupported(base):
118
134
                raise errors.NotBranchError(path=url)
119
135
            t = new_t
120
136
 
 
137
    def open_repository(self):
 
138
        """Open the repository object at this BzrDir if one is present.
 
139
        
 
140
        TODO: static convenience version of this?
 
141
        TODO: NoRepositoryError that can be raised.
 
142
        """
 
143
        raise NotImplementedError(self.open_repository)
 
144
 
 
145
 
 
146
class BzrDir4(BzrDir):
 
147
    """A .bzr version 4 control object."""
 
148
 
 
149
    def create_repository(self):
 
150
        """See BzrDir.create_repository."""
 
151
        from bzrlib.repository import RepositoryFormat4
 
152
        return RepositoryFormat4().initialize(self)
 
153
 
 
154
    def open_repository(self):
 
155
        """See BzrDir.open_repository."""
 
156
        from bzrlib.repository import RepositoryFormat4
 
157
        return RepositoryFormat4().open(self, _found=True)
 
158
 
 
159
 
 
160
class BzrDir5(BzrDir):
 
161
    """A .bzr version 5 control object."""
 
162
 
 
163
    def create_repository(self):
 
164
        """See BzrDir.create_repository."""
 
165
        from bzrlib.repository import RepositoryFormat5
 
166
        return RepositoryFormat5().initialize(self)
 
167
 
 
168
    def open_repository(self):
 
169
        """See BzrDir.open_repository."""
 
170
        from bzrlib.repository import RepositoryFormat5
 
171
        return RepositoryFormat5().open(self, _found=True)
 
172
 
 
173
 
 
174
class BzrDir6(BzrDir):
 
175
    """A .bzr version 6 control object."""
 
176
 
 
177
    def create_repository(self):
 
178
        """See BzrDir.create_repository."""
 
179
        from bzrlib.repository import RepositoryFormat6
 
180
        return RepositoryFormat6().initialize(self)
 
181
 
 
182
    def open_repository(self):
 
183
        """See BzrDir.open_repository."""
 
184
        from bzrlib.repository import RepositoryFormat6
 
185
        return RepositoryFormat6().open(self, _found=True)
 
186
 
121
187
 
122
188
class BzrDirFormat(object):
123
189
    """An encapsulation of the initialization and open routines for a format.
137
203
    """
138
204
 
139
205
    _default_format = None
140
 
    """The default format used for new branches."""
 
206
    """The default format used for new .bzr dirs."""
141
207
 
142
208
    _formats = {}
143
209
    """The known formats."""
191
257
                control_files.put_utf8(file, content)
192
258
        finally:
193
259
            control_files.unlock()
194
 
        return BzrDir(t, self)
 
260
        return self.open(t, _found=True)
195
261
 
196
262
    def is_supported(self):
197
263
        """Is this format supported?
210
276
        if not _found:
211
277
            assert isinstance(BzrDirFormat.find_format(transport),
212
278
                              self.__class__)
213
 
        return BzrDir(transport, self)
 
279
        return self._open(transport)
 
280
 
 
281
    def _open(self, transport):
 
282
        """Template method helper for opening BzrDirectories.
 
283
 
 
284
        This performs the actual open and any additional logic or parameter
 
285
        passing.
 
286
        """
 
287
        raise NotImplementedError(self._open)
214
288
 
215
289
    @classmethod
216
290
    def register_format(klass, format):
255
329
        """
256
330
        return False
257
331
 
 
332
    def _open(self, transport):
 
333
        """See BzrDirFormat._open."""
 
334
        return BzrDir4(transport, self)
 
335
 
258
336
 
259
337
class BzrDirFormat5(BzrDirFormat):
260
338
    """Bzr control format 5.
270
348
        """See BzrDirFormat.get_format_string()."""
271
349
        return "Bazaar-NG branch, format 5\n"
272
350
 
 
351
    def _open(self, transport):
 
352
        """See BzrDirFormat._open."""
 
353
        return BzrDir5(transport, self)
 
354
 
273
355
 
274
356
class BzrDirFormat6(BzrDirFormat):
275
357
    """Bzr control format 6.
285
367
        """See BzrDirFormat.get_format_string()."""
286
368
        return "Bazaar-NG branch, format 6\n"
287
369
 
 
370
    def _open(self, transport):
 
371
        """See BzrDirFormat._open."""
 
372
        return BzrDir6(transport, self)
 
373
 
288
374
 
289
375
BzrDirFormat.register_format(BzrDirFormat4())
290
376
BzrDirFormat.register_format(BzrDirFormat5())