bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
4763.2.4
by John Arbash Meinel
 merge bzr.2.1 in preparation for NEWS entry.  | 
1  | 
# Copyright (C) 2006-2010 Canonical Ltd
 | 
| 
2018.5.4
by Andrew Bennetts
 Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.  | 
2  | 
#
 | 
3  | 
# This program is free software; you can redistribute it and/or modify
 | 
|
4  | 
# it under the terms of the GNU General Public License as published by
 | 
|
5  | 
# the Free Software Foundation; either version 2 of the License, or
 | 
|
6  | 
# (at your option) any later version.
 | 
|
7  | 
#
 | 
|
8  | 
# This program is distributed in the hope that it will be useful,
 | 
|
9  | 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|
10  | 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|
11  | 
# GNU General Public License for more details.
 | 
|
12  | 
#
 | 
|
13  | 
# You should have received a copy of the GNU General Public License
 | 
|
14  | 
# along with this program; if not, write to the Free Software
 | 
|
| 
4183.7.1
by Sabin Iacob
 update FSF mailing address  | 
15  | 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 | 
| 
2018.5.4
by Andrew Bennetts
 Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.  | 
16  | 
|
| 
4160.2.14
by Andrew Bennetts
 Merge bzr.dev, improve NEWS entry and bzrlib.smart.request docs.  | 
17  | 
"""Infrastructure for server-side request handlers.
 | 
18  | 
||
19  | 
Interesting module attributes:
 | 
|
20  | 
    * The request_handlers registry maps verb names to SmartServerRequest
 | 
|
21  | 
      classes.
 | 
|
22  | 
    * The jail_info threading.local() object is used to prevent accidental
 | 
|
23  | 
      opening of BzrDirs outside of the backing transport, or any other
 | 
|
24  | 
      transports placed in jail_info.transports.  The jail_info is reset on
 | 
|
25  | 
      every call into a request handler (which can happen an arbitrary number
 | 
|
26  | 
      of times during a request).
 | 
|
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
27  | 
"""
 | 
| 
2018.5.19
by Andrew Bennetts
 Add docstrings to all the new modules, and a few other places.  | 
28  | 
|
| 
4160.2.14
by Andrew Bennetts
 Merge bzr.dev, improve NEWS entry and bzrlib.smart.request docs.  | 
29  | 
# XXX: The class names are a little confusing: the protocol will instantiate a
 | 
30  | 
# SmartServerRequestHandler, whose dispatch_command method creates an instance
 | 
|
31  | 
# of a SmartServerRequest subclass.
 | 
|
32  | 
||
33  | 
||
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
34  | 
import tempfile  | 
| 
4913.1.1
by John Arbash Meinel
 Switch to using thread.get_ident() which is available on all python versions.  | 
35  | 
import thread  | 
| 
4160.2.2
by Andrew Bennetts
 Add setup_jail and teardown_jail to SmartServerRequest.  | 
36  | 
import threading  | 
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
37  | 
|
| 
2402.1.2
by Andrew Bennetts
 Deal with review comments.  | 
38  | 
from bzrlib import (  | 
39  | 
bzrdir,  | 
|
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
40  | 
debug,  | 
| 
2402.1.2
by Andrew Bennetts
 Deal with review comments.  | 
41  | 
errors,  | 
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
42  | 
osutils,  | 
| 
2402.1.2
by Andrew Bennetts
 Deal with review comments.  | 
43  | 
registry,  | 
44  | 
revision,  | 
|
| 
4064.1.2
by Andrew Bennetts
 Refactor server-side error translation, improve tests.  | 
45  | 
trace,  | 
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
46  | 
urlutils,  | 
| 
2402.1.2
by Andrew Bennetts
 Deal with review comments.  | 
47  | 
    )
 | 
| 
3224.5.6
by Andrew Bennetts
 Don't import bzrlib.bundle in bzrlib.smart.request until it's needed.  | 
48  | 
from bzrlib.lazy_import import lazy_import  | 
49  | 
lazy_import(globals(), """  | 
|
50  | 
from bzrlib.bundle import serializer
 | 
|
51  | 
""")  | 
|
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
52  | 
|
| 
2018.5.4
by Andrew Bennetts
 Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.  | 
53  | 
|
| 
4160.2.2
by Andrew Bennetts
 Add setup_jail and teardown_jail to SmartServerRequest.  | 
54  | 
jail_info = threading.local()  | 
55  | 
jail_info.transports = None  | 
|
56  | 
||
57  | 
||
| 
4160.2.4
by Andrew Bennetts
 Use BzrDir pre_open hook to jail request code from accessing transports other than the backing transport.  | 
58  | 
def _install_hook():  | 
59  | 
bzrdir.BzrDir.hooks.install_named_hook(  | 
|
60  | 
'pre_open', _pre_open_hook, 'checking server jail')  | 
|
61  | 
||
62  | 
||
63  | 
def _pre_open_hook(transport):  | 
|
| 
4205.2.1
by Andrew Bennetts
 Fix BzrDir.open in non-main (and non-server-request) thread when bzrlib.smart.request's _pre_open_hook is installed.  | 
64  | 
allowed_transports = getattr(jail_info, 'transports', None)  | 
| 
4160.2.4
by Andrew Bennetts
 Use BzrDir pre_open hook to jail request code from accessing transports other than the backing transport.  | 
65  | 
if allowed_transports is None:  | 
66  | 
        return
 | 
|
67  | 
abspath = transport.base  | 
|
68  | 
for allowed_transport in allowed_transports:  | 
|
69  | 
try:  | 
|
70  | 
allowed_transport.relpath(abspath)  | 
|
71  | 
except errors.PathNotChild:  | 
|
72  | 
            continue
 | 
|
73  | 
else:  | 
|
74  | 
            return
 | 
|
| 
4294.2.8
by Robert Collins
 Reduce round trips pushing new branches substantially.  | 
75  | 
raise errors.JailBreak(abspath)  | 
| 
4160.2.4
by Andrew Bennetts
 Use BzrDir pre_open hook to jail request code from accessing transports other than the backing transport.  | 
76  | 
|
77  | 
||
78  | 
_install_hook()  | 
|
79  | 
||
80  | 
||
| 
2018.5.4
by Andrew Bennetts
 Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.  | 
81  | 
class SmartServerRequest(object):  | 
| 
2692.1.10
by Andrew Bennetts
 More docstring polish  | 
82  | 
"""Base class for request handlers.  | 
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
83  | 
|
| 
2692.1.10
by Andrew Bennetts
 More docstring polish  | 
84  | 
    To define a new request, subclass this class and override the `do` method
 | 
85  | 
    (and if appropriate, `do_body` as well).  Request implementors should take
 | 
|
86  | 
    care to call `translate_client_path` and `transport_from_client_path` as
 | 
|
87  | 
    appropriate when dealing with paths received from the client.
 | 
|
88  | 
    """
 | 
|
| 
3195.3.2
by Andrew Bennetts
 Checkpoint first rough cut of SmartServerRequestProtocolThree, this implementation reuses the _StatefulDecoder class. Plus some attempts to start tidying the smart protocol tests.  | 
89  | 
    # XXX: rename this class to BaseSmartServerRequestHandler ?  A request
 | 
90  | 
    # *handler* is a different concept to the request.
 | 
|
| 
2018.5.4
by Andrew Bennetts
 Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.  | 
91  | 
|
| 
4760.1.1
by Andrew Bennetts
 Add optional jail_root argument to SmartServerRequest and friends, and use it in the WSGI glue. Allows opening branches in shared repos via bzr+http (assuming the repo should be accessible).  | 
92  | 
def __init__(self, backing_transport, root_client_path='/', jail_root=None):  | 
| 
2402.1.2
by Andrew Bennetts
 Deal with review comments.  | 
