Merge lp:~dasch/bzr-gtk/lock-ui into lp:bzr-gtk/gtk2

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 455
Merged at revision: 712
Proposed branch: lp:~dasch/bzr-gtk/lock-ui
Merge into: lp:bzr-gtk/gtk2
Diff against target: 105 lines (+70/-10)
2 files modified
branchview/treeview.py (+8/-10)
lock.py (+62/-0)
To merge this branch: bzr merge lp:~dasch/bzr-gtk/lock-ui
Reviewer Review Type Date Requested Status
Martin Pool (community) Approve
Review via email: mp+50258@code.launchpad.net

Description of the change

Daniel's lock handling branch.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

Looks reasonable.

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

I might like to see the lock code on a decorator object rather than plain functions, but since this is old code just getting it in is reasonable.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'branchview/treeview.py'
2--- branchview/treeview.py 2009-06-15 14:02:08 +0000
3+++ branchview/treeview.py 2011-02-18 00:28:53 +0000
4@@ -21,6 +21,7 @@
5 from graphcell import CellRendererGraph
6 from treemodel import TreeModel
7 from bzrlib.revision import NULL_REVISION
8+from bzrlib.plugins.gtk import lock
9
10
11 class TreeView(gtk.VBox):
12@@ -225,19 +226,16 @@
13 def add_tag(self, tag, revid=None):
14 if revid is None: revid = self.revision.revision_id
15
16- try:
17- self.branch.unlock()
18-
19+ if lock.release(self.branch):
20 try:
21- self.branch.lock_write()
22+ lock.acquire(self.branch, lock.WRITE)
23 self.model.add_tag(tag, revid)
24 finally:
25- self.branch.unlock()
26-
27- finally:
28- self.branch.lock_read()
29-
30- self.emit('tag-added', tag, revid)
31+ lock.release(self.branch)
32+
33+ lock.acquire(self.branch, lock.READ)
34+
35+ self.emit('tag-added', tag, revid)
36
37 def refresh(self):
38 gobject.idle_add(self.populate, self.get_revision())
39
40=== added file 'lock.py'
41--- lock.py 1970-01-01 00:00:00 +0000
42+++ lock.py 2011-02-18 00:28:53 +0000
43@@ -0,0 +1,62 @@
44+
45+import gtk
46+
47+
48+RESPONSE_BREAK = 0
49+RESPONSE_CANCEL = 1
50+
51+READ = 0
52+WRITE = 1
53+
54+
55+def acquire(branch, lock_type):
56+ if branch.get_physical_lock_status():
57+ dialog = LockDialog(branch)
58+ response = dialog.run()
59+ dialog.destroy()
60+
61+ if response == RESPONSE_BREAK:
62+ branch.break_lock()
63+ else:
64+ return False
65+
66+ if lock_type == READ:
67+ branch.lock_read()
68+ elif lock_type == WRITE:
69+ branch.lock_write()
70+
71+ return True
72+
73+
74+def release(branch):
75+ if branch.get_physical_lock_status():
76+ dialog = LockDialog(branch)
77+ response = dialog.run()
78+ dialog.destroy()
79+
80+ if response == RESPONSE_BREAK:
81+ branch.break_lock()
82+ elif response == RESPONSE_CANCEL:
83+ return False
84+
85+ branch.unlock()
86+
87+ return True
88+
89+
90+class LockDialog(gtk.Dialog):
91+
92+ def __init__(self, branch):
93+ gtk.Dialog.__init__(self)
94+
95+ self.branch = branch
96+
97+ self.set_title('Lock Not Held')
98+
99+ self.vbox.add(gtk.Label('This operation cannot be completed as ' \
100+ 'another application has locked the branch.'))
101+
102+ self.add_button('Break Lock', RESPONSE_BREAK)
103+ self.add_button(gtk.STOCK_CANCEL, RESPONSE_CANCEL)
104+
105+ self.vbox.show_all()

Subscribers

People subscribed via source and target branches

to status/vote changes: