Rev 2907: (robertc) Add Repository.is_write_locked convenience method. (Robert Collins) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Oct 15 07:55:36 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2907
revision-id: pqm at pqm.ubuntu.com-20071015065534-fgmb1lo51bo69biw
parent: pqm at pqm.ubuntu.com-20071012085726-lyq36i8bo7ew28ba
parent: robertc at robertcollins.net-20071015052329-z5458xq9q2kq72mv
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2007-10-15 07:55:34 +0100
message:
(robertc) Add Repository.is_write_locked convenience method. (Robert Collins)
added:
bzrlib/tests/repository_implementations/test_is_write_locked.py test_is_write_locked-20071012063748-vk062lmu683qgbc3-1
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
bzrlib/tests/repository_implementations/test_break_lock.py test_break_lock.py-20060504111704-ee09a107f9f42e43
------------------------------------------------------------
revno: 2904.1.2
merged: robertc at robertcollins.net-20071015052329-z5458xq9q2kq72mv
parent: robertc at robertcollins.net-20071015022537-37pczn78yq27f8yg
parent: pqm at pqm.ubuntu.com-20071012085726-lyq36i8bo7ew28ba
committer: Robert Collins <robertc at robertcollins.net>
branch nick: locks
timestamp: Mon 2007-10-15 15:23:29 +1000
message:
Merge bzr.dev
------------------------------------------------------------
revno: 2904.1.1
merged: robertc at robertcollins.net-20071015022537-37pczn78yq27f8yg
parent: pqm at pqm.ubuntu.com-20071010085229-7x5al1tirr29mq0l
committer: Robert Collins <robertc at robertcollins.net>
branch nick: locks
timestamp: Mon 2007-10-15 12:25:37 +1000
message:
* New method ``bzrlib.repository.Repository.is_write_locked`` useful for
determining if a repository is write locked. (Robert Collins)
=== added file 'bzrlib/tests/repository_implementations/test_is_write_locked.py'
--- a/bzrlib/tests/repository_implementations/test_is_write_locked.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/repository_implementations/test_is_write_locked.py 2007-10-15 02:25:37 +0000
@@ -0,0 +1,38 @@
+# Copyright (C) 2007 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for Repository.is_write_locked()."""
+
+from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
+
+
+class TestIsWriteLocked(TestCaseWithRepository):
+
+ def test_not_locked(self):
+ repo = self.make_repository('.')
+ self.assertFalse(repo.is_write_locked())
+
+ def test_read_locked(self):
+ repo = self.make_repository('.')
+ repo.lock_read()
+ self.addCleanup(repo.unlock)
+ self.assertFalse(repo.is_write_locked())
+
+ def test_write_locked(self):
+ repo = self.make_repository('.')
+ repo.lock_write()
+ self.addCleanup(repo.unlock)
+ self.assertTrue(repo.is_write_locked())
=== modified file 'NEWS'
--- a/NEWS 2007-10-12 08:18:54 +0000
+++ b/NEWS 2007-10-15 05:23:29 +0000
@@ -204,6 +204,9 @@
duplication from user input, when a user mentions both a path and an item
contained within that path. (Robert Collins)
+ * New method ``bzrlib.repository.Repository.is_write_locked`` useful for
+ determining if a repository is write locked. (Robert Collins)
+
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
tuple containing the key information about a path for commit processing
to complete. (Robert Collins)
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2007-10-12 08:18:54 +0000
+++ b/bzrlib/remote.py 2007-10-15 05:23:29 +0000
@@ -401,6 +401,9 @@
assert response[0] in ('yes', 'no'), 'unexpected response code %s' % (response,)
return response[0] == 'yes'
+ def is_write_locked(self):
+ return self._lock_mode == 'w'
+
def lock_read(self):
# wrong eventually - want a local lock cache context
if not self._lock_mode:
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2007-10-12 08:18:54 +0000
+++ b/bzrlib/repository.py 2007-10-15 05:23:29 +0000
@@ -658,6 +658,10 @@
def is_locked(self):
return self.control_files.is_locked()
+ def is_write_locked(self):
+ """Return True if this object is write locked."""
+ return self.is_locked() and self.control_files._lock_mode == 'w'
+
def lock_write(self, token=None):
"""Lock this repository for writing.
@@ -915,7 +919,7 @@
:return: None.
"""
- if not self.is_locked() or self.control_files._lock_mode != 'w':
+ if not self.is_write_locked():
raise errors.NotWriteLocked(self)
if self._write_group:
raise errors.BzrError('already in a write group')
=== modified file 'bzrlib/tests/repository_implementations/__init__.py'
--- a/bzrlib/tests/repository_implementations/__init__.py 2007-10-12 01:52:29 +0000
+++ b/bzrlib/tests/repository_implementations/__init__.py 2007-10-15 05:23:29 +0000
@@ -524,7 +524,6 @@
def test_suite():
-
registry = repository.format_registry
all_formats = [registry.get(k) for k in registry.keys()]
all_formats.extend(weaverepo._legacy_formats)
@@ -547,7 +546,6 @@
format_scenarios = (disk_format_adapter.scenarios +
remote_repo_adapter.scenarios)
-
prefix = 'bzrlib.tests.repository_implementations.'
test_repository_modules = [
'test_break_lock',
@@ -557,6 +555,7 @@
'test_fetch',
'test_fileid_involved',
'test_has_same_location',
+ 'test_is_write_locked',
'test_iter_reverse_revision_history',
'test_pack',
'test_reconcile',
=== modified file 'bzrlib/tests/repository_implementations/test_break_lock.py'
--- a/bzrlib/tests/repository_implementations/test_break_lock.py 2006-10-11 23:08:27 +0000
+++ b/bzrlib/tests/repository_implementations/test_break_lock.py 2007-10-15 02:25:37 +0000
@@ -52,10 +52,11 @@
def test_locked(self):
# break_lock when locked should
self.repo.lock_write()
- try:
- self.unused_repo.break_lock()
- except NotImplementedError:
- # repository does not support break_lock
+ self.assertEqual(self.repo.get_physical_lock_status(),
+ self.unused_repo.get_physical_lock_status())
+ if not self.unused_repo.get_physical_lock_status():
+ # 'lock_write' has not taken a physical mutex out.
self.repo.unlock()
return
+ self.unused_repo.break_lock()
self.assertRaises(errors.LockBroken, self.repo.unlock)
More information about the bazaar-commits
mailing list