[merge] add tests, docs for set_merge_modified; add _must_be_locked

Martin Pool mbp at sourcefrog.net
Mon Feb 26 11:26:52 GMT 2007


Martin Pool wrote:
> As the subject says.
> 
> _put_rio should always be called from inside something that holds a
> lock, so doesn't need to check or take one.  For things where the caller
> is meant to know what they're doing, and for internal methods, it seems
> better just to require the caller to take the lock.

Actually my earlier merge was wrong: is_locked can tell you about either
a read or write lock, so we need this change too.



=== modified file 'bzrlib/lockable_files.py'
--- bzrlib/lockable_files.py    2007-02-09 23:39:24 +0000
+++ bzrlib/lockable_files.py    2007-02-26 11:22:43 +0000
@@ -270,9 +270,15 @@
                 self._lock_mode = self._lock_count = None

     def is_locked(self):
-        """Return true if this LockableFiles group is locked"""
+        """Return true if this LockableFiles group is locked.
+
+        Note that this may be either a read lock or write lock.
+        """
         return self._lock_count >= 1

+    def is_write_locked(self):
+        return self._lock_mode == 'w' and self._lock_count
+
     def get_physical_lock_status(self):
         """Return physical lock status.


=== modified file 'bzrlib/workingtree.py'
--- bzrlib/workingtree.py       2007-02-26 04:40:16 +0000
+++ bzrlib/workingtree.py       2007-02-26 11:23:08 +0000
@@ -785,7 +785,7 @@
         self._put_rio('merge-hashes', iter_stanzas(),
MERGE_MODIFIED_HEADER_1)

     def _put_rio(self, filename, stanzas, header):
-        self._must_be_locked()
+        self._must_be_write_locked()
         my_file = rio_file(stanzas, header)
         self._control_files.put(filename, my_file)

@@ -1524,8 +1524,11 @@
     def is_locked(self):
         return self._control_files.is_locked()

-    def _must_be_locked(self):
-        if not self.is_locked():
+    def is_write_locked(self):
+        return self._control_files.is_write_locked()
+
+    def _must_be_write_locked(self):
+        if not self.is_write_locked():
             raise errors.ObjectNotLocked(self)

     def lock_read(self):


-- 
Martin



More information about the bazaar mailing list