~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Andrew Bennetts
  • Date: 2010-05-13 16:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 5232.
  • Revision ID: andrew.bennetts@canonical.com-20100513161754-q2ak6vzjnur7f3i3
Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2788
2788
        medium = self._branch._client._medium
2789
2789
        if medium._is_remote_before((1, 14)):
2790
2790
            return self._vfs_set_option(value, name, section)
 
2791
        if isinstance(value, dict):
 
2792
            if medium._is_remote_before((2, 2)):
 
2793
                return self._vfs_set_option(value, name, section)
 
2794
            return self._set_config_option_dict(value, name, section)
 
2795
        else:
 
2796
            return self._set_config_option(value, name, section)
 
2797
 
 
2798
    def _set_config_option(self, value, name, section):
2791
2799
        try:
2792
2800
            path = self._branch._remote_path()
2793
2801
            response = self._branch._client.call('Branch.set_config_option',
2794
2802
                path, self._branch._lock_token, self._branch._repo_lock_token,
2795
2803
                value.encode('utf8'), name, section or '')
2796
2804
        except errors.UnknownSmartMethod:
 
2805
            medium = self._branch._client._medium
2797
2806
            medium._remember_remote_is_before((1, 14))
2798
2807
            return self._vfs_set_option(value, name, section)
2799
2808
        if response != ():
2800
2809
            raise errors.UnexpectedSmartServerResponse(response)
2801
2810
 
 
2811
    def _serialize_option_dict(self, option_dict):
 
2812
        utf8_dict = {}
 
2813
        for key, value in option_dict.items():
 
2814
            if isinstance(key, unicode):
 
2815
                key = key.encode('utf8')
 
2816
            if isinstance(value, unicode):
 
2817
                value = value.encode('utf8')
 
2818
            utf8_dict[key] = value
 
2819
        return bencode.bencode(utf8_dict)
 
2820
 
 
2821
    def _set_config_option_dict(self, value, name, section):
 
2822
        try:
 
2823
            path = self._branch._remote_path()
 
2824
            serialised_dict = self._serialize_option_dict(value)
 
2825
            response = self._branch._client.call(
 
2826
                'Branch.set_config_option_dict',
 
2827
                path, self._branch._lock_token, self._branch._repo_lock_token,
 
2828
                serialised_dict, name, section or '')
 
2829
        except errors.UnknownSmartMethod:
 
2830
            medium = self._branch._client._medium
 
2831
            medium._remember_remote_is_before((2, 2))
 
2832
            return self._vfs_set_option(value, name, section)
 
2833
        if response != ():
 
2834
            raise errors.UnexpectedSmartServerResponse(response)
 
2835
 
2802
2836
    def _real_object(self):
2803
2837
        self._branch._ensure_real()
2804
2838
        return self._branch._real_branch