Rev 6317: (jelmer) Move control-files-related code from WorkingTree to in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Nov 28 16:04:45 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6317 [merge]
revision-id: pqm at pqm.ubuntu.com-20111128160445-5ndgnqjd0vggze3d
parent: pqm at pqm.ubuntu.com-20111128151448-7n0jzgkwjlvxvao6
parent: jelmer at samba.org-20111128151859-dw4nua1xiobilw4r
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-11-28 16:04:45 +0000
message:
(jelmer) Move control-files-related code from WorkingTree to
InventoryWorkingTree. (Jelmer Vernooij)
modified:
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2011-11-08 19:09:55 +0000
+++ b/bzrlib/workingtree.py 2011-11-28 15:18:59 +0000
@@ -172,8 +172,8 @@
def __init__(self, basedir='.',
branch=DEPRECATED_PARAMETER,
- _control_files=None,
_internal=False,
+ _transport=None,
_format=None,
_bzrdir=None):
"""Construct a WorkingTree instance. This is not a public API.
@@ -192,8 +192,7 @@
else:
self._branch = self.bzrdir.open_branch()
self.basedir = realpath(basedir)
- self._control_files = _control_files
- self._transport = self._control_files._transport
+ self._transport = _transport
self._rules_searcher = None
self.views = self._make_views()
@@ -237,8 +236,7 @@
This will probe the repository for its lock as well.
"""
- self._control_files.break_lock()
- self.branch.break_lock()
+ raise NotImplementedError(self.break_lock)
def requires_rich_root(self):
return self._format.requires_rich_root
@@ -741,11 +739,8 @@
@needs_tree_write_lock
def set_merge_modified(self, modified_hashes):
- def iter_stanzas():
- for file_id, hash in modified_hashes.iteritems():
- yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
- hash=hash)
- self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
+ """Set the merge modified hashes."""
+ raise NotImplementedError(self.set_merge_modified)
def _sha_from_stat(self, path, stat_result):
"""Get a sha digest from the tree's stat cache.
@@ -757,12 +752,6 @@
"""
return None
- def _put_rio(self, filename, stanzas, header):
- self._must_be_locked()
- my_file = _mod_rio.rio_file(stanzas, header)
- self._transport.put_file(filename, my_file,
- mode=self.bzrdir._get_file_mode())
-
@needs_write_lock # because merge pulls data into the branch.
def merge_from_branch(self, branch, to_revision=None, from_revision=None,
merge_type=None, force=False):
@@ -1148,11 +1137,8 @@
return _mod_revision.ensure_null(self.branch.last_revision())
def is_locked(self):
- return self._control_files.is_locked()
-
- def _must_be_locked(self):
- if not self.is_locked():
- raise errors.ObjectNotLocked(self)
+ """Check if this tree is locked."""
+ raise NotImplementedError(self.is_locked)
def lock_read(self):
"""Lock the tree for reading.
@@ -1161,52 +1147,24 @@
:return: A bzrlib.lock.LogicalLockResult.
"""
- if not self.is_locked():
- self._reset_data()
- self.branch.lock_read()
- try:
- self._control_files.lock_read()
- return LogicalLockResult(self.unlock)
- except:
- self.branch.unlock()
- raise
+ raise NotImplementedError(self.lock_read)
def lock_tree_write(self):
"""See MutableTree.lock_tree_write, and WorkingTree.unlock.
:return: A bzrlib.lock.LogicalLockResult.
"""
- if not self.is_locked():
- self._reset_data()
- self.branch.lock_read()
- try:
- self._control_files.lock_write()
- return LogicalLockResult(self.unlock)
- except:
- self.branch.unlock()
- raise
+ raise NotImplementedError(self.lock_tree_write)
def lock_write(self):
"""See MutableTree.lock_write, and WorkingTree.unlock.
:return: A bzrlib.lock.LogicalLockResult.
"""
- if not self.is_locked():
- self._reset_data()
- self.branch.lock_write()
- try:
- self._control_files.lock_write()
- return LogicalLockResult(self.unlock)
- except:
- self.branch.unlock()
- raise
+ raise NotImplementedError(self.lock_write)
def get_physical_lock_status(self):
- return self._control_files.get_physical_lock_status()
-
- def _reset_data(self):
- """Reset transient data that cannot be revalidated."""
- raise NotImplementedError(self._reset_data)
+ raise NotImplementedError(self.get_physical_lock_status)
def set_last_revision(self, new_revision):
"""Change the last revision in the working tree."""
@@ -1788,9 +1746,10 @@
:param branch: A branch to override probing for the branch.
"""
super(InventoryWorkingTree, self).__init__(basedir=basedir,
- branch=branch, _control_files=_control_files, _internal=_internal,
- _format=_format, _bzrdir=_bzrdir)
+ branch=branch, _transport=_control_files._transport,
+ _internal=_internal, _format=_format, _bzrdir=_bzrdir)
+ self._control_files = _control_files
self._detect_case_handling()
if _inventory is None:
@@ -1835,6 +1794,74 @@
def _deserialize(selt, in_file):
return xml5.serializer_v5.read_inventory(in_file)
+ def break_lock(self):
+ """Break a lock if one is present from another instance.
+
+ Uses the ui factory to ask for confirmation if the lock may be from
+ an active process.
+
+ This will probe the repository for its lock as well.
+ """
+ self._control_files.break_lock()
+ self.branch.break_lock()
+
+ def is_locked(self):
+ return self._control_files.is_locked()
+
+ def _must_be_locked(self):
+ if not self.is_locked():
+ raise errors.ObjectNotLocked(self)
+
+ def lock_read(self):
+ """Lock the tree for reading.
+
+ This also locks the branch, and can be unlocked via self.unlock().
+
+ :return: A bzrlib.lock.LogicalLockResult.
+ """
+ if not self.is_locked():
+ self._reset_data()
+ self.branch.lock_read()
+ try:
+ self._control_files.lock_read()
+ return LogicalLockResult(self.unlock)
+ except:
+ self.branch.unlock()
+ raise
+
+ def lock_tree_write(self):
+ """See MutableTree.lock_tree_write, and WorkingTree.unlock.
+
+ :return: A bzrlib.lock.LogicalLockResult.
+ """
+ if not self.is_locked():
+ self._reset_data()
+ self.branch.lock_read()
+ try:
+ self._control_files.lock_write()
+ return LogicalLockResult(self.unlock)
+ except:
+ self.branch.unlock()
+ raise
+
+ def lock_write(self):
+ """See MutableTree.lock_write, and WorkingTree.unlock.
+
+ :return: A bzrlib.lock.LogicalLockResult.
+ """
+ if not self.is_locked():
+ self._reset_data()
+ self.branch.lock_write()
+ try:
+ self._control_files.lock_write()
+ return LogicalLockResult(self.unlock)
+ except:
+ self.branch.unlock()
+ raise
+
+ def get_physical_lock_status(self):
+ return self._control_files.get_physical_lock_status()
+
@needs_tree_write_lock
def _write_inventory(self, inv):
"""Write inventory as the current inventory."""
@@ -2259,6 +2286,20 @@
for key, line in annotator.annotate_flat(this_key)]
return annotations
+ def _put_rio(self, filename, stanzas, header):
+ self._must_be_locked()
+ my_file = _mod_rio.rio_file(stanzas, header)
+ self._transport.put_file(filename, my_file,
+ mode=self.bzrdir._get_file_mode())
+
+ @needs_tree_write_lock
+ def set_merge_modified(self, modified_hashes):
+ def iter_stanzas():
+ for file_id, hash in modified_hashes.iteritems():
+ yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
+ hash=hash)
+ self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
+
@needs_read_lock
def merge_modified(self):
"""Return a dictionary of files modified by a merge.
More information about the bazaar-commits
mailing list