93  | 
"""Constructor.  | 
94  | 
||
95  | 
        :param backing_transport: the base transport to be used when performing
 | 
|
96  | 
            this request.
 | 
|
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
97  | 
        :param root_client_path: the client path that maps to the root of
 | 
| 
2692.1.9
by Andrew Bennetts
 Docstrings for translate_client_path and transport_from_client_path.  | 
98  | 
            backing_transport.  This is used to interpret relpaths received
 | 
99  | 
            from the client.  Clients will not be able to refer to paths above
 | 
|
| 
2692.1.16
by Andrew Bennetts
 Improve comments.  | 
100  | 
            this root.  If root_client_path is None, then no translation will
 | 
101  | 
            be performed on client paths.  Default is '/'.
 | 
|
| 
4760.1.1
by Andrew Bennetts
 Add optional jail_root argument to SmartServerRequest and friends, and use it in the WSGI glue. Allows opening branches in shared repos via bzr+http (assuming the repo should be accessible).  | 
102  | 
        :param jail_root: if specified, the root of the BzrDir.open jail to use
 | 
103  | 
            instead of backing_transport.
 | 
|
| 
2402.1.2
by Andrew Bennetts
 Deal with review comments.  | 
104  | 
        """
 | 
| 
2018.5.4
by Andrew Bennetts
 Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.  | 
105  | 
self._backing_transport = backing_transport  | 
| 
4760.1.1
by Andrew Bennetts
 Add optional jail_root argument to SmartServerRequest and friends, and use it in the WSGI glue. Allows opening branches in shared repos via bzr+http (assuming the repo should be accessible).  | 
106  | 
if jail_root is None:  | 
107  | 
jail_root = backing_transport  | 
|
108  | 
self._jail_root = jail_root  | 
|
| 
2692.1.14
by Andrew Bennetts
 All WSGI tests passing, and manual testing works too.  | 
109  | 
if root_client_path is not None:  | 
110  | 
if not root_client_path.startswith('/'):  | 
|
111  | 
root_client_path = '/' + root_client_path  | 
|
112  | 
if not root_client_path.endswith('/'):  | 
|
113  | 
root_client_path += '/'  | 
|
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
114  | 
self._root_client_path = root_client_path  | 
| 
3842.3.19
by Andrew Bennetts
 Tweaks suggested by review.  | 
115  | 
self._body_chunks = []  | 
| 
2018.5.5
by Andrew Bennetts
 Pass body_bytes directly to SmartServerRequest.do_body  | 
116  | 
|
| 
2018.5.24
by Andrew Bennetts
 Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)  | 
117  | 
def _check_enabled(self):  | 
118  | 
"""Raises DisabledMethod if this method is disabled."""  | 
|
119  | 
        pass
 | 
|
120  | 
||
| 
2018.5.19
by Andrew Bennetts
 Add docstrings to all the new modules, and a few other places.  | 
121  | 
def do(self, *args):  | 
| 
2018.5.24
by Andrew Bennetts
 Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)  | 
122  | 
"""Mandatory extension point for SmartServerRequest subclasses.  | 
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
123  | 
|
| 
2018.5.24
by Andrew Bennetts
 Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)  | 
124  | 
        Subclasses must implement this.
 | 
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
125  | 
|
| 
2018.5.19
by Andrew Bennetts
 Add docstrings to all the new modules, and a few other places.  | 
126  | 
        This should return a SmartServerResponse if this command expects to
 | 
127  | 
        receive no body.
 | 
|
128  | 
        """
 | 
|
| 
2018.5.5
by Andrew Bennetts
 Pass body_bytes directly to SmartServerRequest.do_body  | 
129  | 
raise NotImplementedError(self.do)  | 
130  | 
||
| 
2018.5.24
by Andrew Bennetts
 Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)  | 
131  | 
def execute(self, *args):  | 
132  | 
"""Public entry point to execute this request.  | 
|
133  | 
||
134  | 
        It will return a SmartServerResponse if the command does not expect a
 | 
|
135  | 
        body.
 | 
|
136  | 
||
137  | 
        :param *args: the arguments of the request.
 | 
|
138  | 
        """
 | 
|
139  | 
self._check_enabled()  | 
|
140  | 
return self.do(*args)  | 
|
141  | 
||
| 
2018.5.5
by Andrew Bennetts
 Pass body_bytes directly to SmartServerRequest.do_body  | 
142  | 
def do_body(self, body_bytes):  | 
| 
2018.5.19
by Andrew Bennetts
 Add docstrings to all the new modules, and a few other places.  | 
143  | 
"""Called if the client sends a body with the request.  | 
| 
3184.1.10
by Robert Collins
 Change the smart server verb for Repository.stream_revisions_chunked to use SearchResults as the request mechanism for downloads.  | 
144  | 
|
145  | 
        The do() method is still called, and must have returned None.
 | 
|
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
146  | 
|
| 
2018.5.19
by Andrew Bennetts
 Add docstrings to all the new modules, and a few other places.  | 
147  | 
        Must return a SmartServerResponse.
 | 
148  | 
        """
 | 
|
| 
3990.3.2
by Andrew Bennetts
 Fix the do_body NotImplementedError log spam.  | 
149  | 
if body_bytes != '':  | 
| 
3990.3.3
by Andrew Bennetts
 Add a test that unexpected request bodies trigger a SmartProtocolError from request implementations.  | 
150  | 
raise errors.SmartProtocolError('Request does not expect a body')  | 
| 
2018.5.4
by Andrew Bennetts
 Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.  | 
151  | 
|
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
152  | 
def do_chunk(self, chunk_bytes):  | 
153  | 
"""Called with each body chunk if the request has a streamed body.  | 
|
154  | 
||
155  | 
        The do() method is still called, and must have returned None.
 | 
|
156  | 
        """
 | 
|
| 
3842.3.19
by Andrew Bennetts
 Tweaks suggested by review.  | 
157  | 
self._body_chunks.append(chunk_bytes)  | 
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
158  | 
|
159  | 
def do_end(self):  | 
|
160  | 
"""Called when the end of the request has been received."""  | 
|
| 
3842.3.19
by Andrew Bennetts
 Tweaks suggested by review.  | 
161  | 
body_bytes = ''.join(self._body_chunks)  | 
162  | 
self._body_chunks = None  | 
|
| 
3923.5.2
by Andrew Bennetts
 Completely delegate handling of request body chunks to the command object. The default implementation accumulates, like the existing behaviour.  | 
163  | 
return self.do_body(body_bytes)  | 
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
164  | 
|
| 
4160.2.2
by Andrew Bennetts
 Add setup_jail and teardown_jail to SmartServerRequest.  | 
165  | 
def setup_jail(self):  | 
| 
4760.1.1
by Andrew Bennetts
 Add optional jail_root argument to SmartServerRequest and friends, and use it in the WSGI glue. Allows opening branches in shared repos via bzr+http (assuming the repo should be accessible).  | 
166  | 
jail_info.transports = [self._jail_root]  | 
| 
4160.2.2
by Andrew Bennetts
 Add setup_jail and teardown_jail to SmartServerRequest.  | 
167  | 
|
168  | 
def teardown_jail(self):  | 
|
169  | 
jail_info.transports = None  | 
|
170  | 
||
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
171  | 
def translate_client_path(self, client_path):  | 
| 
2692.1.9
by Andrew Bennetts
 Docstrings for translate_client_path and transport_from_client_path.  | 
