Rev 4742: (andrew, in file:///home/pqm/archives/thelove/bzr/2.0/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Mar 24 05:31:07 GMT 2010


At file:///home/pqm/archives/thelove/bzr/2.0/

------------------------------------------------------------
revno: 4742 [merge]
revision-id: pqm at pqm.ubuntu.com-20100324053106-t0oiyu04p7u11h96
parent: pqm at pqm.ubuntu.com-20100323082840-6zsr0oeufode5g30
parent: danny at dannyvanheumen.nl-20100317235810-6og1nt8zfxpi7nbi
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.0
timestamp: Wed 2010-03-24 05:31:06 +0000
message:
  (andrew,
   for Danny van Heumen) 'bzr revert' no longer takes a branch lock (#498409)
added:
  bzrlib/tests/commands/test_revert.py test_revert.py-20100309150314-zqzie40mnu7vcfhg-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/lock.py                 lock.py-20050527050856-ec090bb51bc03349
  bzrlib/tests/commands/__init__.py __init__.py-20070520095518-ecfl8531fxgjeycj-1
  doc/developers/testing.txt     testing.txt-20080812140359-i70zzh6v2z7grqex-1
=== modified file 'NEWS'
--- a/NEWS	2010-03-23 06:55:16 +0000
+++ b/NEWS	2010-03-24 05:31:06 +0000
@@ -54,6 +54,10 @@
   errors.
   (Inada Naoki, #524560)
 
+* ``bzr revert`` now only takes write lock on working tree, instead of on 
+  both working tree and branch.
+  (Danny van Heumen, #498409)
+
 Documentation
 *************
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-12-16 22:26:56 +0000
+++ b/bzrlib/builtins.py	2010-03-08 13:12:55 +0000
@@ -4045,7 +4045,7 @@
     def run(self, revision=None, no_backup=False, file_list=None,
             forget_merges=None):
         tree, file_list = tree_files(file_list)
-        tree.lock_write()
+        tree.lock_tree_write()
         try:
             if forget_merges:
                 tree.set_parent_ids(tree.get_parent_ids()[:1])

=== modified file 'bzrlib/lock.py'
--- a/bzrlib/lock.py	2009-07-31 16:51:48 +0000
+++ b/bzrlib/lock.py	2010-03-17 00:06:21 +0000
@@ -84,7 +84,7 @@
         return self.lock_url == other.lock_url and self.details == other.details
 
     def __repr__(self):
-        return '%s(%s%s)' % (self.__class__.__name__,
+        return '%s(%s, %s)' % (self.__class__.__name__,
                              self.lock_url, self.details)
 
 

=== modified file 'bzrlib/tests/commands/__init__.py'
--- a/bzrlib/tests/commands/__init__.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/commands/__init__.py	2010-03-09 15:05:03 +0000
@@ -41,6 +41,7 @@
         'bzrlib.tests.commands.test_pull',
         'bzrlib.tests.commands.test_push',
         'bzrlib.tests.commands.test_update',
+        'bzrlib.tests.commands.test_revert',
         ]
     # add the tests for the sub modules
     suite.addTests(loader.loadTestsFromModuleNames(testmod_names))

=== added file 'bzrlib/tests/commands/test_revert.py'
--- a/bzrlib/tests/commands/test_revert.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/commands/test_revert.py	2010-03-17 09:38:08 +0000
@@ -0,0 +1,61 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+import os
+from bzrlib import (
+    branch,
+    builtins,
+    errors,
+    lock,
+    )
+from bzrlib.tests import (
+    transport_util,
+    TestCaseInTempDir,
+    )
+
+
+class TestRevert(TestCaseInTempDir):
+
+    def setUp(self):
+        super(TestRevert, self).setUp()
+
+    def test_revert_tree_write_lock_and_branch_read_lock(self):
+
+        # install lock hooks to find out about cmd_revert's locking actions
+        locks_acquired = []
+        locks_released = []
+        lock.Lock.hooks.install_named_hook('lock_acquired',
+            locks_acquired.append, None)
+        lock.Lock.hooks.install_named_hook('lock_released',
+            locks_released.append, None)
+
+        # execute the revert command (There is nothing to actually revert,
+        # but locks are acquired either way.)
+        revert = builtins.cmd_revert()
+        revert.run()
+
+        # make sure that only one lock is acquired and released.
+        self.assertLength(1, locks_acquired)
+        self.assertLength(1, locks_released)
+
+        # make sure that the nonces are the same, since otherwise
+        # this would not be the same lock.
+        self.assertEqual(locks_acquired[0].details, locks_released[0].details)
+
+        # make sure that the locks are checkout locks.
+        self.assertEndsWith(locks_acquired[0].lock_url, "/checkout/lock")
+        self.assertEndsWith(locks_released[0].lock_url, "/checkout/lock")
+

=== modified file 'doc/developers/testing.txt'
--- a/doc/developers/testing.txt	2009-09-09 02:21:47 +0000
+++ b/doc/developers/testing.txt	2010-03-17 00:28:46 +0000
@@ -201,6 +201,43 @@
 .. ~~~~~~~~~~~~
 
 
+Testing locking behaviour
+-------------------------
+
+In order to test the locking behaviour of commands, it is possible to install
+a hook that is called when a write lock is: acquired, released or broken.
+(Read locks also exist, they cannot be discovered in this way.)
+
+A hook can be installed by calling bzrlib.lock.Lock.hooks.install_named_hook.
+The three valid hooks are: `lock_acquired`, `lock_released` and `lock_broken`.
+
+Example::
+
+    locks_acquired = []
+    locks_released = []
+
+    lock.Lock.hooks.install_named_hook('lock_acquired',
+        locks_acquired.append, None)
+    lock.Lock.hooks.install_named_hook('lock_released',
+        locks_released.append, None)
+
+`locks_acquired` will now receive a LockResult instance for all locks acquired
+since the time the hook is installed.
+
+The last part of the `lock_url` allows you to identify the type of object that is locked.
+
+- BzrDir: `/branch-lock`
+- Working tree: `/checkout/lock`
+- Branch: `/branch/lock`
+- Repository: `/repository/lock`
+
+To test if a lock is a write lock on a working tree, one can do the following::
+
+    self.assertEndsWith(locks_acquired[0].lock_url, "/checkout/lock")
+
+See bzrlib/tests/commands/test_revert.py for an example of how to use this for
+testing locks.
+
 
 Skipping tests
 --------------




More information about the bazaar-commits mailing list