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
742
740
@needs_tree_write_lock
743
741
def set_merge_modified(self, modified_hashes):
745
for file_id, hash in modified_hashes.iteritems():
746
yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
748
self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
742
"""Set the merge modified hashes."""
743
raise NotImplementedError(self.set_merge_modified)
750
745
def _sha_from_stat(self, path, stat_result):
751
746
"""Get a sha digest from the tree's stat cache.
760
def _put_rio(self, filename, stanzas, header):
761
self._must_be_locked()
762
my_file = _mod_rio.rio_file(stanzas, header)
763
self._transport.put_file(filename, my_file,
764
mode=self.bzrdir._get_file_mode())
766
755
@needs_write_lock # because merge pulls data into the branch.
767
756
def merge_from_branch(self, branch, to_revision=None, from_revision=None,
768
757
merge_type=None, force=False):
1148
1137
return _mod_revision.ensure_null(self.branch.last_revision())
1150
1139
def is_locked(self):
1151
return self._control_files.is_locked()
1153
def _must_be_locked(self):
1154
if not self.is_locked():
1155
raise errors.ObjectNotLocked(self)
1140
"""Check if this tree is locked."""
1141
raise NotImplementedError(self.is_locked)
1157
1143
def lock_read(self):
1158
1144
"""Lock the tree for reading.
1162
1148
:return: A bzrlib.lock.LogicalLockResult.
1164
if not self.is_locked():
1166
self.branch.lock_read()
1168
self._control_files.lock_read()
1169
return LogicalLockResult(self.unlock)
1171
self.branch.unlock()
1150
raise NotImplementedError(self.lock_read)
1174
1152
def lock_tree_write(self):
1175
1153
"""See MutableTree.lock_tree_write, and WorkingTree.unlock.
1177
1155
:return: A bzrlib.lock.LogicalLockResult.
1179
if not self.is_locked():
1181
self.branch.lock_read()
1183
self._control_files.lock_write()
1184
return LogicalLockResult(self.unlock)
1186
self.branch.unlock()
1157
raise NotImplementedError(self.lock_tree_write)
1189
1159
def lock_write(self):
1190
1160
"""See MutableTree.lock_write, and WorkingTree.unlock.
1192
1162
:return: A bzrlib.lock.LogicalLockResult.
1194
if not self.is_locked():
1196
self.branch.lock_write()
1198
self._control_files.lock_write()
1199
return LogicalLockResult(self.unlock)
1201
self.branch.unlock()
1164
raise NotImplementedError(self.lock_write)
1204
1166
def get_physical_lock_status(self):
1205
return self._control_files.get_physical_lock_status()
1207
def _reset_data(self):
1208
"""Reset transient data that cannot be revalidated."""
1209
raise NotImplementedError(self._reset_data)
1167
raise NotImplementedError(self.get_physical_lock_status)
1211
1169
def set_last_revision(self, new_revision):
1212
1170
"""Change the last revision in the working tree."""
1788
1746
:param branch: A branch to override probing for the branch.
1790
1748
super(InventoryWorkingTree, self).__init__(basedir=basedir,
1791
branch=branch, _control_files=_control_files, _internal=_internal,
1792
_format=_format, _bzrdir=_bzrdir)
1749
branch=branch, _transport=_control_files._transport,
1750
_internal=_internal, _format=_format, _bzrdir=_bzrdir)
1752
self._control_files = _control_files
1794
1753
self._detect_case_handling()
1796
1755
if _inventory is None:
1835
1794
def _deserialize(selt, in_file):
1836
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()
1838
1865
@needs_tree_write_lock
1839
1866
def _write_inventory(self, inv):
1840
1867
"""Write inventory as the current inventory."""
2259
2286
for key, line in annotator.annotate_flat(this_key)]
2260
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)
2262
2303
@needs_read_lock
2263
2304
def merge_modified(self):
2264
2305
"""Return a dictionary of files modified by a merge.