Merge lp:~vila/bzr/1020007-branchformat4-lock into lp:bzr

Proposed by Vincent Ladeuil on 2012-07-02
Status: Merged
Approved by: Jelmer Vernooij on 2012-07-02
Approved revision: 6535
Merged at revision: 6534
Proposed branch: lp:~vila/bzr/1020007-branchformat4-lock
Merge into: lp:bzr
Diff against target: 149 lines (+69/-11)
4 files modified
bzrlib/branch.py (+1/-11)
bzrlib/plugins/weave_fmt/branch.py (+56/-0)
bzrlib/tests/per_branch/test_config.py (+8/-0)
doc/en/release-notes/bzr-2.6.txt (+4/-0)
To merge this branch: bzr merge lp:~vila/bzr/1020007-branchformat4-lock
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) 2012-07-02 Approve on 2012-07-02
Review via email: mp+113014@code.launchpad.net

Commit Message

Properly save ``branch.conf`` changes when unlocking a BzrBranch4.

Description of the Change

I ran into bug #1020007 while working on a plugin: the all-in-one format has
an issue with the way the last unlock is recognized for ``branch.conf``
saving.

This went unnoticed as no test was explicitly testing BranchFormat4.

I've added such a test and split the lock_{read_write} and unlock methods
betwenn Branch and BzrBranch4.

This makes the weave_format plugin sole responsible for the specific lock
strategy and leave the Branch class cleaner.

Since the bug was introduced with the bug #948339 fix, only bzr.dev needs to
be fixed.

Since BzrBranch4 is not widely (to say the least) used anymore, I doubt
anyone encounter the bug. Yet, it has the potential to break backwards
compatibility and looks like a good cleanup to have (and completes the work
to isolate weaves into their decicated plugin).

To post a comment you must log in.
Jelmer Vernooij (jelmer) :
review: Approve
Vincent Ladeuil (vila) wrote :

sent to pqm by email

John A Meinel (jameinel) wrote :

sent to pqm by email

Vincent Ladeuil (vila) wrote :

sent to pqm by email

