/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 14:27:19 UTC
  • mto: This revision was merged to the branch mainline in revision 5837.
  • Revision ID: john@arbash-meinel.com-20110420142719-advs1k5vztqzbrgv
Fix bug #767177. Be more agressive with file.close() calls.

Our test suite gets a number of thread leaks and failures because it happens to get async
SFTPFile.close() calls. (if an SFTPFile closes due to __del__ it is done as an async request,
while if you call SFTPFile.close() it is done as a synchronous request.)
We have a couple other cases, probably. Namely SFTPTransport.get() also does an async
prefetch of the content, so if you don't .read() you'll also leak threads that think they
are doing work that you want.

The biggest change here, though, is using a try/finally in a generator, which is not 
python2.4 compatible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Server-side branch related request implmentations."""
18
18
 
19
19
 
20
 
from bzrlib import errors
 
20
from bzrlib import (
 
21
    bencode,
 
22
    errors,
 
23
    )
21
24
from bzrlib.bzrdir import BzrDir
22
25
from bzrlib.smart.request import (
23
26
    FailedSmartServerResponse,
139
142
            self.branch.unlock()
140
143
 
141
144
 
 
145
class SmartServerBranchHeadsToFetch(SmartServerBranchRequest):
 
146
 
 
147
    def do_with_branch(self, branch):
 
148
        """Return the heads-to-fetch for a Branch as two bencoded lists.
 
149
        
 
150
        See Branch.heads_to_fetch.
 
151
 
 
152
        New in 2.4.
 
153
        """
 
154
        must_fetch, if_present_fetch = branch.heads_to_fetch()
 
155
        return SuccessfulSmartServerResponse(
 
156
            (list(must_fetch), list(if_present_fetch)))
 
157
 
 
158
 
142
159
class SmartServerBranchRequestGetStackedOnURL(SmartServerBranchRequest):
143
160
 
144
161
    def do_with_branch(self, branch):
194
211
        return SuccessfulSmartServerResponse(())
195
212
 
196
213
 
 
214
class SmartServerBranchRequestSetConfigOptionDict(SmartServerLockedBranchRequest):
 
215
    """Set an option in the branch configuration.
 
216
    
 
217
    New in 2.2.
 
218
    """
 
219
 
 
220
    def do_with_locked_branch(self, branch, value_dict, name, section):
 
221
        utf8_dict = bencode.bdecode(value_dict)
 
222
        value_dict = {}
 
223
        for key, value in utf8_dict.items():
 
224
            value_dict[key.decode('utf8')] = value.decode('utf8')
 
225
        if not section:
 
226
            section = None
 
227
        branch._get_config().set_option(value_dict, name, section)
 
228
        return SuccessfulSmartServerResponse(())
 
229
 
 
230
 
197
231
class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
198
232
 
199
233
    def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):
292
326
        if repo_token == '':
293
327
            repo_token = None
294
328
        try:
295
 
            repo_token = branch.repository.lock_write(token=repo_token)
 
329
            repo_token = branch.repository.lock_write(
 
330
                token=repo_token).repository_token
296
331
            try:
297
 
                branch_token = branch.lock_write(token=branch_token)
 
332
                branch_token = branch.lock_write(
 
333
                    token=branch_token).branch_token
298
334
            finally:
299
335
                # this leaves the repository with 1 lock
300
336
                branch.repository.unlock()