172  | 
"""Translate a path received from a network client into a local  | 
173  | 
        relpath.
 | 
|
174  | 
||
175  | 
        All paths received from the client *must* be translated.
 | 
|
176  | 
||
| 
2692.1.14
by Andrew Bennetts
 All WSGI tests passing, and manual testing works too.  | 
177  | 
        :param client_path: the path from the client.
 | 
| 
2692.1.9
by Andrew Bennetts
 Docstrings for translate_client_path and transport_from_client_path.  | 
178  | 
        :returns: a relpath that may be used with self._backing_transport
 | 
| 
2692.1.14
by Andrew Bennetts
 All WSGI tests passing, and manual testing works too.  | 
179  | 
            (unlike the untranslated client_path, which must not be used with
 | 
180  | 
            the backing transport).
 | 
|
| 
2692.1.9
by Andrew Bennetts
 Docstrings for translate_client_path and transport_from_client_path.  | 
181  | 
        """
 | 
| 
2692.1.14
by Andrew Bennetts
 All WSGI tests passing, and manual testing works too.  | 
182  | 
if self._root_client_path is None:  | 
183  | 
            # no translation necessary!
 | 
|
184  | 
return client_path  | 
|
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
185  | 
if not client_path.startswith('/'):  | 
186  | 
client_path = '/' + client_path  | 
|
| 
4294.2.1
by Robert Collins
 Move directory checking for bzr push options into Branch.create_clone_on_transport.  | 
187  | 
if client_path + '/' == self._root_client_path:  | 
188  | 
return '.'  | 
|
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
189  | 
if client_path.startswith(self._root_client_path):  | 
190  | 
path = client_path[len(self._root_client_path):]  | 
|
191  | 
relpath = urlutils.joinpath('/', path)  | 
|
| 
3376.2.4
by Martin Pool
 Remove every assert statement from bzrlib!  | 
192  | 
if not relpath.startswith('/'):  | 
193  | 
raise ValueError(relpath)  | 
|
| 
4760.2.1
by Michael Hudson
 very simple fix  | 
194  | 
return urlutils.escape('.' + relpath)  | 
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
195  | 
else:  | 
196  | 
raise errors.PathNotChild(client_path, self._root_client_path)  | 
|
197  | 
||
198  | 
def transport_from_client_path(self, client_path):  | 
|
| 
2692.1.9
by Andrew Bennetts
 Docstrings for translate_client_path and transport_from_client_path.  | 
199  | 
"""Get a backing transport corresponding to the location referred to by  | 
200  | 
        a network client.
 | 
|
201  | 
||
202  | 
        :seealso: translate_client_path
 | 
|
203  | 
        :returns: a transport cloned from self._backing_transport
 | 
|
204  | 
        """
 | 
|
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
205  | 
relpath = self.translate_client_path(client_path)  | 
| 
2692.1.16
by Andrew Bennetts
 Improve comments.  | 
206  | 
return self._backing_transport.clone(relpath)  | 
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
207  | 
|
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
208  | 
|
| 
2018.5.16
by Andrew Bennetts
 Move SmartServerResponse to smart/request.py, untangling more import dependencies.  | 
209  | 
class SmartServerResponse(object):  | 
| 
2432.4.5
by Robert Collins
 Make using SuccessfulSmartServerResponse and FailedSmartServerResponse mandatory rather than optional in smart server logic.  | 
210  | 
"""A response to a client request.  | 
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
211  | 
|
| 
2432.4.5
by Robert Collins
 Make using SuccessfulSmartServerResponse and FailedSmartServerResponse mandatory rather than optional in smart server logic.  | 
212  | 
    This base class should not be used. Instead use
 | 
213  | 
    SuccessfulSmartServerResponse and FailedSmartServerResponse as appropriate.
 | 
|
214  | 
    """
 | 
|
| 
2018.5.16
by Andrew Bennetts
 Move SmartServerResponse to smart/request.py, untangling more import dependencies.  | 
215  | 
|
| 
2748.4.2
by Andrew Bennetts
 Add protocol (version two) support for streaming bodies (using chunking) in responses.  | 
216  | 
def __init__(self, args, body=None, body_stream=None):  | 
217  | 
"""Constructor.  | 
|
218  | 
||
219  | 
        :param args: tuple of response arguments.
 | 
|
220  | 
        :param body: string of a response body.
 | 
|
221  | 
        :param body_stream: iterable of bytestrings to be streamed to the
 | 
|
222  | 
            client.
 | 
|
223  | 
        """
 | 
|
| 
2018.5.16
by Andrew Bennetts
 Move SmartServerResponse to smart/request.py, untangling more import dependencies.  | 
224  | 
self.args = args  | 
| 
2748.4.2
by Andrew Bennetts
 Add protocol (version two) support for streaming bodies (using chunking) in responses.  | 
225  | 
if body is not None and body_stream is not None:  | 
226  | 
raise errors.BzrError(  | 
|
227  | 
"'body' and 'body_stream' are mutually exclusive.")  | 
|
| 
2018.5.16
by Andrew Bennetts
 Move SmartServerResponse to smart/request.py, untangling more import dependencies.  | 
228  | 
self.body = body  | 
| 
2748.4.2
by Andrew Bennetts
 Add protocol (version two) support for streaming bodies (using chunking) in responses.  | 
229  | 
self.body_stream = body_stream  | 
| 
2018.5.16
by Andrew Bennetts
 Move SmartServerResponse to smart/request.py, untangling more import dependencies.  | 
230  | 
|
| 
2402.1.1
by Andrew Bennetts
 Use the Command pattern for handling smart server commands.  | 
231  | 
def __eq__(self, other):  | 
232  | 
if other is None:  | 
|
233  | 
return False  | 
|
| 
2748.4.2
by Andrew Bennetts
 Add protocol (version two) support for streaming bodies (using chunking) in responses.  | 
234  | 
return (other.args == self.args and  | 
235  | 
other.body == self.body and  | 
|
236  | 
other.body_stream is self.body_stream)  | 
|
| 
2402.1.1
by Andrew Bennetts
 Use the Command pattern for handling smart server commands.  | 
237  | 
|
238  | 
def __repr__(self):  | 
|
| 
3691.2.6
by Martin Pool
 Disable RemoteBranch stacking, but get get_stacked_on_url working, and passing back exceptions  | 
239  | 
return "<%s args=%r body=%r>" % (self.__class__.__name__,  | 
| 
2432.4.5
by Robert Collins
 Make using SuccessfulSmartServerResponse and FailedSmartServerResponse mandatory rather than optional in smart server logic.  | 
240  | 
self.args, self.body)  | 
| 
2402.1.1
by Andrew Bennetts
 Use the Command pattern for handling smart server commands.  | 
241  | 
|
| 
2018.5.16
by Andrew Bennetts
 Move SmartServerResponse to smart/request.py, untangling more import dependencies.  | 
242  | 
|
| 
2432.4.2
by Robert Collins
 Add FailedSmartServerResponse.  | 
243  | 
class FailedSmartServerResponse(SmartServerResponse):  | 
244  | 
"""A SmartServerResponse for a request which failed."""  | 
|
245  | 
||
246  | 
def is_successful(self):  | 
|
247  | 
"""FailedSmartServerResponse are not successful."""  | 
|
248  | 
return False  | 
|
249  | 
||
250  | 
||
| 
2432.4.1
by Robert Collins
 Add SuccessfulSmartServerResponse.  | 
251  | 
class SuccessfulSmartServerResponse(SmartServerResponse):  | 
252  | 
"""A SmartServerResponse for a successfully completed request."""  | 
|
253  | 
||
254  | 
def is_successful(self):  | 
|
255  | 
"""SuccessfulSmartServerResponse are successful."""  | 
|
256  | 
return True  | 
|
257  | 
||
| 
2018.5.16
by Andrew Bennetts
 Move SmartServerResponse to smart/request.py, untangling more import dependencies.  | 
