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.
44
base directory this is located under.
44
the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
49
"""Create a new BzrDir at the url 'bzr'.
49
"""Create a new BzrDir at the url 'base'.
51
51
This will call the current default formats initialize with base
52
52
as the only parameter.
57
57
return BzrDirFormat.get_default_format().initialize(safe_unicode(base))
60
def create_repository(base):
61
"""Create a new BzrDir and Repository at the url 'base'.
63
This will use the current default BzrDirFormat, and use whatever
64
repository format that that uses for bzrdirformat.create_repository.
66
The Repository object is returned.
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.
72
bzrdir = BzrDir.create(base)
73
return bzrdir.create_repository()
59
75
def __init__(self, _transport, _format):
60
76
"""Initialize a Bzr control dir object.
118
134
raise errors.NotBranchError(path=url)
137
def open_repository(self):
138
"""Open the repository object at this BzrDir if one is present.
140
TODO: static convenience version of this?
141
TODO: NoRepositoryError that can be raised.
143
raise NotImplementedError(self.open_repository)
146
class BzrDir4(BzrDir):
147
"""A .bzr version 4 control object."""
149
def create_repository(self):
150
"""See BzrDir.create_repository."""
151
from bzrlib.repository import RepositoryFormat4
152
return RepositoryFormat4().initialize(self)
154
def open_repository(self):
155
"""See BzrDir.open_repository."""
156
from bzrlib.repository import RepositoryFormat4
157
return RepositoryFormat4().open(self, _found=True)
160
class BzrDir5(BzrDir):
161
"""A .bzr version 5 control object."""
163
def create_repository(self):
164
"""See BzrDir.create_repository."""
165
from bzrlib.repository import RepositoryFormat5
166
return RepositoryFormat5().initialize(self)
168
def open_repository(self):
169
"""See BzrDir.open_repository."""
170
from bzrlib.repository import RepositoryFormat5
171
return RepositoryFormat5().open(self, _found=True)
174
class BzrDir6(BzrDir):
175
"""A .bzr version 6 control object."""
177
def create_repository(self):
178
"""See BzrDir.create_repository."""
179
from bzrlib.repository import RepositoryFormat6
180
return RepositoryFormat6().initialize(self)
182
def open_repository(self):
183
"""See BzrDir.open_repository."""
184
from bzrlib.repository import RepositoryFormat6
185
return RepositoryFormat6().open(self, _found=True)
122
188
class BzrDirFormat(object):
123
189
"""An encapsulation of the initialization and open routines for a format.
211
277
assert isinstance(BzrDirFormat.find_format(transport),
213
return BzrDir(transport, self)
279
return self._open(transport)
281
def _open(self, transport):
282
"""Template method helper for opening BzrDirectories.
284
This performs the actual open and any additional logic or parameter
287
raise NotImplementedError(self._open)
216
290
def register_format(klass, format):
332
def _open(self, transport):
333
"""See BzrDirFormat._open."""
334
return BzrDir4(transport, self)
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"
351
def _open(self, transport):
352
"""See BzrDirFormat._open."""
353
return BzrDir5(transport, self)
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"
370
def _open(self, transport):
371
"""See BzrDirFormat._open."""
372
return BzrDir6(transport, self)
289
375
BzrDirFormat.register_format(BzrDirFormat4())
290
376
BzrDirFormat.register_format(BzrDirFormat5())