Rev 5452: (mbp) Add 'break-lock --force' in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Sep 29 23:03:06 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5452 [merge]
revision-id: pqm at pqm.ubuntu.com-20100929220303-cr95h8iwtggco721
parent: pqm at pqm.ubuntu.com-20100929204319-s4pxrbqu9osgas9f
parent: john at arbash-meinel.com-20100929205618-qlldxw4ykwt5511n
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-09-29 23:03:03 +0100
message:
  (mbp) Add 'break-lock --force'
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/lockdir.py              lockdir.py-20060220222025-98258adf27fbdda3
  bzrlib/tests/blackbox/test_break_lock.py test_break_lock.py-20060303014503-a90e07d38d042d1d
=== modified file 'NEWS'
--- a/NEWS	2010-09-29 20:01:27 +0000
+++ b/NEWS	2010-09-29 22:03:03 +0000
@@ -29,6 +29,11 @@
 
 Bug Fixes
 *********
+
+* ``bzr break-lock --force`` breaks the lock without prompting.  (Before
+  using this, make sure the process holding the lock really is dead.)
+  (Martin Pool, #392315)
+
 * Skip tests that needs a bzr source tree when there isn't one. This is
   needed to succesfully run the test suite for installed versions.
   (Vincent Ladeuil, #644855).

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2010-09-24 12:53:00 +0000
+++ b/bzrlib/builtins.py	2010-09-29 20:18:37 +0000
@@ -4841,11 +4841,17 @@
     takes_options = [
         Option('config',
                help='LOCATION is the directory where the config lock is.'),
+        Option('force',
+            help='Do not ask for confirmation before breaking the lock.'),
         ]
 
-    def run(self, location=None, config=False):
+    def run(self, location=None, config=False, force=False):
         if location is None:
             location = u'.'
+        if force:
+            ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
+                None,
+                {'bzrlib.lockdir.break': True})
         if config:
             conf = _mod_config.LockableConfig(file_name=location)
             conf.break_lock()

=== modified file 'bzrlib/lockdir.py'
--- a/bzrlib/lockdir.py	2010-09-15 10:40:51 +0000
+++ b/bzrlib/lockdir.py	2010-09-29 20:18:37 +0000
@@ -347,6 +347,8 @@
         This is a UI centric function: it uses the bzrlib.ui.ui_factory to
         prompt for input if a lock is detected and there is any doubt about
         it possibly being still active.
+
+        :returns: LockResult for the broken lock.
         """
         self._check_not_locked()
         try:
@@ -361,7 +363,9 @@
             if bzrlib.ui.ui_factory.confirm_action(
                 "Break %(lock_info)s", 'bzrlib.lockdir.break', 
                 dict(lock_info=lock_info)):
-                self.force_break(holder_info)
+                result = self.force_break(holder_info)
+                bzrlib.ui.ui_factory.show_message(
+                    "Broke lock %s" % result.lock_url)
 
     def force_break(self, dead_holder_info):
         """Release a lock held by another process.
@@ -378,6 +382,8 @@
         After the lock is broken it will not be held by any process.
         It is possible that another process may sneak in and take the
         lock before the breaking process acquires it.
+
+        :returns: LockResult for the broken lock.
         """
         if not isinstance(dead_holder_info, dict):
             raise ValueError("dead_holder_info: %r" % dead_holder_info)
@@ -403,6 +409,7 @@
                                  current_info.get('nonce'))
         for hook in self.hooks['lock_broken']:
             hook(result)
+        return result
 
     def force_break_corrupt(self, corrupt_info_lines):
         """Release a lock that has been corrupted.

=== modified file 'bzrlib/tests/blackbox/test_break_lock.py'
--- a/bzrlib/tests/blackbox/test_break_lock.py	2010-08-23 16:34:38 +0000
+++ b/bzrlib/tests/blackbox/test_break_lock.py	2010-09-14 07:19:22 +0000
@@ -16,18 +16,18 @@
 
 """Tests for lock-breaking user interface"""
 
-import os
-
-import bzrlib
 from bzrlib import (
     branch,
     bzrdir,
     config,
     errors,
-    lockdir,
     osutils,
     tests,
     )
+from bzrlib.tests.script import (
+    ScriptRunner,
+    run_script,
+    )
 
 
 class TestBreakLock(tests.TestCaseWithTransport):
@@ -70,6 +70,16 @@
         # shouldn't fail and should not produce error output
         self.assertEqual('', err)
 
+    def test_break_lock_no_interaction(self):
+        """With --force, the user isn't asked for confirmation"""
+        self.master_branch.lock_write()
+        run_script(self, """
+        $ bzr break-lock --force master-repo/master-branch
+        Broke lock ...master-branch/.bzr/...
+        """)
+        # lock should now be dead
+        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
+
     def test_break_lock_everything_locked(self):
         ### if everything is locked, we should be able to unlock the lot.
         # however, we dont test breaking the working tree because we




More information about the bazaar-commits mailing list