2427
2429
def add_conflicts(self, arg):
2428
2430
raise errors.UnsupportedOperation(self.add_conflicts, self)
2431
2432
def conflicts(self):
2432
conflicts = _mod_conflicts.ConflictList()
2433
for conflicted in self._iter_conflicts():
2436
if file_kind(self.abspath(conflicted)) != "file":
2438
except errors.NoSuchFile:
2441
for suffix in ('.THIS', '.OTHER'):
2443
kind = file_kind(self.abspath(conflicted+suffix))
2446
except errors.NoSuchFile:
2450
ctype = {True: 'text conflict', False: 'contents conflict'}[text]
2451
conflicts.append(_mod_conflicts.Conflict.factory(ctype,
2453
file_id=self.path2id(conflicted)))
2433
raise NotImplementedError(self.conflicts)
2456
2435
def walkdirs(self, prefix=""):
2457
2436
"""Walk the directories of this tree.
2716
2695
return ShelfManager(self, self._transport)
2719
class WorkingTree2(WorkingTree):
2720
"""This is the Format 2 working tree.
2722
This was the first weave based working tree.
2723
- uses os locks for locking.
2724
- uses the branch last-revision.
2727
def __init__(self, *args, **kwargs):
2728
super(WorkingTree2, self).__init__(*args, **kwargs)
2729
# WorkingTree2 has more of a constraint that self._inventory must
2730
# exist. Because this is an older format, we don't mind the overhead
2731
# caused by the extra computation here.
2733
# Newer WorkingTree's should only have self._inventory set when they
2735
if self._inventory is None:
2736
self.read_working_inventory()
2738
def _get_check_refs(self):
2739
"""Return the references needed to perform a check of this tree."""
2740
return [('trees', self.last_revision())]
2742
def lock_tree_write(self):
2743
"""See WorkingTree.lock_tree_write().
2745
In Format2 WorkingTrees we have a single lock for the branch and tree
2746
so lock_tree_write() degrades to lock_write().
2748
:return: An object with an unlock method which will release the lock
2751
self.branch.lock_write()
2753
self._control_files.lock_write()
2756
self.branch.unlock()
2760
# do non-implementation specific cleanup
2763
# we share control files:
2764
if self._control_files._lock_count == 3:
2765
# _inventory_is_modified is always False during a read lock.
2766
if self._inventory_is_modified:
2768
self._write_hashcache_if_dirty()
2770
# reverse order of locking.
2772
return self._control_files.unlock()
2774
self.branch.unlock()
2777
2698
class WorkingTree3(WorkingTree):
2778
2699
"""This is the Format 3 working tree.
2852
2773
self.branch.unlock()
2855
def get_conflicted_stem(path):
2856
for suffix in _mod_conflicts.CONFLICT_SUFFIXES:
2857
if path.endswith(suffix):
2858
return path[:-len(suffix)]
2861
class WorkingTreeFormat(object):
2776
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
2777
"""Registry for working tree formats."""
2779
def __init__(self, other_registry=None):
2780
super(WorkingTreeFormatRegistry, self).__init__(other_registry)
2781
self._default_format = None
2783
def get_default(self):
2784
"""Return the current default format."""
2785
return self._default_format
2787
def set_default(self, format):
2788
self._default_format = format
2791
format_registry = WorkingTreeFormatRegistry()
2794
class WorkingTreeFormat(controldir.ControlComponentFormat):
2862
2795
"""An encapsulation of the initialization and open routines for a format.
2864
2797
Formats provide three things:
2903
2827
transport = a_bzrdir.get_workingtree_transport(None)
2904
2828
format_string = transport.get_bytes("format")
2905
return klass._formats[format_string]
2829
return format_registry.get(format_string)
2906
2830
except errors.NoSuchFile:
2907
2831
raise errors.NoWorkingTree(base=transport.base)
2908
2832
except KeyError:
2909
2833
raise errors.UnknownFormatError(format=format_string,
2910
2834
kind="working tree")
2836
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2837
accelerator_tree=None, hardlink=False):
2838
"""Initialize a new working tree in a_bzrdir.
2840
:param a_bzrdir: BzrDir to initialize the working tree in.
2841
:param revision_id: allows creating a working tree at a different
2842
revision than the branch is at.
2843
:param from_branch: Branch to checkout
2844
:param accelerator_tree: A tree which can be used for retrieving file
2845
contents more quickly than the revision tree, i.e. a workingtree.
2846
The revision tree will be used for cases where accelerator_tree's
2847
content is different.
2848
:param hardlink: If true, hard-link files from accelerator_tree,
2851
raise NotImplementedError(self.initialize)
2912
2853
def __eq__(self, other):
2913
2854
return self.__class__ is other.__class__
2892
@symbol_versioning.deprecated_method(
2893
symbol_versioning.deprecated_in((2, 4, 0)))
2949
2894
def register_format(klass, format):
2950
klass._formats[format.get_format_string()] = format
2895
format_registry.register(format)
2898
@symbol_versioning.deprecated_method(
2899
symbol_versioning.deprecated_in((2, 4, 0)))
2953
2900
def register_extra_format(klass, format):
2954
klass._extra_formats.append(format)
2901
format_registry.register_extra(format)
2904
@symbol_versioning.deprecated_method(
2905
symbol_versioning.deprecated_in((2, 4, 0)))
2957
2906
def unregister_extra_format(klass, format):
2958
klass._extra_formats.remove(format)
2907
format_registry.unregister_extra(format)
2910
@symbol_versioning.deprecated_method(
2911
symbol_versioning.deprecated_in((2, 4, 0)))
2961
2912
def get_formats(klass):
2962
return klass._formats.values() + klass._extra_formats
2913
return format_registry._get_all()
2916
@symbol_versioning.deprecated_method(
2917
symbol_versioning.deprecated_in((2, 4, 0)))
2965
2918
def set_default_format(klass, format):
2966
klass._default_format = format
2919
format_registry.set_default(format)
2922
@symbol_versioning.deprecated_method(
2923
symbol_versioning.deprecated_in((2, 4, 0)))
2969
2924
def unregister_format(klass, format):
2970
del klass._formats[format.get_format_string()]
2973
class WorkingTreeFormat2(WorkingTreeFormat):
2974
"""The second working tree format.
2976
This format modified the hash cache from the format 1 hash cache.
2979
upgrade_recommended = True
2981
requires_normalized_unicode_filenames = True
2983
case_sensitive_filename = "Branch-FoRMaT"
2985
missing_parent_conflicts = False
2987
def get_format_description(self):
2988
"""See WorkingTreeFormat.get_format_description()."""
2989
return "Working tree format 2"
2991
def _stub_initialize_on_transport(self, transport, file_mode):
2992
"""Workaround: create control files for a remote working tree.
2994
This ensures that it can later be updated and dealt with locally,
2995
since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with
2996
no working tree. (See bug #43064).
2999
inv = inventory.Inventory()
3000
xml5.serializer_v5.write_inventory(inv, sio, working=True)
3002
transport.put_file('inventory', sio, file_mode)
3003
transport.put_bytes('pending-merges', '', file_mode)
3005
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
3006
accelerator_tree=None, hardlink=False):
3007
"""See WorkingTreeFormat.initialize()."""
3008
if not isinstance(a_bzrdir.transport, LocalTransport):
3009
raise errors.NotLocalUrl(a_bzrdir.transport.base)
3010
if from_branch is not None:
3011
branch = from_branch
3013
branch = a_bzrdir.open_branch()
3014
if revision_id is None:
3015
revision_id = _mod_revision.ensure_null(branch.last_revision())
3018
branch.generate_revision_history(revision_id)
3021
inv = inventory.Inventory()
3022
wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
3028
_control_files=branch.control_files)
3029
basis_tree = branch.repository.revision_tree(revision_id)
3030
if basis_tree.inventory.root is not None:
3031
wt.set_root_id(basis_tree.get_root_id())
3032
# set the parent list and cache the basis tree.
3033
if _mod_revision.is_null(revision_id):
3036
parent_trees = [(revision_id, basis_tree)]
3037
wt.set_parent_trees(parent_trees)
3038
transform.build_tree(basis_tree, wt)
3042
super(WorkingTreeFormat2, self).__init__()
3043
self._matchingbzrdir = bzrdir.BzrDirFormat6()
3045
def open(self, a_bzrdir, _found=False):
3046
"""Return the WorkingTree object for a_bzrdir
3048
_found is a private parameter, do not use it. It is used to indicate
3049
if format probing has already been done.
3052
# we are being called directly and must probe.
3053
raise NotImplementedError
3054
if not isinstance(a_bzrdir.transport, LocalTransport):
3055
raise errors.NotLocalUrl(a_bzrdir.transport.base)
3056
wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
3060
_control_files=a_bzrdir.open_branch().control_files)
2925
format_registry.remove(format)
3063
2928
class WorkingTreeFormat3(WorkingTreeFormat):
3064
2929
"""The second working tree format updated to record a format marker.
3196
3061
__default_format = WorkingTreeFormat6()
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)
3202
# Register extra formats which have no format string are not discoverable
3203
# and not independently creatable. They are implicitly created as part of
3204
# e.g. older Bazaar formats or foreign formats.
3205
WorkingTreeFormat.register_extra_format(WorkingTreeFormat2())
3062
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
3063
"bzrlib.workingtree_4", "WorkingTreeFormat4")
3064
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",
3065
"bzrlib.workingtree_4", "WorkingTreeFormat5")
3066
format_registry.register_lazy("Bazaar Working Tree Format 6 (bzr 1.14)\n",
3067
"bzrlib.workingtree_4", "WorkingTreeFormat6")
3068
format_registry.register(WorkingTreeFormat3())
3069
format_registry.set_default(__default_format)