2859
2858
return path[:-len(suffix)]
2862
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
2863
"""Registry for working tree formats."""
2865
def __init__(self, other_registry=None):
2866
super(WorkingTreeFormatRegistry, self).__init__(other_registry)
2867
self._default_format = None
2869
def get_default(self):
2870
"""Return the current default format."""
2871
return self._default_format
2873
def set_default(self, format):
2874
self._default_format = format
2877
format_registry = WorkingTreeFormatRegistry()
2880
class WorkingTreeFormat(controldir.ControlComponentFormat):
2861
class WorkingTreeFormat(object):
2881
2862
"""An encapsulation of the initialization and open routines for a format.
2883
2864
Formats provide three things:
2895
2876
object will be created every time regardless.
2879
_default_format = None
2880
"""The default format used for new trees."""
2883
"""The known formats."""
2886
"""Extra formats that can not be used in a metadir."""
2898
2888
requires_rich_root = False
2900
2890
upgrade_recommended = False
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")
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.
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,
2937
raise NotImplementedError(self.initialize)
2939
2912
def __eq__(self, other):
2940
2913
return self.__class__ is other.__class__
2943
2916
return not (self == other)
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
2952
2923
def get_format_string(self):
2953
2924
"""Return the ASCII format string that identifies this format."""
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
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)
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)
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
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
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()]
3014
2973
class WorkingTreeFormat2(WorkingTreeFormat):
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())