258  | 
|
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
259  | 
class SmartServerRequestHandler(object):  | 
260  | 
"""Protocol logic for smart server.  | 
|
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
261  | 
|
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
262  | 
    This doesn't handle serialization at all, it just processes requests and
 | 
263  | 
    creates responses.
 | 
|
264  | 
    """
 | 
|
265  | 
||
266  | 
    # IMPORTANT FOR IMPLEMENTORS: It is important that SmartServerRequestHandler
 | 
|
267  | 
    # not contain encoding or decoding logic to allow the wire protocol to vary
 | 
|
268  | 
    # from the object protocol: we will want to tweak the wire protocol separate
 | 
|
269  | 
    # from the object model, and ideally we will be able to do that without
 | 
|
270  | 
    # having a SmartServerRequestHandler subclass for each wire protocol, rather
 | 
|
271  | 
    # just a Protocol subclass.
 | 
|
272  | 
||
273  | 
    # TODO: Better way of representing the body for commands that take it,
 | 
|
274  | 
    # and allow it to be streamed into the server.
 | 
|
275  | 
||
| 
4760.1.1
by Andrew Bennetts
 Add optional jail_root argument to SmartServerRequest and friends, and use it in the WSGI glue. Allows opening branches in shared repos via bzr+http (assuming the repo should be accessible).  | 
276  | 
def __init__(self, backing_transport, commands, root_client_path,  | 
| 
4760.1.4
by Andrew Bennetts
 Make jail_root param of SmartServerRequestHandler optional for convenience of tests.  | 
277  | 
jail_root=None):  | 
| 
2018.5.17
by Andrew Bennetts
 Paramaterise the commands handled by SmartServerRequestHandler.  | 
278  | 
"""Constructor.  | 
279  | 
||
280  | 
        :param backing_transport: a Transport to handle requests for.
 | 
|
| 
2018.5.23
by Andrew Bennetts
 Use a Registry for smart server command handlers.  | 
281  | 
        :param commands: a registry mapping command names to SmartServerRequest
 | 
| 
2018.5.17
by Andrew Bennetts
 Paramaterise the commands handled by SmartServerRequestHandler.  | 
282  | 
            subclasses. e.g. bzrlib.transport.smart.vfs.vfs_commands.
 | 
283  | 
        """
 | 
|
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
284  | 
self._backing_transport = backing_transport  | 
| 
2692.1.1
by Andrew Bennetts
 Add translate_client_path method to SmartServerRequest.  | 
285  | 
self._root_client_path = root_client_path  | 
| 
2018.5.17
by Andrew Bennetts
 Paramaterise the commands handled by SmartServerRequestHandler.  | 
286  | 
self._commands = commands  | 
| 
4760.1.4
by Andrew Bennetts
 Make jail_root param of SmartServerRequestHandler optional for convenience of tests.  | 
287  | 
if jail_root is None:  | 
288  | 
jail_root = backing_transport  | 
|
| 
4760.1.1
by Andrew Bennetts
 Add optional jail_root argument to SmartServerRequest and friends, and use it in the WSGI glue. Allows opening branches in shared repos via bzr+http (assuming the repo should be accessible).  | 
289  | 
self._jail_root = jail_root  | 
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
290  | 
self.response = None  | 
291  | 
self.finished_reading = False  | 
|
292  | 
self._command = None  | 
|
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
293  | 
if 'hpss' in debug.debug_flags:  | 
294  | 
self._request_start_time = osutils.timer_func()  | 
|
| 
4913.1.1
by John Arbash Meinel
 Switch to using thread.get_ident() which is available on all python versions.  | 
295  | 
self._thread_id = thread.get_ident()  | 
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
296  | 
|
| 
4889.2.4
by John Arbash Meinel
 Clean up some bits, we don't really need the time reported except for end time.  | 
297  | 
def _trace(self, action, message, extra_bytes=None, include_time=False):  | 
| 
4889.2.3
by John Arbash Meinel
 Get rid of -Dhpssthread, just always include it.  | 
298  | 
        # It is a bit of a shame that this functionality overlaps with that of 
 | 
299  | 
        # ProtocolThreeRequester._trace. However, there is enough difference
 | 
|
300  | 
        # that just putting it in a helper doesn't help a lot. And some state
 | 
|
301  | 
        # is taken from the instance.
 | 
|
| 
4889.2.4
by John Arbash Meinel
 Clean up some bits, we don't really need the time reported except for end time.  | 
302  | 
if include_time:  | 
303  | 
t = '%5.3fs ' % (osutils.timer_func() - self._request_start_time)  | 
|
304  | 
else:  | 
|
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
305  | 
t = ''  | 
306  | 
if extra_bytes is None:  | 
|
307  | 
extra = ''  | 
|
308  | 
else:  | 
|
309  | 
extra = ' ' + repr(extra_bytes[:40])  | 
|
310  | 
if len(extra) > 33:  | 
|
311  | 
extra = extra[:29] + extra[-1] + '...'  | 
|
| 
4889.2.3
by John Arbash Meinel
 Get rid of -Dhpssthread, just always include it.  | 
312  | 
trace.mutter('%12s: [%s] %s%s%s'  | 
313  | 
% (action, self._thread_id, t, message, extra))  | 
|
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
314  | 
|
315  | 
def accept_body(self, bytes):  | 
|
316  | 
"""Accept body data."""  | 
|
| 
4475.2.2
by Andrew Bennetts
 Don't try call do_chunk or do_end if there's no active command (e.g. while consuming a request for an unknown method)  | 
317  | 
if self._command is None:  | 
318  | 
            # no active command object, so ignore the event.
 | 
|
319  | 
            return
 | 
|
| 
3923.5.2
by Andrew Bennetts
 Completely delegate handling of request body chunks to the command object. The default implementation accumulates, like the existing behaviour.  | 
320  | 
self._run_handler_code(self._command.do_chunk, (bytes,), {})  | 
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
321  | 
if 'hpss' in debug.debug_flags:  | 
322  | 
self._trace('accept body',  | 
|
323  | 
'%d bytes' % (len(bytes),), bytes)  | 
|
| 
3943.8.1
by Marius Kruger
 remove all trailing whitespace from bzr source  | 
324  | 
|
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
325  | 
def end_of_body(self):  | 
326  | 
"""No more body data will be received."""  | 
|
| 
3923.5.2
by Andrew Bennetts
 Completely delegate handling of request body chunks to the command object. The default implementation accumulates, like the existing behaviour.  | 
327  | 
self._run_handler_code(self._command.do_end, (), {})  | 
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
328  | 
        # cannot read after this.
 | 
329  | 
self.finished_reading = True  | 
|
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
330  | 
if 'hpss' in debug.debug_flags:  | 
| 
4889.2.4
by John Arbash Meinel
 Clean up some bits, we don't really need the time reported except for end time.  | 
331  | 
self._trace('end of body', '', include_time=True)  | 
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
332  | 
|
333  | 
def _run_handler_code(self, callable, args, kwargs):  | 
|
334  | 
"""Run some handler specific code 'callable'.  | 
|
335  | 
||
336  | 
        If a result is returned, it is considered to be the commands response,
 | 
|
337  | 
        and finished_reading is set true, and its assigned to self.response.
 | 
|
338  | 
||
339  | 
        Any exceptions caught are translated and a response object created
 | 
|
340  | 
        from them.
 | 
|
341  | 
        """
 | 
|
342  | 
result = self._call_converting_errors(callable, args, kwargs)  | 
|
| 
2018.5.19
by Andrew Bennetts
 Add docstrings to all the new modules, and a few other places.  | 
