~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-04 23:36:44 UTC
  • mfrom: (2224 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2225.
  • Revision ID: bialix@ukr.net-20070104233644-7znkxoj9b0y7ev28
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from cStringIO import StringIO
32
32
import os
 
33
import textwrap
33
34
 
34
35
from bzrlib.lazy_import import lazy_import
35
36
lazy_import(globals(), """
42
43
    errors,
43
44
    lockable_files,
44
45
    lockdir,
 
46
    registry,
45
47
    revision as _mod_revision,
46
48
    repository as _mod_repository,
47
49
    urlutils,
1941
1943
                converter = CopyConverter(self.target_format.repository_format)
1942
1944
                converter.convert(repo, pb)
1943
1945
        return to_convert
 
1946
 
 
1947
 
 
1948
class BzrDirFormatInfo(object):
 
1949
 
 
1950
    def __init__(self, native, deprecated):
 
1951
        self.deprecated = deprecated
 
1952
        self.native = native
 
1953
 
 
1954
 
 
1955
class BzrDirFormatRegistry(registry.Registry):
 
1956
    """Registry of user-selectable BzrDir subformats.
 
1957
    
 
1958
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
 
1959
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
 
1960
    """
 
1961
 
 
1962
    def register_metadir(self, key, repo, help, native=True, deprecated=False):
 
1963
        """Register a metadir subformat.
 
1964
        
 
1965
        repo is the repository format name as a string.
 
1966
        """
 
1967
        # This should be expanded to support setting WorkingTree and Branch
 
1968
        # formats, once BzrDirMetaFormat1 supports that.
 
1969
        def helper():
 
1970
            import bzrlib.repository
 
1971
            repo_format = getattr(bzrlib.repository, repo)
 
1972
            bd = BzrDirMetaFormat1()
 
1973
            bd.repository_format = repo_format()
 
1974
            return bd
 
1975
        self.register(key, helper, help, native, deprecated)
 
1976
 
 
1977
    def register(self, key, factory, help, native=True, deprecated=False):
 
1978
        """Register a BzrDirFormat factory.
 
1979
        
 
1980
        The factory must be a callable that takes one parameter: the key.
 
1981
        It must produce an instance of the BzrDirFormat when called.
 
1982
 
 
1983
        This function mainly exists to prevent the info object from being
 
1984
        supplied directly.
 
1985
        """
 
1986
        registry.Registry.register(self, key, factory, help, 
 
1987
            BzrDirFormatInfo(native, deprecated))
 
1988
 
 
1989
    def register_lazy(self, key, module_name, member_name, help, native=True,
 
1990
                      deprecated=False):
 
1991
        registry.Registry.register_lazy(self, key, module_name, member_name, 
 
1992
            help, BzrDirFormatInfo(native, deprecated))
 
1993
 
 
1994
    def set_default(self, key):
 
1995
        """Set the 'default' key to be a clone of the supplied key.
 
1996
        
 
1997
        This method must be called once and only once.
 
1998
        """
 
1999
        registry.Registry.register(self, 'default', self.get(key), 
 
2000
            self.get_help(key), info=self.get_info(key))
 
2001
 
 
2002
    def make_bzrdir(self, key):
 
2003
        return self.get(key)()
 
2004
 
 
2005
    def help_topic(self, topic):
 
2006
        output = textwrap.dedent("""\
 
2007
            Bazaar directory formats
 
2008
            ------------------------
 
2009
 
 
2010
            These formats can be used for creating branches, working trees, and
 
2011
            repositories.
 
2012
 
 
2013
            """)
 
2014
        default_help = self.get_help('default')
 
2015
        help_pairs = []
 
2016
        for key in self.keys():
 
2017
            if key == 'default':
 
2018
                continue
 
2019
            help = self.get_help(key)
 
2020
            if help == default_help:
 
2021
                default_realkey = key
 
2022
            else:
 
2023
                help_pairs.append((key, help))
 
2024
 
 
2025
        def wrapped(key, help, info):
 
2026
            if info.native:
 
2027
                help = '(native) ' + help
 
2028
            return '  %s:\n%s\n\n' % (key, 
 
2029
                    textwrap.fill(help, initial_indent='    ', 
 
2030
                    subsequent_indent='    '))
 
2031
        output += wrapped('%s/default' % default_realkey, default_help,
 
2032
                          self.get_info('default'))
 
2033
        deprecated_pairs = []
 
2034
        for key, help in help_pairs:
 
2035
            info = self.get_info(key)
 
2036
            if info.deprecated:
 
2037
                deprecated_pairs.append((key, help))
 
2038
            else:
 
2039
                output += wrapped(key, help, info)
 
2040
        if len(deprecated_pairs) > 0:
 
2041
            output += "Deprecated formats\n------------------\n\n"
 
2042
            for key, help in deprecated_pairs:
 
2043
                info = self.get_info(key)
 
2044
                output += wrapped(key, help, info)
 
2045
 
 
2046
        return output
 
2047
 
 
2048
 
 
2049
format_registry = BzrDirFormatRegistry()
 
2050
format_registry.register('weave', BzrDirFormat6,
 
2051
    'Pre-0.8 format.  Slower than knit and does not'
 
2052
    ' support checkouts or shared repositories.', deprecated=True)
 
2053
format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
 
2054
    'Format using knits.  Recommended.')
 
2055
format_registry.set_default('knit')
 
2056
format_registry.register_metadir('metaweave', 'RepositoryFormat7',
 
2057
    'Transitional format in 0.8.  Slower than knit.',
 
2058
    deprecated=True)
 
2059
format_registry.register_metadir('experimental-knit2', 'RepositoryFormatKnit2',
 
2060
    'Experimental successor to knit.  Use at your own risk.')