/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

  • Committer: Martin Pool
  • Date: 2007-02-21 05:34:56 UTC
  • mfrom: (2296 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2309.
  • Revision ID: mbp@sourcefrog.net-20070221053456-vyr6o0ehqnbetrvb
merge trunk, in particular new Branch6 changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
925
925
 
926
926
    def create_branch(self):
927
927
        """See BzrDir.create_branch."""
928
 
        from bzrlib.branch import BranchFormat
929
 
        return BranchFormat.get_default_format().initialize(self)
 
928
        return self._format.get_branch_format().initialize(self)
930
929
 
931
930
    def create_repository(self, shared=False):
932
931
        """See BzrDir.create_repository."""
1011
1010
                return True
1012
1011
        except errors.NoRepositoryPresent:
1013
1012
            pass
 
1013
        try:
 
1014
            if not isinstance(self.open_branch()._format,
 
1015
                              format.get_branch_format().__class__):
 
1016
                # the repository needs an upgrade.
 
1017
                return True
 
1018
        except errors.NotBranchError:
 
1019
            pass
1014
1020
        # currently there are no other possible conversions for meta1 formats.
1015
1021
        return False
1016
1022
 
1439
1445
 
1440
1446
    _lock_class = lockdir.LockDir
1441
1447
 
 
1448
    def __init__(self):
 
1449
        self._branch_format = None
 
1450
 
 
1451
    def get_branch_format(self):
 
1452
        if self._branch_format is None:
 
1453
            from bzrlib.branch import BranchFormat
 
1454
            self._branch_format = BranchFormat.get_default_format()
 
1455
        return self._branch_format
 
1456
 
 
1457
    def set_branch_format(self, format):
 
1458
        self._branch_format = format
 
1459
 
1442
1460
    def get_converter(self, format=None):
1443
1461
        """See BzrDirFormat.get_converter()."""
1444
1462
        if format is None:
1970
1988
                self.pb.note('starting repository conversion')
1971
1989
                converter = CopyConverter(self.target_format.repository_format)
1972
1990
                converter.convert(repo, pb)
 
1991
        try:
 
1992
            branch = self.bzrdir.open_branch()
 
1993
        except errors.NotBranchError:
 
1994
            pass
 
1995
        else:
 
1996
            # Avoid circular imports
 
1997
            from bzrlib import branch as _mod_branch
 
1998
            if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
 
1999
                self.target_format.get_branch_format().__class__ is
 
2000
                _mod_branch.BzrBranchFormat6):
 
2001
                branch_converter = _mod_branch.Converter5to6()
 
2002
                branch_converter.convert(branch)
1973
2003
        return to_convert
1974
2004
 
1975
2005
 
1988
2018
    """
1989
2019
 
1990
2020
    def register_metadir(self, key, repo, help, native=True, deprecated=False,
1991
 
            repo_module='bzrlib.repository'):
 
2021
                         branch_format=None):
1992
2022
        """Register a metadir subformat.
1993
2023
 
1994
2024
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
1995
2025
        by the Repository format.
1996
2026
 
1997
 
        :param repo: The repository format class name as a string.
1998
 
 
1999
 
        :param repo_module: The module from which the repository class 
2000
 
        should be lazily loaded.  By default this is bzrlib.repository.
 
2027
        :param repo: The fully-qualified repository format class name as a
 
2028
        string.
2001
2029
        """
2002
2030
        # This should be expanded to support setting WorkingTree and Branch
2003
2031
        # formats, once BzrDirMetaFormat1 supports that.
2004
2032
        def helper():
2005
 
            mod = __import__(repo_module, globals(), locals(), [repo])
2006
 
            try:
2007
 
                repo_format_class = getattr(mod, repo)
 
2033
            import bzrlib.branch
 
2034
            mod_name, repo_factory_name = repo.rsplit('.', 1)
 
2035
            try:
 
2036
                mod = __import__(mod_name, globals(), locals(),
 
2037
                        [repo_factory_name])
 
2038
            except ImportError, e:
 
2039
                raise ImportError('failed to load repository %s: %s'
 
2040
                    % (repo, e))
 
2041
            try:
 
2042
                repo_format_class = getattr(mod, repo_factory_name)
2008
2043
            except AttributeError:
2009
2044
                raise AttributeError('no repository format %r in module %r' 
2010
2045
                    % (repo, mod))
2011
2046
            bd = BzrDirMetaFormat1()
2012
2047
            bd.repository_format = repo_format_class()
 
2048
            if branch_format is not None:
 
2049
                bd.set_branch_format(getattr(bzrlib.branch, branch_format)())
2013
2050
            return bd
2014
2051
        self.register(key, helper, help, native, deprecated)
2015
2052
 
2103
2140
    ' support checkouts or shared repositories.',
2104
2141
    deprecated=True)
2105
2142
format_registry.register_metadir('knit',
2106
 
    'RepositoryFormatKnit1',
 
2143
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2107
2144
    'Format using knits.  Recommended.',
2108
 
    repo_module='bzrlib.repofmt.knitrepo')
 
2145
    branch_format='BzrBranchFormat5')
2109
2146
format_registry.set_default('knit')
2110
 
format_registry.register_metadir('metaweave', 'RepositoryFormat7',
 
2147
format_registry.register_metadir('metaweave',
 
2148
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2111
2149
    'Transitional format in 0.8.  Slower than knit.',
2112
2150
    deprecated=True,
2113
 
    repo_module='bzrlib.repofmt.weaverepo')
 
2151
    )
2114
2152
format_registry.register_metadir('experimental-knit2',
2115
 
    'RepositoryFormatKnit2',
2116
 
    'Experimental successor to knit.  Use at your own risk.',
2117
 
    repo_module='bzrlib.repofmt.knitrepo')
 
2153
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit2',
 
2154
    'Experimental successor to knit.  Use at your own risk.',
 
2155
    branch_format='BzrBranchFormat5')
 
2156
format_registry.register_metadir('experimental-branch6',
 
2157
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
2158
    'Experimental successor to knit.  Use at your own risk.',
 
2159
    branch_format='BzrBranchFormat6')