343  | 
|
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
344  | 
if result is not None:  | 
345  | 
self.response = result  | 
|
346  | 
self.finished_reading = True  | 
|
347  | 
||
348  | 
def _call_converting_errors(self, callable, args, kwargs):  | 
|
349  | 
"""Call callable converting errors to Response objects."""  | 
|
350  | 
        # XXX: most of this error conversion is VFS-related, and thus ought to
 | 
|
351  | 
        # be in SmartServerVFSRequestHandler somewhere.
 | 
|
352  | 
try:  | 
|
| 
4160.2.2
by Andrew Bennetts
 Add setup_jail and teardown_jail to SmartServerRequest.  | 
353  | 
self._command.setup_jail()  | 
354  | 
try:  | 
|
355  | 
return callable(*args, **kwargs)  | 
|
356  | 
finally:  | 
|
357  | 
self._command.teardown_jail()  | 
|
| 
4064.1.2
by Andrew Bennetts
 Refactor server-side error translation, improve tests.  | 
358  | 
except (KeyboardInterrupt, SystemExit):  | 
359  | 
            raise
 | 
|
360  | 
except Exception, err:  | 
|
361  | 
err_struct = _translate_error(err)  | 
|
362  | 
return FailedSmartServerResponse(err_struct)  | 
|
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
363  | 
|
| 
3195.3.2
by Andrew Bennetts
 Checkpoint first rough cut of SmartServerRequestProtocolThree, this implementation reuses the _StatefulDecoder class. Plus some attempts to start tidying the smart protocol tests.  | 
364  | 
def headers_received(self, headers):  | 
| 
3245.4.33
by Andrew Bennetts
 Remove unused no_body_received method on SmartServerRequestHandler.  | 
365  | 
        # Just a no-op at the moment.
 | 
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
366  | 
if 'hpss' in debug.debug_flags:  | 
367  | 
self._trace('headers', repr(headers))  | 
|
| 
3195.3.2
by Andrew Bennetts
 Checkpoint first rough cut of SmartServerRequestProtocolThree, this implementation reuses the _StatefulDecoder class. Plus some attempts to start tidying the smart protocol tests.  | 
368  | 
|
369  | 
def args_received(self, args):  | 
|
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
370  | 
cmd = args[0]  | 
371  | 
args = args[1:]  | 
|
372  | 
try:  | 
|
373  | 
command = self._commands.get(cmd)  | 
|
374  | 
except LookupError:  | 
|
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
375  | 
if 'hpss' in debug.debug_flags:  | 
376  | 
self._trace('hpss unknown request',  | 
|
| 
4889.2.4
by John Arbash Meinel
 Clean up some bits, we don't really need the time reported except for end time.  | 
377  | 
cmd, repr(args)[1:-1])  | 
| 
3245.4.48
by Andrew Bennetts
 raise UnknownSmartMethod from dispatch_command.  | 
378  | 
raise errors.UnknownSmartMethod(cmd)  | 
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
379  | 
if 'hpss' in debug.debug_flags:  | 
380  | 
from bzrlib.smart import vfs  | 
|
381  | 
if issubclass(command, vfs.VfsRequest):  | 
|
382  | 
action = 'hpss vfs req'  | 
|
383  | 
else:  | 
|
384  | 
action = 'hpss request'  | 
|
385  | 
self._trace(action,  | 
|
| 
4889.2.4
by John Arbash Meinel
 Clean up some bits, we don't really need the time reported except for end time.  | 
386  | 
'%s %s' % (cmd, repr(args)[1:-1]))  | 
| 
4634.6.30
by Andrew Bennetts
 Remove SmartServerRequest.dispatch_command, fix SmartServerRequest.args_received.  | 
387  | 
self._command = command(  | 
| 
4760.1.1
by Andrew Bennetts
 Add optional jail_root argument to SmartServerRequest and friends, and use it in the WSGI glue. Allows opening branches in shared repos via bzr+http (assuming the repo should be accessible).  | 
388  | 
self._backing_transport, self._root_client_path, self._jail_root)  | 
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
389  | 
self._run_handler_code(self._command.execute, args, {})  | 
| 
3195.3.2
by Andrew Bennetts
 Checkpoint first rough cut of SmartServerRequestProtocolThree, this implementation reuses the _StatefulDecoder class. Plus some attempts to start tidying the smart protocol tests.  | 
390  | 
|
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
391  | 
def end_received(self):  | 
| 
4475.2.2
by Andrew Bennetts
 Don't try call do_chunk or do_end if there's no active command (e.g. while consuming a request for an unknown method)  | 
392  | 
if self._command is None:  | 
393  | 
            # no active command object, so ignore the event.
 | 
|
394  | 
            return
 | 
|
| 
3195.3.4
by Andrew Bennetts
 Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).  | 
395  | 
self._run_handler_code(self._command.do_end, (), {})  | 
| 
4889.2.1
by John Arbash Meinel
 Make -Dhpss log debug information for the server process.  | 
396  | 
if 'hpss' in debug.debug_flags:  | 
| 
4889.2.4
by John Arbash Meinel
 Clean up some bits, we don't really need the time reported except for end time.  | 
397  | 
self._trace('end', '', include_time=True)  | 
| 
3195.3.2
by Andrew Bennetts
 Checkpoint first rough cut of SmartServerRequestProtocolThree, this implementation reuses the _StatefulDecoder class. Plus some attempts to start tidying the smart protocol tests.  | 
398  | 
|
| 
3923.5.4
by Andrew Bennetts
 Allow a request's body part(s) to be followed by an error.  | 
399  | 
def post_body_error_received(self, error_args):  | 
400  | 
        # Just a no-op at the moment.
 | 
|
401  | 
        pass
 | 
|
402  | 
||
| 
2018.5.14
by Andrew Bennetts
 Move SmartTCPServer to smart/server.py, and SmartServerRequestHandler to smart/request.py.  | 
403  | 
|
| 
4064.1.2
by Andrew Bennetts
 Refactor server-side error translation, improve tests.  | 
404  | 
def _translate_error(err):  | 
405  | 
if isinstance(err, errors.NoSuchFile):  | 
|
406  | 
return ('NoSuchFile', err.path)  | 
|
407  | 
elif isinstance(err, errors.FileExists):  | 
|
408  | 
return ('FileExists', err.path)  | 
|
409  | 
elif isinstance(err, errors.DirectoryNotEmpty):  | 
|
410  | 
return ('DirectoryNotEmpty', err.path)  | 
|
| 
4650.2.2
by Robert Collins
 Serialize IncompatibleRepositories from the server too.  | 
411  | 
elif isinstance(err, errors.IncompatibleRepositories):  | 
412  | 
return ('IncompatibleRepositories', str(err.source), str(err.target),  | 
|
413  | 
str(err.details))  | 
|
| 
4064.1.2
by Andrew Bennetts
 Refactor server-side error translation, improve tests.  | 
414  | 
elif isinstance(err, errors.ShortReadvError):  | 
415  | 
return ('ShortReadvError', err.path, str(err.offset), str(err.length),  | 
|
416  | 
str(err.actual))  | 
|
417  | 
elif isinstance(err, errors.UnstackableRepositoryFormat):  | 
|
418  | 
return (('UnstackableRepositoryFormat', str(err.format), err.url))  | 
|
419  | 
elif isinstance(err, errors.UnstackableBranchFormat):  | 
|
420  | 
return ('UnstackableBranchFormat', str(err.format), err.url)  | 
|
421  | 
elif isinstance(err, errors.NotStacked):  | 
|
422  | 
return ('NotStacked',)  | 
|
423  | 
elif isinstance(err, UnicodeError):  | 
|
424  | 
        # If it is a DecodeError, than most likely we are starting
 | 
