173
173
def __init__(self, basedir='.',
174
174
branch=DEPRECATED_PARAMETER,
179
179
"""Construct a WorkingTree instance. This is not a public API.
193
193
self._branch = self.bzrdir.open_branch()
194
194
self.basedir = realpath(basedir)
195
self._control_files = _control_files
196
self._transport = self._control_files._transport
195
self._transport = _transport
197
196
self._rules_searcher = None
198
197
self.views = self._make_views()
238
237
This will probe the repository for its lock as well.
240
self._control_files.break_lock()
241
self.branch.break_lock()
239
raise NotImplementedError(self.break_lock)
243
241
def requires_rich_root(self):
244
242
return self._format.requires_rich_root
522
520
# TODO now merge from tree.last_revision to revision (to preserve
523
521
# user local changes)
524
522
merge.transform_tree(tree, self)
525
tree.set_parent_ids([revision_id])
523
if revision_id == _mod_revision.NULL_REVISION:
526
new_parents = [revision_id]
527
tree.set_parent_ids(new_parents)
527
529
def id2abspath(self, file_id):
528
530
return self.abspath(self.id2path(file_id))
738
740
@needs_tree_write_lock
739
741
def set_merge_modified(self, modified_hashes):
741
for file_id, hash in modified_hashes.iteritems():
742
yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
744
self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
742
"""Set the merge modified hashes."""
743
raise NotImplementedError(self.set_merge_modified)
746
745
def _sha_from_stat(self, path, stat_result):
747
746
"""Get a sha digest from the tree's stat cache.
756
def _put_rio(self, filename, stanzas, header):
757
self._must_be_locked()
758
my_file = _mod_rio.rio_file(stanzas, header)
759
self._transport.put_file(filename, my_file,
760
mode=self.bzrdir._get_file_mode())
762
755
@needs_write_lock # because merge pulls data into the branch.
763
756
def merge_from_branch(self, branch, to_revision=None, from_revision=None,
764
757
merge_type=None, force=False):
1004
997
show_base=show_base)
1005
998
basis_root_id = basis_tree.get_root_id()
1006
999
new_root_id = new_basis_tree.get_root_id()
1007
if basis_root_id != new_root_id:
1000
if new_root_id is not None and basis_root_id != new_root_id:
1008
1001
self.set_root_id(new_root_id)
1010
1003
basis_tree.unlock()
1011
1004
# TODO - dedup parents list with things merged by pull ?
1012
1005
# reuse the revisiontree we merged against to set the new
1014
parent_trees = [(self.branch.last_revision(), new_basis_tree)]
1008
if self.branch.last_revision() != _mod_revision.NULL_REVISION:
1009
parent_trees.append(
1010
(self.branch.last_revision(), new_basis_tree))
1015
1011
# we have to pull the merge trees out again, because
1016
1012
# merge_inner has set the ids. - this corner is not yet
1017
1013
# layered well enough to prevent double handling.
1141
1137
return _mod_revision.ensure_null(self.branch.last_revision())
1143
1139
def is_locked(self):
1144
return self._control_files.is_locked()
1146
def _must_be_locked(self):
1147
if not self.is_locked():
1148
raise errors.ObjectNotLocked(self)
1140
"""Check if this tree is locked."""
1141
raise NotImplementedError(self.is_locked)
1150
1143
def lock_read(self):
1151
1144
"""Lock the tree for reading.
1155
1148
:return: A bzrlib.lock.LogicalLockResult.
1157
if not self.is_locked():
1159
self.branch.lock_read()
1161
self._control_files.lock_read()
1162
return LogicalLockResult(self.unlock)
1164
self.branch.unlock()
1150
raise NotImplementedError(self.lock_read)
1167
1152
def lock_tree_write(self):
1168
1153
"""See MutableTree.lock_tree_write, and WorkingTree.unlock.
1170
1155
:return: A bzrlib.lock.LogicalLockResult.
1172
if not self.is_locked():
1174
self.branch.lock_read()
1176
self._control_files.lock_write()
1177
return LogicalLockResult(self.unlock)
1179
self.branch.unlock()
1157
raise NotImplementedError(self.lock_tree_write)
1182
1159
def lock_write(self):
1183
1160
"""See MutableTree.lock_write, and WorkingTree.unlock.
1185
1162
:return: A bzrlib.lock.LogicalLockResult.
1187
if not self.is_locked():
1189
self.branch.lock_write()
1191
self._control_files.lock_write()
1192
return LogicalLockResult(self.unlock)
1194
self.branch.unlock()
1164
raise NotImplementedError(self.lock_write)
1197
1166
def get_physical_lock_status(self):
1198
return self._control_files.get_physical_lock_status()
1200
def _reset_data(self):
1201
"""Reset transient data that cannot be revalidated."""
1202
raise NotImplementedError(self._reset_data)
1167
raise NotImplementedError(self.get_physical_lock_status)
1204
1169
def set_last_revision(self, new_revision):
1205
1170
"""Change the last revision in the working tree."""
1781
1746
:param branch: A branch to override probing for the branch.
1783
1748
super(InventoryWorkingTree, self).__init__(basedir=basedir,
1784
branch=branch, _control_files=_control_files, _internal=_internal,
1785
_format=_format, _bzrdir=_bzrdir)
1749
branch=branch, _transport=_control_files._transport,
1750
_internal=_internal, _format=_format, _bzrdir=_bzrdir)
1752
self._control_files = _control_files
1787
1753
self._detect_case_handling()
1789
1755
if _inventory is None:
1828
1794
def _deserialize(selt, in_file):
1829
1795
return xml5.serializer_v5.read_inventory(in_file)
1797
def break_lock(self):
1798
"""Break a lock if one is present from another instance.
1800
Uses the ui factory to ask for confirmation if the lock may be from
1803
This will probe the repository for its lock as well.
1805
self._control_files.break_lock()
1806
self.branch.break_lock()
1808
def is_locked(self):
1809
return self._control_files.is_locked()
1811
def _must_be_locked(self):
1812
if not self.is_locked():
1813
raise errors.ObjectNotLocked(self)
1815
def lock_read(self):
1816
"""Lock the tree for reading.
1818
This also locks the branch, and can be unlocked via self.unlock().
1820
:return: A bzrlib.lock.LogicalLockResult.
1822
if not self.is_locked():
1824
self.branch.lock_read()
1826
self._control_files.lock_read()
1827
return LogicalLockResult(self.unlock)
1829
self.branch.unlock()
1832
def lock_tree_write(self):
1833
"""See MutableTree.lock_tree_write, and WorkingTree.unlock.
1835
:return: A bzrlib.lock.LogicalLockResult.
1837
if not self.is_locked():
1839
self.branch.lock_read()
1841
self._control_files.lock_write()
1842
return LogicalLockResult(self.unlock)
1844
self.branch.unlock()
1847
def lock_write(self):
1848
"""See MutableTree.lock_write, and WorkingTree.unlock.
1850
:return: A bzrlib.lock.LogicalLockResult.
1852
if not self.is_locked():
1854
self.branch.lock_write()
1856
self._control_files.lock_write()
1857
return LogicalLockResult(self.unlock)
1859
self.branch.unlock()
1862
def get_physical_lock_status(self):
1863
return self._control_files.get_physical_lock_status()
1831
1865
@needs_tree_write_lock
1832
1866
def _write_inventory(self, inv):
1833
1867
"""Write inventory as the current inventory."""
2252
2286
for key, line in annotator.annotate_flat(this_key)]
2253
2287
return annotations
2289
def _put_rio(self, filename, stanzas, header):
2290
self._must_be_locked()
2291
my_file = _mod_rio.rio_file(stanzas, header)
2292
self._transport.put_file(filename, my_file,
2293
mode=self.bzrdir._get_file_mode())
2295
@needs_tree_write_lock
2296
def set_merge_modified(self, modified_hashes):
2298
for file_id, hash in modified_hashes.iteritems():
2299
yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
2301
self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
2255
2303
@needs_read_lock
2256
2304
def merge_modified(self):
2257
2305
"""Return a dictionary of files modified by a merge.