/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/message.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import collections
18
20
from cStringIO import StringIO
19
21
 
303
305
            mutter('   result:   %r', self.args)
304
306
        if self.status == 'E':
305
307
            self._wait_for_response_end()
306
 
            _translate_error(self.args)
 
308
            _raise_smart_server_error(self.args)
307
309
        return tuple(self.args)
308
310
 
309
311
    def read_body_bytes(self, count=-1):
335
337
                yield bytes_part
336
338
            self._read_more()
337
339
        if self._body_stream_status == 'E':
338
 
            _translate_error(self._body_error_args)
 
340
            _raise_smart_server_error(self._body_error_args)
339
341
 
340
342
    def cancel_read_body(self):
341
343
        self._wait_for_response_end()
342
344
 
343
345
 
344
 
def _translate_error(error_tuple):
345
 
    # Many exceptions need some state from the requestor to be properly
346
 
    # translated (e.g. they need a branch object).  So this only translates a
347
 
    # few errors, and the rest are turned into a generic ErrorFromSmartServer.
348
 
    error_name = error_tuple[0]
349
 
    error_args = error_tuple[1:]
350
 
    if error_name == 'UnknownMethod':
351
 
        raise errors.UnknownSmartMethod(error_args[0])
352
 
    if error_name == 'LockContention':
353
 
        raise errors.LockContention('(remote lock)')
354
 
    elif error_name == 'LockFailed':
355
 
        raise errors.LockFailed(*error_args[:2])
356
 
    elif error_name == 'FileExists':
357
 
        raise errors.FileExists(error_args[0])
358
 
    elif error_name == 'NoSuchFile':
359
 
        raise errors.NoSuchFile(error_args[0])
360
 
    else:
361
 
        raise errors.ErrorFromSmartServer(error_tuple)
 
346
def _raise_smart_server_error(error_tuple):
 
347
    """Raise exception based on tuple received from smart server
 
348
 
 
349
    Specific error translation is handled by bzrlib.remote._translate_error
 
350
    """
 
351
    if error_tuple[0] == 'UnknownMethod':
 
352
        raise errors.UnknownSmartMethod(error_tuple[1])
 
353
    raise errors.ErrorFromSmartServer(error_tuple)