|
425  | 
        # with a plain string
 | 
|
426  | 
str_or_unicode = err.object  | 
|
427  | 
if isinstance(str_or_unicode, unicode):  | 
|
428  | 
            # XXX: UTF-8 might have \x01 (our protocol v1 and v2 seperator
 | 
|
429  | 
            # byte) in it, so this encoding could cause broken responses.
 | 
|
430  | 
            # Newer clients use protocol v3, so will be fine.
 | 
|
431  | 
val = 'u:' + str_or_unicode.encode('utf-8')  | 
|
432  | 
else:  | 
|
433  | 
val = 's:' + str_or_unicode.encode('base64')  | 
|
434  | 
        # This handles UnicodeEncodeError or UnicodeDecodeError
 | 
|
435  | 
return (err.__class__.__name__, err.encoding, val, str(err.start),  | 
|
436  | 
str(err.end), err.reason)  | 
|
437  | 
elif isinstance(err, errors.TransportNotPossible):  | 
|
438  | 
if err.msg == "readonly transport":  | 
|
439  | 
return ('ReadOnlyError', )  | 
|
440  | 
elif isinstance(err, errors.ReadError):  | 
|
441  | 
        # cannot read the file
 | 
|
442  | 
return ('ReadError', err.path)  | 
|
443  | 
elif isinstance(err, errors.PermissionDenied):  | 
|
444  | 
return ('PermissionDenied', err.path, err.extra)  | 
|
| 
4144.3.1
by Andrew Bennetts
 Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.  | 
445  | 
elif isinstance(err, errors.TokenMismatch):  | 
446  | 
return ('TokenMismatch', err.given_token, err.lock_token)  | 
|
447  | 
elif isinstance(err, errors.LockContention):  | 
|
| 
4556.2.6
by Andrew Bennetts
 More conservative fix for LockContention serialisation.  | 
448  | 
return ('LockContention',)  | 
| 
4064.1.2
by Andrew Bennetts
 Refactor server-side error translation, improve tests.  | 
449  | 
    # Unserialisable error.  Log it, and return a generic error
 | 
450  | 
trace.log_exception_quietly()  | 
|
451  | 
return ('error', str(err))  | 
|
452  | 
||
453  | 
||
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
454  | 
class HelloRequest(SmartServerRequest):  | 
| 
2432.2.6
by Andrew Bennetts
 Improve HelloRequest's docstring.  | 
455  | 
"""Answer a version request with the highest protocol version this server  | 
456  | 
    supports.
 | 
|
457  | 
    """
 | 
|
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
458  | 
|
459  | 
def do(self):  | 
|
| 
3245.4.59
by Andrew Bennetts
 Various tweaks in response to Martin's review.  | 
460  | 
return SuccessfulSmartServerResponse(('ok', '2'))  | 
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
461  | 
|
462  | 
||
463  | 
class GetBundleRequest(SmartServerRequest):  | 
|
| 
2402.1.2
by Andrew Bennetts
 Deal with review comments.  | 
464  | 
"""Get a bundle of from the null revision to the specified revision."""  | 
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
465  | 
|
466  | 
def do(self, path, revision_id):  | 
|
467  | 
        # open transport relative to our base
 | 
|
| 
2692.1.7
by Andrew Bennetts
 Translate path in GetBundleRequest too.  | 
468  | 
t = self.transport_from_client_path(path)  | 
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
469  | 
control, extra_path = bzrdir.BzrDir.open_containing_from_transport(t)  | 
470  | 
repo = control.open_repository()  | 
|
471  | 
tmpf = tempfile.TemporaryFile()  | 
|
472  | 
base_revision = revision.NULL_REVISION  | 
|
| 
3224.5.6
by Andrew Bennetts
 Don't import bzrlib.bundle in bzrlib.smart.request until it's needed.  | 
473  | 
serializer.write_bundle(repo, revision_id, base_revision, tmpf)  | 
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
474  | 
tmpf.seek(0)  | 
| 
2432.4.5
by Robert Collins
 Make using SuccessfulSmartServerResponse and FailedSmartServerResponse mandatory rather than optional in smart server logic.  | 
475  | 
return SuccessfulSmartServerResponse((), tmpf.read())  | 
| 
2018.5.6
by Andrew Bennetts
 Tidy ups, and turn do_hello and do_get_bundle into command objects.  | 
476  | 
|
477  | 
||
| 
2018.5.95
by Andrew Bennetts
 Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.  | 
478  | 
class SmartServerIsReadonly(SmartServerRequest):  | 
479  | 
    # XXX: this request method belongs somewhere else.
 | 
|
480  | 
||
481  | 
def do(self):  | 
|
482  | 
if self._backing_transport.is_readonly():  | 
|
483  | 
answer = 'yes'  | 
|
484  | 
else:  | 
|
485  | 
answer = 'no'  | 
|
| 
2432.4.5
by Robert Collins
 Make using SuccessfulSmartServerResponse and FailedSmartServerResponse mandatory rather than optional in smart server logic.  | 
486  | 
return SuccessfulSmartServerResponse((answer,))  | 
| 
2018.5.95
by Andrew Bennetts
 Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.  | 
487  | 
|
488  | 
||
| 
2018.5.23
by Andrew Bennetts
 Use a Registry for smart server command handlers.  | 
489  | 
request_handlers = registry.Registry()  | 
490  | 
request_handlers.register_lazy(  | 
|
491  | 
'append', 'bzrlib.smart.vfs', 'AppendRequest')  | 
|
492  | 
request_handlers.register_lazy(  | 
|
| 
4084.2.1
by Robert Collins
 Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.  | 
493  | 
'Branch.get_config_file', 'bzrlib.smart.branch',  | 
494  | 
'SmartServerBranchGetConfigFile')  | 
|
| 
2018.5.59
by Robert Collins
 Get BranchConfig working somewhat on RemoteBranches (Robert Collins, Vincent Ladeuil).  | 
495  | 
request_handlers.register_lazy(  | 
| 
4078.2.1
by Robert Collins
 Add a Branch.get_parent remote call for RemoteBranch.  | 
496  | 
'Branch.get_parent', 'bzrlib.smart.branch', 'SmartServerBranchGetParent')  | 
497  | 
request_handlers.register_lazy(  | 
|
| 
4084.2.1
by Robert Collins
 Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.  | 
498  | 
'Branch.get_tags_bytes', 'bzrlib.smart.branch',  | 
499  | 
'SmartServerBranchGetTagsBytes')  | 
|
500  | 
request_handlers.register_lazy(  | 
|
| 
4556.2.1
by Andrew Bennetts
 Add Branch.set_tags_bytes RPC, with HPSS call count acceptance test. Also fixes serialisation of LockDir, and uses external_url() in LockDir's repr and contention message.  | 
501  | 
'Branch.set_tags_bytes', 'bzrlib.smart.branch',  | 
502  | 
'SmartServerBranchSetTagsBytes')  | 
|
503  | 
request_handlers.register_lazy(  | 
|
| 
3691.2.5
by Martin Pool
 Add Branch.get_stacked_on_url rpc and tests for same  | 
504  | 
'Branch.get_stacked_on_url', 'bzrlib.smart.branch', 'SmartServerBranchRequestGetStackedOnURL')  | 
505  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.51
by Wouter van Heyst
 Test and implement RemoteBranch.last_revision_info()  | 
506  | 
'Branch.last_revision_info', 'bzrlib.smart.branch', 'SmartServerBranchRequestLastRevisionInfo')  | 
507  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.79
by Andrew Bennetts
 Implement RemoteBranch.lock_write/unlock as smart operations.  | 
508  | 
'Branch.lock_write', 'bzrlib.smart.branch', 'SmartServerBranchRequestLockWrite')  | 
| 
4226.2.1
by Robert Collins
 Set branch config options via a smart method.  | 
