1443
1452
# check the inventory for source and destination
1444
1453
if from_id is None:
1445
1454
raise errors.BzrMoveFailedError(from_rel,to_rel,
1446
errors.NotVersionedError(path=str(from_rel)))
1455
errors.NotVersionedError(path=from_rel))
1447
1456
if to_id is not None:
1448
1457
raise errors.BzrMoveFailedError(from_rel,to_rel,
1449
errors.AlreadyVersionedError(path=str(to_rel)))
1458
errors.AlreadyVersionedError(path=to_rel))
1451
1460
# try to determine the mode for rename (only change inv or change
1452
1461
# inv and file system)
1454
1463
if not self.has_filename(to_rel):
1455
1464
raise errors.BzrMoveFailedError(from_id,to_rel,
1456
errors.NoSuchFile(path=str(to_rel),
1465
errors.NoSuchFile(path=to_rel,
1457
1466
extra="New file has not been created yet"))
1458
1467
only_change_inv = True
1459
1468
elif not self.has_filename(from_rel) and self.has_filename(to_rel):
2425
2423
def add_conflicts(self, arg):
2426
2424
raise errors.UnsupportedOperation(self.add_conflicts, self)
2429
2426
def conflicts(self):
2430
conflicts = _mod_conflicts.ConflictList()
2431
for conflicted in self._iter_conflicts():
2434
if file_kind(self.abspath(conflicted)) != "file":
2436
except errors.NoSuchFile:
2439
for suffix in ('.THIS', '.OTHER'):
2441
kind = file_kind(self.abspath(conflicted+suffix))
2444
except errors.NoSuchFile:
2448
ctype = {True: 'text conflict', False: 'contents conflict'}[text]
2449
conflicts.append(_mod_conflicts.Conflict.factory(ctype,
2451
file_id=self.path2id(conflicted)))
2427
raise NotImplementedError(self.conflicts)
2454
2429
def walkdirs(self, prefix=""):
2455
2430
"""Walk the directories of this tree.
2652
def check_state(self):
2653
"""Check that the working state is/isn't valid."""
2654
check_refs = self._get_check_refs()
2656
for ref in check_refs:
2659
refs[ref] = self.branch.repository.revision_tree(value)
2662
@needs_tree_write_lock
2663
def reset_state(self, revision_ids=None):
2664
"""Reset the state of the working tree.
2666
This does a hard-reset to a last-known-good state. This is a way to
2667
fix if something got corrupted (like the .bzr/checkout/dirstate file)
2669
if revision_ids is None:
2670
revision_ids = self.get_parent_ids()
2671
if not revision_ids:
2672
rt = self.branch.repository.revision_tree(
2673
_mod_revision.NULL_REVISION)
2675
rt = self.branch.repository.revision_tree(revision_ids[0])
2676
self._write_inventory(rt.inventory)
2677
self.set_parent_ids(revision_ids)
2676
2679
def _get_rules_searcher(self, default_searcher):
2677
2680
"""See Tree._get_rules_searcher."""
2678
2681
if self._rules_searcher is None:
2686
2689
return ShelfManager(self, self._transport)
2689
class WorkingTree2(WorkingTree):
2690
"""This is the Format 2 working tree.
2692
This was the first weave based working tree.
2693
- uses os locks for locking.
2694
- uses the branch last-revision.
2697
def __init__(self, *args, **kwargs):
2698
super(WorkingTree2, self).__init__(*args, **kwargs)
2699
# WorkingTree2 has more of a constraint that self._inventory must
2700
# exist. Because this is an older format, we don't mind the overhead
2701
# caused by the extra computation here.
2703
# Newer WorkingTree's should only have self._inventory set when they
2705
if self._inventory is None:
2706
self.read_working_inventory()
2708
def _get_check_refs(self):
2709
"""Return the references needed to perform a check of this tree."""
2710
return [('trees', self.last_revision())]
2712
def lock_tree_write(self):
2713
"""See WorkingTree.lock_tree_write().
2715
In Format2 WorkingTrees we have a single lock for the branch and tree
2716
so lock_tree_write() degrades to lock_write().
2718
:return: An object with an unlock method which will release the lock
2721
self.branch.lock_write()
2723
self._control_files.lock_write()
2726
self.branch.unlock()
2730
# do non-implementation specific cleanup
2733
# we share control files:
2734
if self._control_files._lock_count == 3:
2735
# _inventory_is_modified is always False during a read lock.
2736
if self._inventory_is_modified:
2738
self._write_hashcache_if_dirty()
2740
# reverse order of locking.
2742
return self._control_files.unlock()
2744
self.branch.unlock()
2747
2692
class WorkingTree3(WorkingTree):
2748
2693
"""This is the Format 3 working tree.
2822
2768
self.branch.unlock()
2825
def get_conflicted_stem(path):
2826
for suffix in _mod_conflicts.CONFLICT_SUFFIXES:
2827
if path.endswith(suffix):
2828
return path[:-len(suffix)]
2831
class WorkingTreeFormat(object):
2771
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
2772
"""Registry for working tree formats."""
2774
def __init__(self, other_registry=None):
2775
super(WorkingTreeFormatRegistry, self).__init__(other_registry)
2776
self._default_format = None
2778
def get_default(self):
2779
"""Return the current default format."""
2780
return self._default_format
2782
def set_default(self, format):
2783
self._default_format = format
2786
format_registry = WorkingTreeFormatRegistry()
2789
class WorkingTreeFormat(controldir.ControlComponentFormat):
2832
2790
"""An encapsulation of the initialization and open routines for a format.
2834
2792
Formats provide three things:
2846
2804
object will be created every time regardless.
2849
_default_format = None
2850
"""The default format used for new trees."""
2853
"""The known formats."""
2855
2807
requires_rich_root = False
2857
2809
upgrade_recommended = False
2811
requires_normalized_unicode_filenames = False
2813
case_sensitive_filename = "FoRMaT"
2815
missing_parent_conflicts = False
2816
"""If this format supports missing parent conflicts."""
2860
2819
def find_format(klass, a_bzrdir):
2861
2820
"""Return the format for the working tree object in a_bzrdir."""
2863
2822
transport = a_bzrdir.get_workingtree_transport(None)
2864
2823
format_string = transport.get_bytes("format")
2865
return klass._formats[format_string]
2824
return format_registry.get(format_string)
2866
2825
except errors.NoSuchFile:
2867
2826
raise errors.NoWorkingTree(base=transport.base)
2868
2827
except KeyError:
2869
2828
raise errors.UnknownFormatError(format=format_string,
2870
2829
kind="working tree")
2831
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2832
accelerator_tree=None, hardlink=False):
2833
"""Initialize a new working tree in a_bzrdir.
2835
:param a_bzrdir: BzrDir to initialize the working tree in.
2836
:param revision_id: allows creating a working tree at a different
2837
revision than the branch is at.
2838
:param from_branch: Branch to checkout
2839
:param accelerator_tree: A tree which can be used for retrieving file
2840
contents more quickly than the revision tree, i.e. a workingtree.
2841
The revision tree will be used for cases where accelerator_tree's
2842
content is different.
2843
:param hardlink: If true, hard-link files from accelerator_tree,
2846
raise NotImplementedError(self.initialize)
2872
2848
def __eq__(self, other):
2873
2849
return self.__class__ is other.__class__
2887
@symbol_versioning.deprecated_method(
2888
symbol_versioning.deprecated_in((2, 4, 0)))
2909
2889
def register_format(klass, format):
2910
klass._formats[format.get_format_string()] = format
2890
format_registry.register(format)
2893
@symbol_versioning.deprecated_method(
2894
symbol_versioning.deprecated_in((2, 4, 0)))
2895
def register_extra_format(klass, format):
2896
format_registry.register_extra(format)
2899
@symbol_versioning.deprecated_method(
2900
symbol_versioning.deprecated_in((2, 4, 0)))
2901
def unregister_extra_format(klass, format):
2902
format_registry.unregister_extra(format)
2905
@symbol_versioning.deprecated_method(
2906
symbol_versioning.deprecated_in((2, 4, 0)))
2907
def get_formats(klass):
2908
return format_registry._get_all()
2911
@symbol_versioning.deprecated_method(
2912
symbol_versioning.deprecated_in((2, 4, 0)))
2913
2913
def set_default_format(klass, format):
2914
klass._default_format = format
2914
format_registry.set_default(format)
2917
@symbol_versioning.deprecated_method(
2918
symbol_versioning.deprecated_in((2, 4, 0)))
2917
2919
def unregister_format(klass, format):
2918
del klass._formats[format.get_format_string()]
2921
class WorkingTreeFormat2(WorkingTreeFormat):
2922
"""The second working tree format.
2924
This format modified the hash cache from the format 1 hash cache.
2927
upgrade_recommended = True
2929
def get_format_description(self):
2930
"""See WorkingTreeFormat.get_format_description()."""
2931
return "Working tree format 2"
2933
def _stub_initialize_on_transport(self, transport, file_mode):
2934
"""Workaround: create control files for a remote working tree.
2936
This ensures that it can later be updated and dealt with locally,
2937
since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with
2938
no working tree. (See bug #43064).
2941
inv = inventory.Inventory()
2942
xml5.serializer_v5.write_inventory(inv, sio, working=True)
2944
transport.put_file('inventory', sio, file_mode)
2945
transport.put_bytes('pending-merges', '', file_mode)
2947
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2948
accelerator_tree=None, hardlink=False):
2949
"""See WorkingTreeFormat.initialize()."""
2950
if not isinstance(a_bzrdir.transport, LocalTransport):
2951
raise errors.NotLocalUrl(a_bzrdir.transport.base)
2952
if from_branch is not None:
2953
branch = from_branch
2955
branch = a_bzrdir.open_branch()
2956
if revision_id is None:
2957
revision_id = _mod_revision.ensure_null(branch.last_revision())
2960
branch.generate_revision_history(revision_id)
2963
inv = inventory.Inventory()
2964
wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2970
basis_tree = branch.repository.revision_tree(revision_id)
2971
if basis_tree.inventory.root is not None:
2972
wt.set_root_id(basis_tree.get_root_id())
2973
# set the parent list and cache the basis tree.
2974
if _mod_revision.is_null(revision_id):
2977
parent_trees = [(revision_id, basis_tree)]
2978
wt.set_parent_trees(parent_trees)
2979
transform.build_tree(basis_tree, wt)
2983
super(WorkingTreeFormat2, self).__init__()
2984
self._matchingbzrdir = bzrdir.BzrDirFormat6()
2986
def open(self, a_bzrdir, _found=False):
2987
"""Return the WorkingTree object for a_bzrdir
2989
_found is a private parameter, do not use it. It is used to indicate
2990
if format probing has already been done.
2993
# we are being called directly and must probe.
2994
raise NotImplementedError
2995
if not isinstance(a_bzrdir.transport, LocalTransport):
2996
raise errors.NotLocalUrl(a_bzrdir.transport.base)
2997
wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2920
format_registry.remove(format)
3003
2923
class WorkingTreeFormat3(WorkingTreeFormat):
3004
2924
"""The second working tree format updated to record a format marker.
3134
3056
__default_format = WorkingTreeFormat6()
3135
WorkingTreeFormat.register_format(__default_format)
3136
WorkingTreeFormat.register_format(WorkingTreeFormat5())
3137
WorkingTreeFormat.register_format(WorkingTreeFormat4())
3138
WorkingTreeFormat.register_format(WorkingTreeFormat3())
3139
WorkingTreeFormat.set_default_format(__default_format)
3140
# formats which have no format string are not discoverable
3141
# and not independently creatable, so are not registered.
3142
_legacy_formats = [WorkingTreeFormat2(),
3057
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
3058
"bzrlib.workingtree_4", "WorkingTreeFormat4")
3059
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",
3060
"bzrlib.workingtree_4", "WorkingTreeFormat5")
3061
format_registry.register_lazy("Bazaar Working Tree Format 6 (bzr 1.14)\n",
3062
"bzrlib.workingtree_4", "WorkingTreeFormat6")
3063
format_registry.register(WorkingTreeFormat3())
3064
format_registry.set_default(__default_format)