~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Andrew Bennetts
  • Date: 2011-02-25 08:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 5695.
  • Revision ID: andrew.bennetts@canonical.com-20110225084527-0ucp7p00d00hoqon
Add another test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    ignores,
59
59
    inventory,
60
60
    merge,
61
 
    registry,
62
61
    revision as _mod_revision,
63
62
    revisiontree,
64
63
    trace,
2859
2858
            return path[:-len(suffix)]
2860
2859
 
2861
2860
 
2862
 
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
2863
 
    """Registry for working tree formats."""
2864
 
 
2865
 
    def __init__(self, other_registry=None):
2866
 
        super(WorkingTreeFormatRegistry, self).__init__(other_registry)
2867
 
        self._default_format = None
2868
 
 
2869
 
    def get_default(self):
2870
 
        """Return the current default format."""
2871
 
        return self._default_format
2872
 
 
2873
 
    def set_default(self, format):
2874
 
        self._default_format = format
2875
 
 
2876
 
 
2877
 
format_registry = WorkingTreeFormatRegistry()
2878
 
 
2879
 
 
2880
 
class WorkingTreeFormat(controldir.ControlComponentFormat):
 
2861
class WorkingTreeFormat(object):
2881
2862
    """An encapsulation of the initialization and open routines for a format.
2882
2863
 
2883
2864
    Formats provide three things:
2895
2876
    object will be created every time regardless.
2896
2877
    """
2897
2878
 
 
2879
    _default_format = None
 
2880
    """The default format used for new trees."""
 
2881
 
 
2882
    _formats = {}
 
2883
    """The known formats."""
 
2884
 
 
2885
    _extra_formats = []
 
2886
    """Extra formats that can not be used in a metadir."""
 
2887
 
2898
2888
    requires_rich_root = False
2899
2889
 
2900
2890
    upgrade_recommended = False
2912
2902
        try:
2913
2903
            transport = a_bzrdir.get_workingtree_transport(None)
2914
2904
            format_string = transport.get_bytes("format")
2915
 
            return format_registry.get(format_string)
 
2905
            return klass._formats[format_string]
2916
2906
        except errors.NoSuchFile:
2917
2907
            raise errors.NoWorkingTree(base=transport.base)
2918
2908
        except KeyError:
2919
2909
            raise errors.UnknownFormatError(format=format_string,
2920
2910
                                            kind="working tree")
2921
2911
 
2922
 
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2923
 
                   accelerator_tree=None, hardlink=False):
2924
 
        """Initialize a new working tree in a_bzrdir.
2925
 
 
2926
 
        :param a_bzrdir: BzrDir to initialize the working tree in.
2927
 
        :param revision_id: allows creating a working tree at a different
2928
 
            revision than the branch is at.
2929
 
        :param from_branch: Branch to checkout
2930
 
        :param accelerator_tree: A tree which can be used for retrieving file
2931
 
            contents more quickly than the revision tree, i.e. a workingtree.
2932
 
            The revision tree will be used for cases where accelerator_tree's
2933
 
            content is different.
2934
 
        :param hardlink: If true, hard-link files from accelerator_tree,
2935
 
            where possible.
2936
 
        """
2937
 
        raise NotImplementedError(self.initialize)
2938
 
 
2939
2912
    def __eq__(self, other):
2940
2913
        return self.__class__ is other.__class__
2941
2914
 
2943
2916
        return not (self == other)
2944
2917
 
2945
2918
    @classmethod
2946
 
    @symbol_versioning.deprecated_method(
2947
 
        symbol_versioning.deprecated_in((2, 4, 0)))
2948
2919
    def get_default_format(klass):
2949
2920
        """Return the current default format."""
2950
 
        return format_registry.get_default()
 
2921
        return klass._default_format
2951
2922
 
2952
2923
    def get_format_string(self):
2953
2924
        """Return the ASCII format string that identifies this format."""
2975
2946
        return False
2976
2947
 
2977
2948
    @classmethod
2978
 
    @symbol_versioning.deprecated_method(
2979
 
        symbol_versioning.deprecated_in((2, 4, 0)))
2980
2949
    def register_format(klass, format):
2981
 
        format_registry.register(format)
 
2950
        klass._formats[format.get_format_string()] = format
2982
2951
 
2983
2952
    @classmethod
2984
 
    @symbol_versioning.deprecated_method(
2985
 
        symbol_versioning.deprecated_in((2, 4, 0)))
2986
2953
    def register_extra_format(klass, format):
2987
 
        format_registry.register_extra(format)
 
2954
        klass._extra_formats.append(format)
2988
2955
 
2989
2956
    @classmethod
2990
 
    @symbol_versioning.deprecated_method(
2991
 
        symbol_versioning.deprecated_in((2, 4, 0)))
2992
2957
    def unregister_extra_format(klass, format):
2993
 
        format_registry.unregister_extra(format)
 
2958
        klass._extra_formats.remove(format)
2994
2959
 
2995
2960
    @classmethod
2996
 
    @symbol_versioning.deprecated_method(
2997
 
        symbol_versioning.deprecated_in((2, 4, 0)))
2998
2961
    def get_formats(klass):
2999
 
        return format_registry._get_all()
 
2962
        return klass._formats.values() + klass._extra_formats
3000
2963
 
3001
2964
    @classmethod
3002
 
    @symbol_versioning.deprecated_method(
3003
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3004
2965
    def set_default_format(klass, format):
3005
 
        format_registry.set_default(format)
 
2966
        klass._default_format = format
3006
2967
 
3007
2968
    @classmethod
3008
 
    @symbol_versioning.deprecated_method(
3009
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3010
2969
    def unregister_format(klass, format):
3011
 
        format_registry.remove(format)
 
2970
        del klass._formats[format.get_format_string()]
3012
2971
 
3013
2972
 
3014
2973
class WorkingTreeFormat2(WorkingTreeFormat):
3235
3194
 
3236
3195
 
3237
3196
__default_format = WorkingTreeFormat6()
3238
 
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
3239
 
    "bzrlib.workingtree_4", "WorkingTreeFormat4")
3240
 
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",
3241
 
    "bzrlib.workingtree_4", "WorkingTreeFormat5")
3242
 
format_registry.register_lazy("Bazaar Working Tree Format 6 (bzr 1.14)\n",
3243
 
    "bzrlib.workingtree_4", "WorkingTreeFormat6")
3244
 
format_registry.register(WorkingTreeFormat3())
3245
 
format_registry.set_default(__default_format)
 
3197
WorkingTreeFormat.register_format(__default_format)
 
3198
WorkingTreeFormat.register_format(WorkingTreeFormat5())
 
3199
WorkingTreeFormat.register_format(WorkingTreeFormat4())
 
3200
WorkingTreeFormat.register_format(WorkingTreeFormat3())
 
3201
WorkingTreeFormat.set_default_format(__default_format)
3246
3202
# Register extra formats which have no format string are not discoverable
3247
3203
# and not independently creatable. They are implicitly created as part of
3248
3204
# e.g. older Bazaar formats or foreign formats.
3249
 
format_registry.register_extra(WorkingTreeFormat2())
 
3205
WorkingTreeFormat.register_extra_format(WorkingTreeFormat2())