268
268
self._control_files.break_lock()
269
269
self.branch.break_lock()
271
def _get_check_refs(self):
272
"""Return the references needed to perform a check of this tree.
274
The default implementation returns no refs, and is only suitable for
275
trees that have no local caching and can commit on ghosts at any time.
277
:seealso: bzrlib.check for details about check_refs.
281
271
def requires_rich_root(self):
282
272
return self._format.requires_rich_root
572
562
def id2abspath(self, file_id):
573
563
return self.abspath(self.id2path(file_id))
565
def _check_for_tree_references(self, iterator):
566
"""See if directories have become tree-references."""
567
blocked_parent_ids = set()
568
for path, ie in iterator:
569
if ie.parent_id in blocked_parent_ids:
570
# This entry was pruned because one of its parents became a
571
# TreeReference. If this is a directory, mark it as blocked.
572
if ie.kind == 'directory':
573
blocked_parent_ids.add(ie.file_id)
575
if ie.kind == 'directory' and self._directory_is_tree_reference(path):
576
# This InventoryDirectory needs to be a TreeReference
577
ie = inventory.TreeReference(ie.file_id, ie.name, ie.parent_id)
578
blocked_parent_ids.add(ie.file_id)
581
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
582
"""See Tree.iter_entries_by_dir()"""
583
# The only trick here is that if we supports_tree_reference then we
584
# need to detect if a directory becomes a tree-reference.
585
iterator = super(WorkingTree, self).iter_entries_by_dir(
586
specific_file_ids=specific_file_ids,
587
yield_parents=yield_parents)
588
if not self.supports_tree_reference():
591
return self._check_for_tree_references(iterator)
575
593
def get_file_size(self, file_id):
576
594
"""See Tree.get_file_size"""
577
595
# XXX: this returns the on-disk size; it should probably return the
845
863
self.add(path, file_id, 'directory')
848
def get_symlink_target(self, file_id):
849
abspath = self.id2abspath(file_id)
866
def get_symlink_target(self, file_id, path=None):
868
abspath = self.abspath(path)
870
abspath = self.id2abspath(file_id)
850
871
target = osutils.readlink(abspath)
1004
1025
new_revision_info = self.branch.last_revision_info()
1005
1026
if new_revision_info != old_revision_info:
1006
1027
repository = self.branch.repository
1028
if repository._format.fast_deltas:
1029
parent_ids = self.get_parent_ids()
1031
basis_id = parent_ids[0]
1032
basis_tree = repository.revision_tree(basis_id)
1007
1033
basis_tree.lock_read()
1009
1035
new_basis_tree = self.branch.basis_tree()
1228
1254
if _mod_revision.is_null(new_revision):
1229
1255
self.branch.set_last_revision_info(0, new_revision)
1257
_mod_revision.check_not_reserved_id(new_revision)
1232
1259
self.branch.generate_revision_history(new_revision)
1233
1260
except errors.NoSuchRevision:
1751
1778
self.set_conflicts(un_resolved)
1752
1779
return un_resolved, resolved
1755
def _check(self, references):
1756
"""Check the tree for consistency.
1758
:param references: A dict with keys matching the items returned by
1759
self._get_check_refs(), and values from looking those keys up in
1762
tree_basis = self.basis_tree()
1763
tree_basis.lock_read()
1765
repo_basis = references[('trees', self.last_revision())]
1766
if len(list(repo_basis.iter_changes(tree_basis))) > 0:
1767
raise errors.BzrCheckError(
1768
"Mismatched basis inventory content.")
1773
1781
def _validate(self):
1774
1782
"""Validate internal structures.
1785
1792
def check_state(self):
1786
1793
"""Check that the working state is/isn't valid."""
1787
check_refs = self._get_check_refs()
1789
for ref in check_refs:
1792
refs[ref] = self.branch.repository.revision_tree(value)
1794
raise NotImplementedError(self.check_state)
1795
1796
def reset_state(self, revision_ids=None):
1796
1797
"""Reset the state of the working tree.
2088
2089
__contains__ = has_id
2090
# should be deprecated - this is slow and in any case treating them as a
2091
# container is (we now know) bad style -- mbp 20070302
2092
## @deprecated_method(zero_fifteen)
2091
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
2093
2092
def __iter__(self):
2094
2093
"""Iterate through file_ids for this tree.
2107
2106
if self._change_last_revision(new_revision):
2108
2107
self._cache_basis_inventory(new_revision)
2109
def _get_check_refs(self):
2110
"""Return the references needed to perform a check of this tree.
2112
The default implementation returns no refs, and is only suitable for
2113
trees that have no local caching and can commit on ghosts at any time.
2115
:seealso: bzrlib.check for details about check_refs.
2120
def _check(self, references):
2121
"""Check the tree for consistency.
2123
:param references: A dict with keys matching the items returned by
2124
self._get_check_refs(), and values from looking those keys up in
2127
tree_basis = self.basis_tree()
2128
tree_basis.lock_read()
2130
repo_basis = references[('trees', self.last_revision())]
2131
if len(list(repo_basis.iter_changes(tree_basis))) > 0:
2132
raise errors.BzrCheckError(
2133
"Mismatched basis inventory content.")
2139
def check_state(self):
2140
"""Check that the working state is/isn't valid."""
2141
check_refs = self._get_check_refs()
2143
for ref in check_refs:
2146
refs[ref] = self.branch.repository.revision_tree(value)
2110
2149
@needs_tree_write_lock
2111
2150
def reset_state(self, revision_ids=None):
2112
2151
"""Reset the state of the working tree.