509  | 
request_handlers.register_lazy( 'Branch.revision_history',  | 
510  | 
'bzrlib.smart.branch', 'SmartServerRequestRevisionHistory')  | 
|
511  | 
request_handlers.register_lazy( 'Branch.set_config_option',  | 
|
512  | 
'bzrlib.smart.branch', 'SmartServerBranchRequestSetConfigOption')  | 
|
| 
5227.1.2
by Andrew Bennetts
 Add Branch.set_config_option_dict RPC (and VFS fallback), fixes #430382.  | 
513  | 
request_handlers.register_lazy( 'Branch.set_config_option_dict',  | 
514  | 
'bzrlib.smart.branch', 'SmartServerBranchRequestSetConfigOptionDict')  | 
|
| 
4226.2.1
by Robert Collins
 Set branch config options via a smart method.  | 
515  | 
request_handlers.register_lazy( 'Branch.set_last_revision',  | 
516  | 
'bzrlib.smart.branch', 'SmartServerBranchRequestSetLastRevision')  | 
|
| 
2018.12.3
by Andrew Bennetts
 Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  | 
517  | 
request_handlers.register_lazy(  | 
| 
2892.2.1
by Andrew Bennetts
 Add Branch.set_last_revision_info smart method, and make the RemoteBranch client use it.  | 
518  | 
'Branch.set_last_revision_info', 'bzrlib.smart.branch',  | 
519  | 
'SmartServerBranchRequestSetLastRevisionInfo')  | 
|
520  | 
request_handlers.register_lazy(  | 
|
| 
3441.5.25
by Andrew Bennetts
 Rename Branch.set_last_revision_descendant verb to Branch.set_last_revision_ex. It's a cop out, but at least it's not misleading.  | 
521  | 
'Branch.set_last_revision_ex', 'bzrlib.smart.branch',  | 
522  | 
'SmartServerBranchRequestSetLastRevisionEx')  | 
|
| 
3441.5.6
by Andrew Bennetts
 Greatly simplify RemoteBranch.update_revisions. Still needs more tests.  | 
523  | 
request_handlers.register_lazy(  | 
| 
4288.1.7
by Robert Collins
 Add new remote server verb Branch.set_parent_location, dropping roundtrips further on push operations.  | 
524  | 
'Branch.set_parent_location', 'bzrlib.smart.branch',  | 
525  | 
'SmartServerBranchRequestSetParentLocation')  | 
|
526  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.79
by Andrew Bennetts
 Implement RemoteBranch.lock_write/unlock as smart operations.  | 
527  | 
'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock')  | 
528  | 
request_handlers.register_lazy(  | 
|
| 
4070.2.3
by Robert Collins
 Get BzrDir.cloning_metadir working.  | 
529  | 
'BzrDir.cloning_metadir', 'bzrlib.smart.bzrdir',  | 
530  | 
'SmartServerBzrDirRequestCloningMetaDir')  | 
|
531  | 
request_handlers.register_lazy(  | 
|
| 
4084.2.1
by Robert Collins
 Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.  | 
532  | 
'BzrDir.create_branch', 'bzrlib.smart.bzrdir',  | 
533  | 
'SmartServerRequestCreateBranch')  | 
|
534  | 
request_handlers.register_lazy(  | 
|
535  | 
'BzrDir.create_repository', 'bzrlib.smart.bzrdir',  | 
|
536  | 
'SmartServerRequestCreateRepository')  | 
|
537  | 
request_handlers.register_lazy(  | 
|
538  | 
'BzrDir.find_repository', 'bzrlib.smart.bzrdir',  | 
|
539  | 
'SmartServerRequestFindRepositoryV1')  | 
|
540  | 
request_handlers.register_lazy(  | 
|
541  | 
'BzrDir.find_repositoryV2', 'bzrlib.smart.bzrdir',  | 
|
542  | 
'SmartServerRequestFindRepositoryV2')  | 
|
543  | 
request_handlers.register_lazy(  | 
|
544  | 
'BzrDir.find_repositoryV3', 'bzrlib.smart.bzrdir',  | 
|
545  | 
'SmartServerRequestFindRepositoryV3')  | 
|
546  | 
request_handlers.register_lazy(  | 
|
| 
4288.1.2
by Robert Collins
 Create a server verb for doing BzrDir.get_config()  | 
547  | 
'BzrDir.get_config_file', 'bzrlib.smart.bzrdir',  | 
548  | 
'SmartServerBzrDirRequestConfigFile')  | 
|
549  | 
request_handlers.register_lazy(  | 
|
| 
4084.2.1
by Robert Collins
 Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.  | 
550  | 
'BzrDirFormat.initialize', 'bzrlib.smart.bzrdir',  | 
551  | 
'SmartServerRequestInitializeBzrDir')  | 
|
552  | 
request_handlers.register_lazy(  | 
|
| 
4436.1.1
by Andrew Bennetts
 Rename BzrDirFormat.initialize_ex verb to BzrDirFormat.initialize_ex_1.16.  | 
553  | 
'BzrDirFormat.initialize_ex_1.16', 'bzrlib.smart.bzrdir',  | 
| 
4294.2.7
by Robert Collins
 Start building up a BzrDir.initialize_ex verb for the smart server.  | 
554  | 
'SmartServerRequestBzrDirInitializeEx')  | 
555  | 
request_handlers.register_lazy(  | 
|
| 
4288.1.2
by Robert Collins
 Create a server verb for doing BzrDir.get_config()  | 
556  | 
'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')  | 
557  | 
request_handlers.register_lazy(  | 
|
| 
4634.47.3
by Andrew Bennetts
 Add a BzrDir.open_2.1 verb that indicates if there is a workingtree present. Removes the last 2 VFS calls from incremental pushes.  | 
558  | 
'BzrDir.open_2.1', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir_2_1')  | 
559  | 
request_handlers.register_lazy(  | 
|
| 
4084.2.1
by Robert Collins
 Make accessing a branch.tags.get_tag_dict use a smart[er] method rather than VFS calls and real objects.  | 
560  | 
'BzrDir.open_branch', 'bzrlib.smart.bzrdir',  | 
561  | 
'SmartServerRequestOpenBranch')  | 
|
562  | 
request_handlers.register_lazy(  | 
|
563  | 
'BzrDir.open_branchV2', 'bzrlib.smart.bzrdir',  | 
|
564  | 
'SmartServerRequestOpenBranchV2')  | 
|
| 
2018.6.1
by Robert Collins
 Implement a BzrDir.open_branch smart server method for opening a branch without VFS.  | 
565  | 
request_handlers.register_lazy(  | 
| 
4734.4.8
by Andrew Bennetts
 Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).  | 
566  | 
'BzrDir.open_branchV3', 'bzrlib.smart.bzrdir',  | 
567  | 
'SmartServerRequestOpenBranchV3')  | 
|
568  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.23
by Andrew Bennetts
 Use a Registry for smart server command handlers.  | 
569  | 
'delete', 'bzrlib.smart.vfs', 'DeleteRequest')  | 
570  | 
request_handlers.register_lazy(  | 
|
571  | 
'get', 'bzrlib.smart.vfs', 'GetRequest')  | 
|
572  | 
request_handlers.register_lazy(  | 
|
573  | 
'get_bundle', 'bzrlib.smart.request', 'GetBundleRequest')  | 
|
574  | 
request_handlers.register_lazy(  | 
|
575  | 
'has', 'bzrlib.smart.vfs', 'HasRequest')  | 
|
576  | 
request_handlers.register_lazy(  | 
|
577  | 
'hello', 'bzrlib.smart.request', 'HelloRequest')  | 
|
578  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.37
by Andrew Bennetts
 Make sure all the request handlers in bzrlib/smart/vfs.py have consistent names.  | 
