Rev 2373: (broken) lock and unlock the DirState object when locking and unlocking the Tree itself in http://bzr.arbash-meinel.com/branches/bzr/experimental/dirstate

John Arbash Meinel john at arbash-meinel.com
Fri Feb 23 02:16:50 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/experimental/dirstate

------------------------------------------------------------
revno: 2373
revision-id: john at arbash-meinel.com-20070223021644-7hp2p2f3rjvkmx4s
parent: john at arbash-meinel.com-20070223011122-eyncc8ny0hchp0qc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate
timestamp: Thu 2007-02-22 20:16:44 -0600
message:
  (broken) lock and unlock the DirState object when locking and unlocking the Tree itself
  broken because we have timing issues with parent ids disappearing on us
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/tests/test_workingtree.py testworkingtree.py-20051004024258-b88d0fe8f101d468
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-02-23 01:11:22 +0000
+++ b/bzrlib/dirstate.py	2007-02-23 02:16:44 +0000
@@ -1462,7 +1462,7 @@
         if self._lock_token is not None:
             raise errors.LockContention(self._lock_token)
         self._lock_token = lock.ReadLock(self._filename)
-        self._state_file = open(self._filename, 'rb')
+        self._state_file = self._lock_token.f
         self._wipe_state()
 
     def lock_write(self):
@@ -1470,14 +1470,14 @@
         if self._lock_token is not None:
             raise errors.LockContention(self._lock_token)
         self._lock_token = lock.WriteLock(self._filename)
-        self._state_file = open(self._filename, 'rb+')
+        self._state_file = self._lock_token.f
         self._wipe_state()
 
     def unlock(self):
         """Drop any locks held on the dirstate"""
         if self._lock_token is None:
             raise errors.LockNotHeld(self)
-        self._state_file.close()
+        self._state_file = None
         self._lock_token.unlock()
         self._lock_token = None
 

=== modified file 'bzrlib/tests/test_workingtree.py'
--- a/bzrlib/tests/test_workingtree.py	2007-02-16 06:57:53 +0000
+++ b/bzrlib/tests/test_workingtree.py	2007-02-23 02:16:44 +0000
@@ -249,7 +249,11 @@
         # correctly and last-revision file becomes present.
         # manually make a dirstate toc check the format is as desired.
         state = dirstate.DirState.on_file(t.local_abspath('dirstate'))
-        self.assertEqual([], state.get_parent_ids())
+        state.lock_read()
+        try:
+            self.assertEqual([], state.get_parent_ids())
+        finally:
+            state.unlock()
 
     def test_uses_lockdir(self):
         """WorkingTreeFormat4 uses its own LockDir:

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-02-22 23:26:15 +0000
+++ b/bzrlib/workingtree_4.py	2007-02-23 02:16:44 +0000
@@ -378,6 +378,24 @@
         else:
             return None
 
+    def lock_read(self):
+        super(WorkingTree4, self).lock_read()
+        if self._dirstate is None:
+            self.current_dirstate()
+            self._dirstate.lock_read()
+
+    def lock_tree_write(self):
+        super(WorkingTree4, self).lock_tree_write()
+        if self._dirstate is None:
+            self.current_dirstate()
+            self._dirstate.lock_write()
+
+    def lock_write(self):
+        super(WorkingTree4, self).lock_write()
+        if self._dirstate is None:
+            self.current_dirstate()
+            self._dirstate.lock_write()
+
     @needs_tree_write_lock
     def move(self, from_paths, to_dir=None, after=False, **kwargs):
         """See WorkingTree.move()."""
@@ -790,6 +808,8 @@
             if self._control_files._lock_mode == 'w':
                 if self._dirty:
                     self.flush()
+            if self._dirstate is not None:
+                self._dirstate.unlock()
             self._dirstate = None
             self._inventory = None
         # reverse order of locking.
@@ -925,7 +945,8 @@
         if revision_id is None:
             revision_id = branch.last_revision()
         local_path = transport.local_abspath('dirstate')
-        dirstate.DirState.initialize(local_path)
+        state = dirstate.DirState.initialize(local_path)
+        state.unlock()
         wt = WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
                          branch,
                          _format=self,
@@ -969,6 +990,7 @@
         self._repository = repository
         self._inventory = None
         self._locked = 0
+        self._dirstate_locked = False
 
     def annotate_iter(self, file_id):
         """See Tree.annotate_iter"""
@@ -1145,6 +1167,9 @@
         """Lock the tree for a set of operations."""
         if not self._locked:
             self._repository.lock_read()
+            if self._dirstate._lock_token is None:
+                self._dirstate.lock_read()
+                self._dirstate_locked = True
         self._locked += 1
 
     @needs_read_lock
@@ -1162,7 +1187,10 @@
         self._locked -=1
         if not self._locked:
             self._inventory = None
-            self._locked = False
+            self._locked = 0
+            if self._dirstate_locked:
+                self._dirstate.unlock()
+                self._dirstate_locked = False
             self._repository.unlock()
 
     def walkdirs(self, prefix=""):



More information about the bazaar-commits mailing list