Rev 5332: Implement the --conf option for break-lock as per lifeless suggestion. in file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Jun 30 15:19:58 BST 2010


At file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/

------------------------------------------------------------
revno: 5332
revision-id: v.ladeuil+lp at free.fr-20100630141957-su7t86t2fo1c1n1u
parent: v.ladeuil+lp at free.fr-20100630103044-r1tcs4e3y1neyllz
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 525571-lock-bazaar-conf-files
timestamp: Wed 2010-06-30 16:19:57 +0200
message:
  Implement the --conf option for break-lock as per lifeless suggestion.
  
  * bzrlib/errors.py:
  (NoLockDir): Useless, deleted.
  
  * bzrlib/config.py:
  (LockableConfig.unlock): NoLockDir is useless, break_lock()
  silenty succeeds if the directory doesn't exist.
  
  * bzrlib/tests/blackbox/test_break_lock.py:
  Tweak the tests.
  
  * bzrlib/builtins.py:
  (cmd_break_lock): Fix docstring, add a --conf option to deal with
  config files.
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2010-06-30 10:28:55 +0000
+++ b/bzrlib/builtins.py	2010-06-30 14:19:57 +0000
@@ -4831,7 +4831,9 @@
 
 class cmd_break_lock(Command):
     __doc__ = """Break a dead lock.
-    This could be on a repository, branch, working directory or config file.
+
+    This command breaks a lock on a repository, branch, working directory or
+    config file.
 
     CAUTION: Locks should only be broken when you are sure that the process
     holding the lock has been stopped.
@@ -4842,19 +4844,22 @@
     :Examples:
         bzr break-lock
         bzr break-lock bzr+ssh://example.com/bzr/foo
-        bzr break-lock ~/.bazaar
+        bzr break-lock --conf ~/.bazaar
     """
+
     takes_args = ['location?']
+    takes_options = [
+        Option('conf',
+               help='LOCATION is a directory containing configuration files.'),
+        ]
 
-    def run(self, location=None, show=False):
+    def run(self, location=None, conf=False):
         if location is None:
             location = u'.'
-        try:
-            # Config locks first
-            conf = config.LockableConfig(lambda : location)
-            conf.break_lock()
-        except errors.NoLockDir:
-            # Then wt, branch, repo, etc.
+        if conf:
+            c = config.LockableConfig(lambda : location)
+            c.break_lock()
+        else:
             control, relpath = bzrdir.BzrDir.open_containing(location)
             try:
                 control.break_lock()

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-06-30 10:30:44 +0000
+++ b/bzrlib/config.py	2010-06-30 14:19:57 +0000
@@ -532,8 +532,6 @@
         self._lock.unlock()
 
     def break_lock(self):
-        if not self.transport.has(self.lock_name):
-            raise errors.NoLockDir(self.dir)
         if self._lock is None:
             self._lock = lockdir.LockDir(self.transport, self.lock_name)
         self._lock.break_lock()

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2010-06-29 15:36:54 +0000
+++ b/bzrlib/errors.py	2010-06-30 14:19:57 +0000
@@ -1083,16 +1083,6 @@
         self.lock = lock
 
 
-class NoLockDir(LockError):
-
-    _fmt = "No lock directory (hence no lock) in: %(path)s"
-
-    internal_error = False
-
-    def __init__(self, path):
-        self.path = path
-
-
 class TokenLockingNotSupported(LockError):
 
     _fmt = "The object %(obj)s does not support token specifying a token when locking."

=== modified file 'bzrlib/tests/blackbox/test_break_lock.py'
--- a/bzrlib/tests/blackbox/test_break_lock.py	2010-06-29 15:36:54 +0000
+++ b/bzrlib/tests/blackbox/test_break_lock.py	2010-06-30 14:19:57 +0000
@@ -24,6 +24,7 @@
     config,
     errors,
     lockdir,
+    osutils,
     tests,
     )
 
@@ -105,11 +106,22 @@
 
 class TestConfigBreakLock(tests.TestCaseWithTransport):
 
-    def test_break_lock(self):
+    def create_pending_lock(self):
         def config_file_name():
             return './my.conf'
         self.build_tree_contents([(config_file_name(), '[DEFAULT]\none=1\n')])
-        c1 = config.LockableConfig(config_file_name)
-        c1.lock_write()
-        self.run_bzr('break-lock %s' % config_file_name(), stdin="y\n")
-        self.assertRaises(errors.LockBroken, c1.unlock)
+        conf = config.LockableConfig(config_file_name)
+        conf.lock_write()
+        return conf
+
+    def test_create_pending_lock(self):
+        conf = self.create_pending_lock()
+        self.addCleanup(conf.unlock)
+        self.assertTrue(conf._lock.is_held)
+
+    def test_break_lock(self):
+        conf = self.create_pending_lock()
+        self.run_bzr('break-lock --conf %s'
+                     % osutils.dirname(conf._get_filename()),
+                     stdin="y\n")
+        self.assertRaises(errors.LockBroken, conf.unlock)



More information about the bazaar-commits mailing list