579  | 
'iter_files_recursive', 'bzrlib.smart.vfs', 'IterFilesRecursiveRequest')  | 
| 
2018.5.23
by Andrew Bennetts
 Use a Registry for smart server command handlers.  | 
580  | 
request_handlers.register_lazy(  | 
581  | 
'list_dir', 'bzrlib.smart.vfs', 'ListDirRequest')  | 
|
582  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.37
by Andrew Bennetts
 Make sure all the request handlers in bzrlib/smart/vfs.py have consistent names.  | 
583  | 
'mkdir', 'bzrlib.smart.vfs', 'MkdirRequest')  | 
584  | 
request_handlers.register_lazy(  | 
|
585  | 
'move', 'bzrlib.smart.vfs', 'MoveRequest')  | 
|
586  | 
request_handlers.register_lazy(  | 
|
587  | 
'put', 'bzrlib.smart.vfs', 'PutRequest')  | 
|
588  | 
request_handlers.register_lazy(  | 
|
589  | 
'put_non_atomic', 'bzrlib.smart.vfs', 'PutNonAtomicRequest')  | 
|
590  | 
request_handlers.register_lazy(  | 
|
591  | 
'readv', 'bzrlib.smart.vfs', 'ReadvRequest')  | 
|
592  | 
request_handlers.register_lazy(  | 
|
593  | 
'rename', 'bzrlib.smart.vfs', 'RenameRequest')  | 
|
| 
3452.2.2
by Andrew Bennetts
 Experimental PackRepository.{check_references,autopack} RPCs.  | 
594  | 
request_handlers.register_lazy(  | 
595  | 
'PackRepository.autopack', 'bzrlib.smart.packrepository',  | 
|
596  | 
'SmartServerPackRepositoryAutopack')  | 
|
| 
2018.10.2
by v.ladeuil+lp at free
 gather_stats server side and request registration  | 
597  | 
request_handlers.register_lazy('Repository.gather_stats',  | 
598  | 
'bzrlib.smart.repository',  | 
|
599  | 
'SmartServerRepositoryGatherStats')  | 
|
| 
3842.3.3
by Andrew Bennetts
 Remove RPC registration for VersionedFiles.get_parent_map, not Repository.get_parent_map.  | 
600  | 
request_handlers.register_lazy('Repository.get_parent_map',  | 
601  | 
'bzrlib.smart.repository',  | 
|
602  | 
'SmartServerRepositoryGetParentMap')  | 
|
| 
2018.5.37
by Andrew Bennetts
 Make sure all the request handlers in bzrlib/smart/vfs.py have consistent names.  | 
603  | 
request_handlers.register_lazy(  | 
| 
2018.5.67
by Wouter van Heyst
 Implement RemoteRepository.get_revision_graph (Wouter van Heyst, Robert Collins)  | 
604  | 
'Repository.get_revision_graph', 'bzrlib.smart.repository', 'SmartServerRepositoryGetRevisionGraph')  | 
605  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.40
by Robert Collins
 Implement a remote Repository.has_revision method.  | 
606  | 
'Repository.has_revision', 'bzrlib.smart.repository', 'SmartServerRequestHasRevision')  | 
607  | 
request_handlers.register_lazy(  | 
|
| 
4022.1.6
by Robert Collins
 Cherrypick and polish the RemoteSink for streaming push.  | 
608  | 
'Repository.insert_stream', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream')  | 
609  | 
request_handlers.register_lazy(  | 
|
| 
4476.3.82
by Andrew Bennetts
 Mention another bug fix in NEWS, and update verb name, comments, and NEWS additions for landing on 1.19 rather than 1.18.  | 
610  | 
'Repository.insert_stream_1.19', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream_1_19')  | 
| 
4476.3.15
by Andrew Bennetts
 Partially working fallback for pre-1.17 servers.  | 
611  | 
request_handlers.register_lazy(  | 
| 
4144.3.1
by Andrew Bennetts
 Add Repository.insert_stream_locked server-side implementation, plus tests for server-side _translate_error.  | 
612  | 
'Repository.insert_stream_locked', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStreamLocked')  | 
613  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.57
by Robert Collins
 Implement RemoteRepository.is_shared (Robert Collins, Vincent Ladeuil).  | 
614  | 
'Repository.is_shared', 'bzrlib.smart.repository', 'SmartServerRepositoryIsShared')  | 
615  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
616  | 
'Repository.lock_write', 'bzrlib.smart.repository', 'SmartServerRepositoryLockWrite')  | 
617  | 
request_handlers.register_lazy(  | 
|
| 
4017.3.4
by Robert Collins
 Create a verb for Repository.set_make_working_trees.  | 
618  | 
'Repository.set_make_working_trees', 'bzrlib.smart.repository',  | 
619  | 
'SmartServerRepositorySetMakeWorkingTrees')  | 
|
620  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.78
by Andrew Bennetts
 Implement RemoteRepository.lock_write/unlock to expect and send tokens over the  | 
621  | 
'Repository.unlock', 'bzrlib.smart.repository', 'SmartServerRepositoryUnlock')  | 
622  | 
request_handlers.register_lazy(  | 
|
| 
4419.2.4
by Andrew Bennetts
 Add Repository.get_rev_id_for_revno RPC, removes VFS calls from 'pull -r 123' case.  | 
623  | 
'Repository.get_rev_id_for_revno', 'bzrlib.smart.repository',  | 
624  | 
'SmartServerRepositoryGetRevIdForRevno')  | 
|
625  | 
request_handlers.register_lazy(  | 
|
| 
4060.1.5
by Robert Collins
 Verb change name requested by Andrew.  | 
626  | 
'Repository.get_stream', 'bzrlib.smart.repository',  | 
627  | 
'SmartServerRepositoryGetStream')  | 
|
| 
4060.1.4
by Robert Collins
 Streaming fetch from remote servers.  | 
628  | 
request_handlers.register_lazy(  | 
| 
4476.3.82
by Andrew Bennetts
 Mention another bug fix in NEWS, and update verb name, comments, and NEWS additions for landing on 1.19 rather than 1.18.  | 
629  | 
'Repository.get_stream_1.19', 'bzrlib.smart.repository',  | 
630  | 
'SmartServerRepositoryGetStream_1_19')  | 
|
| 
4476.3.29
by Andrew Bennetts
 Add Repository.get_stream_1.18 verb.  | 
631  | 
request_handlers.register_lazy(  | 
| 
2018.18.1
by Martin Pool
 Add stub Repository.tarball smart method  | 
632  | 
'Repository.tarball', 'bzrlib.smart.repository',  | 
633  | 
'SmartServerRepositoryTarball')  | 
|
634  | 
request_handlers.register_lazy(  | 
|
| 
2018.5.37
by Andrew Bennetts
 Make sure all the request handlers in bzrlib/smart/vfs.py have consistent names.  | 
635  | 
'rmdir', 'bzrlib.smart.vfs', 'RmdirRequest')  | 
636  | 
request_handlers.register_lazy(  | 
|
637  | 
'stat', 'bzrlib.smart.vfs', 'StatRequest')  | 
|
| 
2018.5.26
by Andrew Bennetts
 Extract a simple SmartClient class from RemoteTransport, and a hack to avoid VFS operations when probing for a bzrdir over a smart transport.  | 
638  | 
request_handlers.register_lazy(  | 
| 
2018.5.95
by Andrew Bennetts
 Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.  | 
639  | 
'Transport.is_readonly', 'bzrlib.smart.request', 'SmartServerIsReadonly')  |