Rev 4381: (Jelmer) Add registry for the 'bzr serve' protocol. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue May 26 09:48:56 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4381
revision-id: pqm at pqm.ubuntu.com-20090526084851-z5v419bk4ni21res
parent: pqm at pqm.ubuntu.com-20090525081809-9z1knxaipz0p3pw6
parent: jelmer at samba.org-20090526074803-fx1cdhcfcuxux8pf
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-05-26 09:48:51 +0100
message:
(Jelmer) Add registry for the 'bzr serve' protocol.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/smart/server.py server.py-20061110062051-chzu10y32vx8gvur-1
bzrlib/tests/blackbox/test_serve.py test_serve.py-20060913064329-8t2pvmsikl4s3xhl-1
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
------------------------------------------------------------
revno: 4370.4.7
revision-id: jelmer at samba.org-20090526074803-fx1cdhcfcuxux8pf
parent: jelmer at samba.org-20090521191311-ck3s9vse7fitciva
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: serve-protocol
timestamp: Tue 2009-05-26 09:48:03 +0200
message:
Review feedback from Ian.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/smart/server.py server.py-20061110062051-chzu10y32vx8gvur-1
------------------------------------------------------------
revno: 4370.4.6
revision-id: jelmer at samba.org-20090521191311-ck3s9vse7fitciva
parent: jelmer at samba.org-20090521185511-yhcs7okvqvtpp6as
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: serve-protocol
timestamp: Thu 2009-05-21 21:13:11 +0200
message:
Move server protocol registry to bzrlib.transport.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/smart/server.py server.py-20061110062051-chzu10y32vx8gvur-1
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
------------------------------------------------------------
revno: 4370.4.5
revision-id: jelmer at samba.org-20090521185511-yhcs7okvqvtpp6as
parent: jelmer at samba.org-20090521181809-7tyrzgad83e1sk0w
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: serve-protocol
timestamp: Thu 2009-05-21 20:55:11 +0200
message:
Fix import.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
------------------------------------------------------------
revno: 4370.4.4
revision-id: jelmer at samba.org-20090521181809-7tyrzgad83e1sk0w
parent: jelmer at samba.org-20090521181338-g3ctccvmdkv3orkh
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: serve-protocol
timestamp: Thu 2009-05-21 20:18:09 +0200
message:
Move more bzr smart server-specific stuff into a single function.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
------------------------------------------------------------
revno: 4370.4.3
revision-id: jelmer at samba.org-20090521181338-g3ctccvmdkv3orkh
parent: jelmer at samba.org-20090516131410-iofeqtu9o8y8r8av
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: serve-protocol
timestamp: Thu 2009-05-21 20:13:38 +0200
message:
Move host/port parsing to early in bzr-serve.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
------------------------------------------------------------
revno: 4370.4.2
revision-id: jelmer at samba.org-20090516131410-iofeqtu9o8y8r8av
parent: jelmer at samba.org-20090516121500-4x33ltsaznpq1jv7
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: serve-protocol
timestamp: Sat 2009-05-16 15:14:10 +0200
message:
Add --protocol option to 'bzr serve'.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_serve.py test_serve.py-20060913064329-8t2pvmsikl4s3xhl-1
------------------------------------------------------------
revno: 4370.4.1
revision-id: jelmer at samba.org-20090516121500-4x33ltsaznpq1jv7
parent: pqm at pqm.ubuntu.com-20090516091716-x8ozyp5uuvsgmsfg
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: serve-protocol
timestamp: Sat 2009-05-16 14:15:00 +0200
message:
Add registry for 'bzr serve' protocols.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2009-05-23 04:55:52 +0000
+++ b/bzrlib/builtins.py 2009-05-26 08:48:51 +0000
@@ -4540,11 +4540,15 @@
takes_options = [
Option('inet',
help='Serve on stdin/out for use from inetd or sshd.'),
+ RegistryOption('protocol',
+ help="Protocol to serve.",
+ lazy_registry=('bzrlib.transport', 'transport_server_registry'),
+ value_switches=True),
Option('port',
help='Listen for connections on nominated port of the form '
'[hostname:]portnumber. Passing 0 as the port number will '
- 'result in a dynamically allocated port. The default port is '
- '4155.',
+ 'result in a dynamically allocated port. The default port '
+ 'depends on the protocol.',
type=str),
Option('directory',
help='Serve contents of this directory.',
@@ -4556,28 +4560,10 @@
),
]
- def run_smart_server(self, smart_server):
- """Run 'smart_server' forever, with no UI output at all."""
- # For the duration of this server, no UI output is permitted. note
- # that this may cause problems with blackbox tests. This should be
- # changed with care though, as we dont want to use bandwidth sending
- # progress over stderr to smart server clients!
- from bzrlib import lockdir
- old_factory = ui.ui_factory
- old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
- try:
- ui.ui_factory = ui.SilentUIFactory()
- lockdir._DEFAULT_TIMEOUT_SECONDS = 0
- smart_server.serve()
- finally:
- ui.ui_factory = old_factory
- lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
-
def get_host_and_port(self, port):
"""Return the host and port to run the smart server on.
- If 'port' is None, the default host (`medium.BZR_DEFAULT_INTERFACE`)
- and port (`medium.BZR_DEFAULT_PORT`) will be used.
+ If 'port' is None, None will be returned for the host and port.
If 'port' has a colon in it, the string before the colon will be
interpreted as the host.
@@ -4586,52 +4572,26 @@
:return: A tuple of (host, port), where 'host' is a host name or IP,
and port is an integer TCP/IP port.
"""
- from bzrlib.smart import medium
- host = medium.BZR_DEFAULT_INTERFACE
- if port is None:
- port = medium.BZR_DEFAULT_PORT
- else:
+ host = None
+ if port is not None:
if ':' in port:
host, port = port.split(':')
port = int(port)
return host, port
- def get_smart_server(self, transport, inet, port):
- """Construct a smart server.
-
- :param transport: The base transport from which branches will be
- served.
- :param inet: If True, serve over stdin and stdout. Used for running
- from inet.
- :param port: The port to listen on. By default, it's `
- medium.BZR_DEFAULT_PORT`. See `get_host_and_port` for more
- information.
- :return: A smart server.
- """
- from bzrlib.smart import medium, server
- if inet:
- smart_server = medium.SmartServerPipeStreamMedium(
- sys.stdin, sys.stdout, transport)
- else:
- host, port = self.get_host_and_port(port)
- smart_server = server.SmartTCPServer(
- transport, host=host, port=port)
- note('listening on port: %s' % smart_server.port)
- return smart_server
-
- def run(self, port=None, inet=False, directory=None, allow_writes=False):
- from bzrlib.transport import get_transport
- from bzrlib.transport.chroot import ChrootServer
+ def run(self, port=None, inet=False, directory=None, allow_writes=False,
+ protocol=None):
+ from bzrlib.transport import get_transport, transport_server_registry
if directory is None:
directory = os.getcwd()
+ if protocol is None:
+ protocol = transport_server_registry.get()
+ host, port = self.get_host_and_port(port)
url = urlutils.local_path_to_url(directory)
if not allow_writes:
url = 'readonly+' + url
- chroot_server = ChrootServer(get_transport(url))
- chroot_server.setUp()
- t = get_transport(chroot_server.get_url())
- smart_server = self.get_smart_server(t, inet, port)
- self.run_smart_server(smart_server)
+ transport = get_transport(url)
+ protocol(transport, host, port, inet)
class cmd_join(Command):
=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py 2009-04-04 02:50:01 +0000
+++ b/bzrlib/smart/server.py 2009-05-26 07:48:03 +0000
@@ -307,3 +307,35 @@
return transport.get_transport(url)
+def serve_bzr(transport, host=None, port=None, inet=False):
+ from bzrlib import lockdir, ui
+ from bzrlib.transport import get_transport
+ from bzrlib.transport.chroot import ChrootServer
+ chroot_server = ChrootServer(transport)
+ chroot_server.setUp()
+ t = get_transport(chroot_server.get_url())
+ if inet:
+ smart_server = medium.SmartServerPipeStreamMedium(
+ sys.stdin, sys.stdout, transport)
+ else:
+ if host is None:
+ host = medium.BZR_DEFAULT_INTERFACE
+ if port is None:
+ port = medium.BZR_DEFAULT_PORT
+ smart_server = SmartTCPServer(
+ transport, host=host, port=port)
+ trace.note('listening on port: %s' % smart_server.port)
+ # For the duration of this server, no UI output is permitted. note
+ # that this may cause problems with blackbox tests. This should be
+ # changed with care though, as we dont want to use bandwidth sending
+ # progress over stderr to smart server clients!
+ old_factory = ui.ui_factory
+ old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
+ try:
+ ui.ui_factory = ui.SilentUIFactory()
+ lockdir._DEFAULT_TIMEOUT_SECONDS = 0
+ smart_server.serve()
+ finally:
+ ui.ui_factory = old_factory
+ lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
+
=== modified file 'bzrlib/tests/blackbox/test_serve.py'
--- a/bzrlib/tests/blackbox/test_serve.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_serve.py 2009-05-16 13:14:10 +0000
@@ -138,6 +138,18 @@
self.make_read_requests(branch)
self.assertServerFinishesCleanly(process)
+ def test_bzr_serve_supports_protocol(self):
+ # Make a branch
+ self.make_branch('.')
+
+ process, url = self.start_server_port(['--allow-writes',
+ '--protocol=bzr'])
+
+ # Connect to the server
+ branch = Branch.open(url)
+ self.make_read_requests(branch)
+ self.assertServerFinishesCleanly(process)
+
def test_bzr_connect_to_bzr_ssh(self):
"""User acceptance that get_transport of a bzr+ssh:// behaves correctly.
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2009-04-27 03:34:12 +0000
+++ b/bzrlib/transport/__init__.py 2009-05-21 19:13:11 +0000
@@ -1853,3 +1853,9 @@
register_transport_proto('ssh:')
register_lazy_transport('ssh:', 'bzrlib.transport.remote',
'HintingSSHTransport')
+
+
+transport_server_registry = registry.Registry()
+transport_server_registry.register_lazy('bzr', 'bzrlib.smart.server',
+ 'serve_bzr', help="The Bazaar smart server protocol over TCP. (default port: 4155)")
+transport_server_registry.default_key = 'bzr'
More information about the bazaar-commits
mailing list