John A Meinel (jameinel) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/branch.py'
2--- bzrlib/branch.py 2012-06-26 15:33:56 +0000
3+++ bzrlib/branch.py 2012-07-02 10:51:23 +0000
4@@ -2437,9 +2437,6 @@
5 """
6 if not self.is_locked():
7 self._note_lock('w')
8- # All-in-one needs to always unlock/lock.
9- repo_control = getattr(self.repository, 'control_files', None)
10- if self.control_files == repo_control or not self.is_locked():
11 self.repository._warn_if_deprecated(self)
12 self.repository.lock_write()
13 took_lock = True
14@@ -2460,9 +2457,6 @@
15 """
16 if not self.is_locked():
17 self._note_lock('r')
18- # All-in-one needs to always unlock/lock.
19- repo_control = getattr(self.repository, 'control_files', None)
20- if self.control_files == repo_control or not self.is_locked():
21 self.repository._warn_if_deprecated(self)
22 self.repository.lock_read()
23 took_lock = True
24@@ -2483,12 +2477,8 @@
25 try:
26 self.control_files.unlock()
27 finally:
28- # All-in-one needs to always unlock/lock.
29- repo_control = getattr(self.repository, 'control_files', None)
30- if (self.control_files == repo_control or
31- not self.control_files.is_locked()):
32- self.repository.unlock()
33 if not self.control_files.is_locked():
34+ self.repository.unlock()
35 # we just released the lock
36 self._clear_cached_state()
37
38
39=== modified file 'bzrlib/plugins/weave_fmt/branch.py'
40--- bzrlib/plugins/weave_fmt/branch.py 2012-01-07 01:06:26 +0000
41+++ bzrlib/plugins/weave_fmt/branch.py 2012-07-02 10:51:23 +0000
42@@ -23,10 +23,17 @@
43 lockable_files,
44 )
45
46+from bzrlib.decorators import (
47+ needs_read_lock,
48+ needs_write_lock,
49+ only_raises,
50+ )
51+from bzrlib.lock import LogicalLockResult
52 from bzrlib.trace import mutter
53
54 from bzrlib.branch import (
55 BranchFormat,
56+ BranchWriteLockResult,
57 FullHistoryBzrBranch,
58 )
59
60@@ -34,6 +41,55 @@
61 class BzrBranch4(FullHistoryBzrBranch):
62 """Branch format 4."""
63
64+ def lock_write(self, token=None):
65+ """Lock the branch for write operations.
66+
67+ :param token: A token to permit reacquiring a previously held and
68+ preserved lock.
69+ :return: A BranchWriteLockResult.
70+ """
71+ if not self.is_locked():
72+ self._note_lock('w')
73+ # All-in-one needs to always unlock/lock.
74+ self.repository._warn_if_deprecated(self)
75+ self.repository.lock_write()
76+ try:
77+ return BranchWriteLockResult(self.unlock,
78+ self.control_files.lock_write(token=token))
79+ except:
80+ self.repository.unlock()
81+ raise
82+
83+ def lock_read(self):
84+ """Lock the branch for read operations.
85+
86+ :return: A bzrlib.lock.LogicalLockResult.
87+ """
88+ if not self.is_locked():
89+ self._note_lock('r')
90+ # All-in-one needs to always unlock/lock.
91+ self.repository._warn_if_deprecated(self)
92+ self.repository.lock_read()
93+ try:
94+ self.control_files.lock_read()
95+ return LogicalLockResult(self.unlock)
96+ except:
97+ self.repository.unlock()
98+ raise
99+
100+ @only_raises(errors.LockNotHeld, errors.LockBroken)
101+ def unlock(self):
102+ if self.control_files._lock_count == 2 and self.conf_store is not None:
103+ self.conf_store.save_changes()
104+ try:
105+ self.control_files.unlock()
106+ finally:
107+ # All-in-one needs to always unlock/lock.
108+ self.repository.unlock()
109+ if not self.control_files.is_locked():
110+ # we just released the lock
111+ self._clear_cached_state()
112+
113 def _get_checkout_format(self, lightweight=False):
114 """Return the most suitable metadir for a checkout of this branch.
115 """
116
117=== modified file 'bzrlib/tests/per_branch/test_config.py'
118--- bzrlib/tests/per_branch/test_config.py 2011-02-18 11:24:21 +0000
119+++ bzrlib/tests/per_branch/test_config.py 2012-07-02 10:51:23 +0000
120@@ -35,4 +35,12 @@
121 config.set_user_option('name', value_dict.copy())
122 self.assertEqual(value_dict, config.get_user_option('name'))
123
124+ def test_set_submit_branch(self):
125+ # Make sure setting a config option persists on disk
126+ b = self.make_branch('.')
127+ b.set_submit_branch('foo')
128+ # Refresh the branch
129+ b = branch.Branch.open('.')
130+ self.assertEquals('foo', b.get_submit_branch())
131+
132
133
134=== modified file 'doc/en/release-notes/bzr-2.6.txt'
135--- doc/en/release-notes/bzr-2.6.txt 2012-06-26 15:40:44 +0000
136+++ doc/en/release-notes/bzr-2.6.txt 2012-07-02 10:51:23 +0000
137@@ -41,9 +41,13 @@
138 * "bzr missing" now shows tag names when displaying revision information.
139 (#559072, Neil Martinsen-Burrell)
140
141+* Fix ``branch.conf`` saving when unlocking the branch for BranchFormat4.
142+ (Vincent Ladeuil, #1020007)
143+
144 * Implement ``ResponseFile.readline`` and ``ReponseFile.tell``,
145 fixing some clones over HTTP. (Jelmer Vernooij, #963769)
146
147+
148 Documentation
149 *************
150