Rev 3333: Polish on lock hooks to be easier to use. in http://people.ubuntu.com/~robertc/baz2.0/physicallock.hooks

Robert Collins robertc at robertcollins.net
Fri Apr 4 04:53:41 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/physicallock.hooks

------------------------------------------------------------
revno: 3333
revision-id: robertc at robertcollins.net-20080404035337-ldligjwfp2bzqi47
parent: robertc at robertcollins.net-20080404021333-13wfvylrgmvcp3gz
committer: Robert Collins <robertc at robertcollins.net>
branch nick: PhysicalLock.hooks
timestamp: Fri 2008-04-04 14:53:37 +1100
message:
  Polish on lock hooks to be easier to use.
modified:
  bzrlib/lock.py                 lock.py-20050527050856-ec090bb51bc03349
  bzrlib/lockdir.py              lockdir.py-20060220222025-98258adf27fbdda3
  bzrlib/tests/test_help.py      test_help.py-20070419045354-6q6rq15j9e2n5fna-1
  bzrlib/tests/test_lockdir.py   test_lockdir.py-20060220222025-33d4221569a3d600
=== modified file 'bzrlib/lock.py'
--- a/bzrlib/lock.py	2008-04-04 02:13:33 +0000
+++ b/bzrlib/lock.py	2008-04-04 03:53:37 +0000
@@ -69,13 +69,13 @@
 
 class LockResult(object):
 
-    def __init__(self, lock, details=None):
+    def __init__(self, lock_url, details=None):
         """Create a lock result for lock with optional details about the lock."""
-        self.lock = lock
+        self.lock_url = lock_url
         self.details = details
 
     def __eq__(self, other):
-        return self.lock == other.lock and self.details == other.details
+        return self.lock_url == other.lock_url and self.details == other.details
 
 
 class _OSLock(object):

=== modified file 'bzrlib/lockdir.py'
--- a/bzrlib/lockdir.py	2008-04-04 02:13:33 +0000
+++ b/bzrlib/lockdir.py	2008-04-04 03:53:37 +0000
@@ -325,7 +325,8 @@
                 self.transport.delete_tree(tmpname)
             self._trace("... unlock succeeded after %dms",
                     (time.time() - start_time) * 1000)
-            result = lock.LockResult(self, old_nonce)
+            result = lock.LockResult(self.transport.abspath(self.path),
+                old_nonce)
             for hook in lock.hooks['released']:
                 hook(result)
 
@@ -461,7 +462,8 @@
         if self._fake_read_lock:
             raise LockContention(self)
         result = self._attempt_lock()
-        hook_result = lock.LockResult(self, result)
+        hook_result = lock.LockResult(self.transport.abspath(self.path),
+                self.nonce)
         for hook in lock.hooks['acquired']:
             hook(hook_result)
         return result

=== modified file 'bzrlib/tests/test_help.py'
--- a/bzrlib/tests/test_help.py	2007-12-10 03:31:11 +0000
+++ b/bzrlib/tests/test_help.py	2008-04-04 03:53:37 +0000
@@ -205,8 +205,8 @@
         # Pick a known topic stored in an external file
         topic = help_topics.RegisteredTopic('hooks')
         self.assertStartsWith(topic.get_help_text(),
-            'Hooks\n'
-            '=====\n'
+            'Branch Hooks\n'
+            '============\n'
             '\n')
 
     def test_get_help_topic(self):

=== modified file 'bzrlib/tests/test_lockdir.py'
--- a/bzrlib/tests/test_lockdir.py	2008-04-04 02:13:33 +0000
+++ b/bzrlib/tests/test_lockdir.py	2008-04-04 03:53:37 +0000
@@ -667,9 +667,10 @@
         ld.create()
         self.assertEqual([], self._calls)
         result = ld.attempt_lock()
-        self.assertEqual([lock.LockResult(ld, result)], self._calls)
+        lock_path = ld.transport.abspath(ld.path)
+        self.assertEqual([lock.LockResult(lock_path, result)], self._calls)
         ld.unlock()
-        self.assertEqual([lock.LockResult(ld, result)], self._calls)
+        self.assertEqual([lock.LockResult(lock_path, result)], self._calls)
 
     def test_PhysicalLock_dot_acquired_fail(self):
         # the PhysicalLock.acquired hook does not fire on failure.
@@ -697,7 +698,8 @@
         result = ld.attempt_lock()
         self.assertEqual([], self._calls)
         ld.unlock()
-        self.assertEqual([lock.LockResult(ld, result)], self._calls)
+        lock_path = ld.transport.abspath(ld.path)
+        self.assertEqual([lock.LockResult(lock_path, result)], self._calls)
 
     def test_PhysicalLock_dot_released_fail(self):
         # the PhysicalLock.released hook does not fire on failure.




More information about the bazaar-commits mailing list