1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
878
877
def open_repository(self):
879
878
"""See BzrDir.open_repository."""
880
from bzrlib.repository import RepositoryFormat4
879
from bzrlib.repofmt.weaverepo import RepositoryFormat4
881
880
return RepositoryFormat4().open(self, _found=True)
890
889
def open_repository(self):
891
890
"""See BzrDir.open_repository."""
892
from bzrlib.repository import RepositoryFormat5
891
from bzrlib.repofmt.weaverepo import RepositoryFormat5
893
892
return RepositoryFormat5().open(self, _found=True)
895
894
def open_workingtree(self, _unsupported=False):
907
906
def open_repository(self):
908
907
"""See BzrDir.open_repository."""
909
from bzrlib.repository import RepositoryFormat6
908
from bzrlib.repofmt.weaverepo import RepositoryFormat6
910
909
return RepositoryFormat6().open(self, _found=True)
912
911
def open_workingtree(self, _unsupported=False):
931
930
def create_branch(self):
932
931
"""See BzrDir.create_branch."""
933
from bzrlib.branch import BranchFormat
934
return BranchFormat.get_default_format().initialize(self)
932
return self._format.get_branch_format().initialize(self)
936
934
def create_repository(self, shared=False):
937
935
"""See BzrDir.create_repository."""
1017
1015
except errors.NoRepositoryPresent:
1018
if not isinstance(self.open_branch()._format,
1019
format.get_branch_format().__class__):
1020
# the repository needs an upgrade.
1022
except errors.NotBranchError:
1019
1024
# currently there are no other possible conversions for meta1 formats.
1308
1313
def __return_repository_format(self):
1309
1314
"""Circular import protection."""
1310
from bzrlib.repository import RepositoryFormat4
1315
from bzrlib.repofmt.weaverepo import RepositoryFormat4
1311
1316
return RepositoryFormat4()
1312
1317
repository_format = property(__return_repository_format)
1347
1352
Except when they are being cloned.
1349
1354
from bzrlib.branch import BzrBranchFormat4
1350
from bzrlib.repository import RepositoryFormat5
1355
from bzrlib.repofmt.weaverepo import RepositoryFormat5
1351
1356
from bzrlib.workingtree import WorkingTreeFormat2
1352
1357
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1353
1358
RepositoryFormat5().initialize(result, _internal=True)
1368
1373
def __return_repository_format(self):
1369
1374
"""Circular import protection."""
1370
from bzrlib.repository import RepositoryFormat5
1375
from bzrlib.repofmt.weaverepo import RepositoryFormat5
1371
1376
return RepositoryFormat5()
1372
1377
repository_format = property(__return_repository_format)
1406
1411
Except when they are being cloned.
1408
1413
from bzrlib.branch import BzrBranchFormat4
1409
from bzrlib.repository import RepositoryFormat6
1414
from bzrlib.repofmt.weaverepo import RepositoryFormat6
1410
1415
from bzrlib.workingtree import WorkingTreeFormat2
1411
1416
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1412
1417
RepositoryFormat6().initialize(result, _internal=True)
1427
1432
def __return_repository_format(self):
1428
1433
"""Circular import protection."""
1429
from bzrlib.repository import RepositoryFormat6
1434
from bzrlib.repofmt.weaverepo import RepositoryFormat6
1430
1435
return RepositoryFormat6()
1431
1436
repository_format = property(__return_repository_format)
1445
1450
_lock_class = lockdir.LockDir
1453
self._branch_format = None
1455
def get_branch_format(self):
1456
if self._branch_format is None:
1457
from bzrlib.branch import BranchFormat
1458
self._branch_format = BranchFormat.get_default_format()
1459
return self._branch_format
1461
def set_branch_format(self, format):
1462
self._branch_format = format
1447
1464
def get_converter(self, format=None):
1448
1465
"""See BzrDirFormat.get_converter()."""
1449
1466
if format is None:
1839
1856
def convert(self, to_convert, pb):
1840
1857
"""See Converter.convert()."""
1858
from bzrlib.repofmt.weaverepo import RepositoryFormat7
1841
1859
from bzrlib.branch import BzrBranchFormat5
1842
1860
self.bzrdir = to_convert
1873
1891
# we hard code the formats here because we are converting into
1874
1892
# the meta format. The meta format upgrader can take this to a
1875
1893
# future format within each component.
1876
self.put_format('repository', _mod_repository.RepositoryFormat7())
1894
self.put_format('repository', RepositoryFormat7())
1877
1895
for entry in repository_names:
1878
1896
self.move_entry('repository', entry)
1974
1992
self.pb.note('starting repository conversion')
1975
1993
converter = CopyConverter(self.target_format.repository_format)
1976
1994
converter.convert(repo, pb)
1996
branch = self.bzrdir.open_branch()
1997
except errors.NotBranchError:
2000
# Avoid circular imports
2001
from bzrlib import branch as _mod_branch
2002
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2003
self.target_format.get_branch_format().__class__ is
2004
_mod_branch.BzrBranchFormat6):
2005
branch_converter = _mod_branch.Converter5to6()
2006
branch_converter.convert(branch)
1977
2007
return to_convert
1991
2021
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
1994
def register_metadir(self, key, repo, help, native=True, deprecated=False):
2024
def register_metadir(self, key, repo, help, native=True, deprecated=False,
2025
branch_format=None):
1995
2026
"""Register a metadir subformat.
1997
repo is the repository format name as a string.
2028
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2029
by the Repository format.
2031
:param repo: The fully-qualified repository format class name as a
1999
2034
# This should be expanded to support setting WorkingTree and Branch
2000
2035
# formats, once BzrDirMetaFormat1 supports that.
2002
import bzrlib.repository
2003
repo_format = getattr(bzrlib.repository, repo)
2037
import bzrlib.branch
2038
mod_name, repo_factory_name = repo.rsplit('.', 1)
2040
mod = __import__(mod_name, globals(), locals(),
2041
[repo_factory_name])
2042
except ImportError, e:
2043
raise ImportError('failed to load repository %s: %s'
2046
repo_format_class = getattr(mod, repo_factory_name)
2047
except AttributeError:
2048
raise AttributeError('no repository format %r in module %r'
2004
2050
bd = BzrDirMetaFormat1()
2005
bd.repository_format = repo_format()
2051
bd.repository_format = repo_format_class()
2052
if branch_format is not None:
2053
bd.set_branch_format(getattr(bzrlib.branch, branch_format)())
2007
2055
self.register(key, helper, help, native, deprecated)
2042
2090
self.set_default(key)
2043
2091
format = self.get('default')()
2044
2092
assert isinstance(format, BzrDirMetaFormat1)
2045
from bzrlib import repository
2046
repository.RepositoryFormat._set_default_format(
2047
format.repository_format)
2049
2094
def make_bzrdir(self, key):
2050
2095
return self.get(key)()
2096
2141
format_registry = BzrDirFormatRegistry()
2097
2142
format_registry.register('weave', BzrDirFormat6,
2098
2143
'Pre-0.8 format. Slower than knit and does not'
2099
' support checkouts or shared repositories.', deprecated=True)
2100
format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
2101
'Format using knits. Recommended.')
2144
' support checkouts or shared repositories.',
2146
format_registry.register_metadir('knit',
2147
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2148
'Format using knits. Recommended.',
2149
branch_format='BzrBranchFormat5')
2102
2150
format_registry.set_default('knit')
2103
format_registry.register_metadir('metaweave', 'RepositoryFormat7',
2151
format_registry.register_metadir('metaweave',
2152
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2104
2153
'Transitional format in 0.8. Slower than knit.',
2106
format_registry.register_metadir('experimental-knit2', 'RepositoryFormatKnit2',
2107
'Experimental successor to knit. Use at your own risk.')
2156
format_registry.register_metadir('experimental-knit2',
2157
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
2158
'Experimental successor to knit. Use at your own risk.',
2159
branch_format='BzrBranchFormat5')
2160
format_registry.register_metadir('experimental-branch6',
2161
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2162
'Experimental successor to knit. Use at your own risk.',
2163
branch_format='BzrBranchFormat6')