~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

(jelmer) Add a common base class BzrDirMetaComponentFormat for all formats
 living in bzr meta directories. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3029
3029
 
3030
3030
    supports_versioned_directories = None
3031
3031
 
3032
 
    @classmethod
3033
 
    def find_format_string(klass, controldir):
3034
 
        """Return format name for the working tree object in controldir."""
3035
 
        try:
3036
 
            transport = controldir.get_workingtree_transport(None)
3037
 
            return transport.get_bytes("format")
3038
 
        except errors.NoSuchFile:
3039
 
            raise errors.NoWorkingTree(base=transport.base)
3040
 
 
3041
 
    @classmethod
3042
 
    def find_format(klass, controldir):
3043
 
        """Return the format for the working tree object in controldir."""
3044
 
        try:
3045
 
            format_string = klass.find_format_string(controldir)
3046
 
            return format_registry.get(format_string)
3047
 
        except KeyError:
3048
 
            raise errors.UnknownFormatError(format=format_string,
3049
 
                                            kind="working tree")
3050
 
 
3051
3032
    def initialize(self, controldir, revision_id=None, from_branch=None,
3052
3033
                   accelerator_tree=None, hardlink=False):
3053
3034
        """Initialize a new working tree in controldir.
3078
3059
        """Return the current default format."""
3079
3060
        return format_registry.get_default()
3080
3061
 
3081
 
    def get_format_string(self):
3082
 
        """Return the ASCII format string that identifies this format."""
3083
 
        raise NotImplementedError(self.get_format_string)
3084
 
 
3085
3062
    def get_format_description(self):
3086
3063
        """Return the short description for this format."""
3087
3064
        raise NotImplementedError(self.get_format_description)
3148
3125
        return self._matchingbzrdir
3149
3126
 
3150
3127
 
 
3128
class WorkingTreeFormatMetaDir(bzrdir.BzrDirMetaComponentFormat, WorkingTreeFormat):
 
3129
    """Base class for working trees that live in bzr meta directories."""
 
3130
 
 
3131
    def __init__(self):
 
3132
        WorkingTreeFormat.__init__(self)
 
3133
        bzrdir.BzrDirMetaComponentFormat.__init__(self)
 
3134
 
 
3135
    @classmethod
 
3136
    def find_format_string(klass, controldir):
 
3137
        """Return format name for the working tree object in controldir."""
 
3138
        try:
 
3139
            transport = controldir.get_workingtree_transport(None)
 
3140
            return transport.get_bytes("format")
 
3141
        except errors.NoSuchFile:
 
3142
            raise errors.NoWorkingTree(base=transport.base)
 
3143
 
 
3144
    @classmethod
 
3145
    def find_format(klass, controldir):
 
3146
        """Return the format for the working tree object in controldir."""
 
3147
        format_string = klass.find_format_string(controldir)
 
3148
        return klass._find_format(format_registry, 'working tree',
 
3149
                format_string)
 
3150
 
 
3151
 
3151
3152
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
3152
3153
    "bzrlib.workingtree_4", "WorkingTreeFormat4")
3153
3154
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",