Merge lp:~gagern/trac-bzr/bug484324 into lp:trac-bzr

Proposed by Martin von Gagern
Status: Merged
Merged at revision: not available
Proposed branch: lp:~gagern/trac-bzr/bug484324
Merge into: lp:trac-bzr
Diff against target: 64 lines (+27/-9)
1 file modified
tracbzr/backend.py (+27/-9)
To merge this branch: bzr merge lp:~gagern/trac-bzr/bug484324
Reviewer Review Type Date Requested Status
Trac-bzr-team Pending
Review via email: mp+14984@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tracbzr/backend.py'
2--- tracbzr/backend.py 2009-06-03 21:18:09 +0000
3+++ tracbzr/backend.py 2009-11-18 09:20:26 +0000
4@@ -131,6 +131,31 @@
5 repo.unlock()
6
7
8+class LockedBranches(object):
9+
10+ """Keep track of locks and ensure they get unlocked one day.
11+ This deals with the fact that Trac doesn't always call the repository
12+ close method, and that a __del__ method in the repository itself causes
13+ trouble as described in https://bugs.launchpad.net/trac-bzr/+bug/484324"""
14+
15+ def __init__(self):
16+ self._locked_branches = []
17+
18+ def __del__(self):
19+ # XXX Eeeeeww. Unfortunately for us trac does not actually call the
20+ # close method of BzrRepository. So we do this. Quite silly, since
21+ # bzr does the same thing (printing a warning...)
22+ self.unlock()
23+
24+ def append(self, branch):
25+ self._locked_branches.append(branch)
26+
27+ def unlock(self):
28+ for branch in self._locked_branches:
29+ branch.unlock()
30+ self._locked_branches = []
31+
32+
33 class BzrRepository(versioncontrol.Repository):
34
35 """Present a bzr branch as a trac repository."""
36@@ -139,7 +164,7 @@
37 versioncontrol.Repository.__init__(self, location, None, log)
38 self.root_transport = transport.get_transport(location)
39 self._tree_cache = {}
40- self._locked_branches = []
41+ self._locked_branches = LockedBranches()
42 self._branch_cache = {}
43 self._history = None
44 self._previous = None
45@@ -263,18 +288,11 @@
46 # Unsupported format.
47 raise versioncontrol.NoSuchChangeset(rev)
48
49- def __del__(self):
50- # XXX Eeeeeww. Unfortunately for us trac does not actually call the
51- # close method. So we do this. Quite silly, since bzr does the same
52- # thing (printing a warning...)
53- self.close()
54-
55 # Trac api methods.
56
57 def close(self):
58 """Release our branches. Trac does not *have* to call this!"""
59- for branch in self._locked_branches:
60- branch.unlock()
61+ self._locked_branches.unlock()
62
63 def get_branch(self, location):
64 if location in self._branch_cache:

Subscribers

People subscribed via source and target branches