Custom HPSS request handlers?
Russ Brown
pickscrape at gmail.com
Wed Jan 21 17:45:00 GMT 2009
John Arbash Meinel wrote:
> Russ Brown wrote:
>> Hi,
>
>> I'm wondering if it is possible to define a custom HPPS request in a
>> plugin on the server, and make that request from a plugin at the client end.
>
>> The specific use case is that we have a number of repositories contain a
>> number of branches, and want to to be able to find out which are
>> candidates for removal. For the purposes of this utility, removable
>> branches are defined as containing no revisions that are not already
>> merged into the trunk branch in the same repository.
>
>> I have working code that does this already: the problem is that it is
>> extremely slow. So, I'm thinking that if I could write something that
>> would do the server-side trawling completely at the server side that
>> just returned the results to the client, that would speed up the
>> operation considerably.
>
>> So, is it possible to do this in a plugin, and if so, could someone
>> point me at an example of this that I can work from?
>
>> Much appreciated,
>
>
> On the server side you would need to register the RPC in
> bzrlib.smart.request.request_handlers.register_lazy()
>
Excellent, it looks like I can just call this from within the plugin: I
really didn't want to have to use a custom bzrlib.
> And then on the client side, I would assume you are adding a new command
> object (registered via bzrlib.commands.register_command)
>
> Which can then make the request. There is a helper class in
> bzrlib.remote._RpcHelper, which provides a '_call()' function which
> could be useful for you.
>
> In general, I would imagine the client plugin would look roughly like:
>
> from bzrlib import commands, errors
>
> class cmd_xxx(commands.Command):
> """Run the xxx command on the remote machine."""
>
> takes_args = ['location']
>
> def run(self, location):
> from bzrlib import bzrdir, remote
> remote_bzrdir = bzrdir.BzrDir.open(location)
> if not isinstance(remote_bzrdir, remote.RemoteBzrDir):
> raise errors.BzrCommandError('Not a remote location:'
> ' %s' % (location,))
> response = remote_bzrdir._call_with_body_bytes("MyCustomRPC",
> arg1, foo='bar')
> response_tuple, response_handler = response
> if response_tuple[0] != 'ok':
> # Request failed
> return 1
> body = response_handler.read_body_bytes()
> # Parse the body bytes into whatever you need
>
> commands.register_command(cmd_xxx)
>
I actually already have the command: the remote request will only need
to be made if a specific option is passed to the command. Your code
gives what I need very nicely though.
> John
> =:->
Thanks a lot for the help!
More information about the bazaar
mailing list