Merge lp:~piastucki/bzr-xmloutput/missing-locks into lp:bzr-xmloutput

Proposed by Piotr Piastucki
Status: Needs review
Proposed branch: lp:~piastucki/bzr-xmloutput/missing-locks
Merge into: lp:bzr-xmloutput
Diff against target: 86 lines (+38/-30)
2 files modified
shelvexml.py (+15/-11)
tagsxml.py (+23/-19)
To merge this branch: bzr merge lp:~piastucki/bzr-xmloutput/missing-locks
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Pending
Review via email: mp+183692@code.launchpad.net

Description of the change

I have recently noticed that some locks are actually missing in xmltags and xmlshelvelist commands. It does not seem to break anything, but to improve the code I suggest the following changes.

To post a comment you must log in.

Unmerged revisions

175. By Piotr Piastucki

Add missing locks

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'shelvexml.py'
2--- shelvexml.py 2013-02-27 13:38:55 +0000
3+++ shelvexml.py 2013-09-03 15:25:13 +0000
4@@ -29,16 +29,20 @@
5
6 def list_xml(outf, directory='.'):
7 tree = WorkingTree.open_containing(directory)[0]
8- manager = tree.get_shelf_manager()
9- shelves = manager.active_shelves()
10- outf.write('<?xml version="1.0" encoding="%s"?>' % \
11- bzrlib.osutils.get_user_encoding())
12- outf.write('<shelves>')
13- for shelf_id in reversed(shelves):
14- message = manager.get_metadata(shelf_id).get('message')
15- if message is None:
16- message = ''
17- outf.write('<shelf><id>%s</id><message>%s</message></shelf>' % (shelf_id, _escape_cdata(message)))
18- outf.write('</shelves>')
19+ tree.lock_read()
20+ try:
21+ manager = tree.get_shelf_manager()
22+ shelves = manager.active_shelves()
23+ outf.write('<?xml version="1.0" encoding="%s"?>' % \
24+ bzrlib.osutils.get_user_encoding())
25+ outf.write('<shelves>')
26+ for shelf_id in reversed(shelves):
27+ message = manager.get_metadata(shelf_id).get('message')
28+ if message is None:
29+ message = ''
30+ outf.write('<shelf><id>%s</id><message>%s</message></shelf>' % (shelf_id, _escape_cdata(message)))
31+ outf.write('</shelves>')
32+ finally:
33+ tree.unlock()
34
35
36
37=== modified file 'tagsxml.py'
38--- tagsxml.py 2013-02-22 21:13:54 +0000
39+++ tagsxml.py 2013-09-03 15:25:13 +0000
40@@ -37,25 +37,29 @@
41 bzrlib.osutils.get_user_encoding())
42 outf.write('<tags>')
43 if tags:
44- if sort is None:
45- sort = tag_sort_methods.get()
46- sort(branch, tags)
47- if not show_ids:
48- # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
49- for index, (tag, revid) in enumerate(tags):
50- try:
51- revno = branch.revision_id_to_dotted_revno(revid)
52- if isinstance(revno, tuple):
53- revno = '.'.join(map(str, revno))
54- except (errors.NoSuchRevision,
55- errors.GhostRevisionsHaveNoRevno,
56- errors.UnsupportedOperation):
57- # Bad tag data/merges can lead to tagged revisions
58- # which are not in this branch. Fail gracefully ...
59- revno = '?'
60- tags[index] = (tag, revno)
61- for tag, revspec in tags:
62- outf.write('<tag><name>%s</name><revision>%s</revision></tag>' % (_escape_cdata(tag), _escape_cdata(revspec)))
63+ branch.lock_read()
64+ try:
65+ if sort is None:
66+ sort = tag_sort_methods.get()
67+ sort(branch, tags)
68+ if not show_ids:
69+ # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
70+ for index, (tag, revid) in enumerate(tags):
71+ try:
72+ revno = branch.revision_id_to_dotted_revno(revid)
73+ if isinstance(revno, tuple):
74+ revno = '.'.join(map(str, revno))
75+ except (errors.NoSuchRevision,
76+ errors.GhostRevisionsHaveNoRevno,
77+ errors.UnsupportedOperation):
78+ # Bad tag data/merges can lead to tagged revisions
79+ # which are not in this branch. Fail gracefully ...
80+ revno = '?'
81+ tags[index] = (tag, revno)
82+ for tag, revspec in tags:
83+ outf.write('<tag><name>%s</name><revision>%s</revision></tag>' % (_escape_cdata(tag), _escape_cdata(revspec)))
84+ finally:
85+ branch.unlock()
86 outf.write('</tags>')
87
88

Subscribers

People subscribed via source and target branches

to all changes: