152
def lookup_sibling_branch(control_dir, location, possible_transports=None):
153
"""Lookup sibling branch.
152
def open_sibling_branch(control_dir, location, possible_transports=None):
153
"""Open a branch, possibly a sibling.
155
155
:param control_dir: Control directory relative to which to lookup the
157
157
:param location: Location to look up
162
162
return control_dir.open_branch(location,
163
163
possible_transports=possible_transports)
164
164
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
165
this_url = _get_branch_location(control_dir)
168
this_url, '..', urlutils.escape(location)))
171
def open_nearby_branch(near=None, location=None, possible_transports=None):
172
"""Open a nearby branch.
174
:param near: Optional location of container from which to open branch
175
:param location: Location of the branch
176
:return: Branch instance
166
return Branch.open(location)
182
return Branch.open(location,
183
possible_transports=possible_transports)
167
184
except errors.NotBranchError:
168
this_url = _get_branch_location(control_dir)
171
this_url, '..', urlutils.escape(location)))
186
cdir = controldir.ControlDir.open(near,
187
possible_transports=possible_transports)
188
return open_sibling_branch(cdir, location,
189
possible_transports=possible_transports)
174
192
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
5479
5497
help="Protocol to serve.",
5480
5498
lazy_registry=('bzrlib.transport', 'transport_server_registry'),
5481
5499
value_switches=True),
5501
help='Listen for connections on nominated address.', type=str),
5483
help='Listen for connections on nominated port of the form '
5484
'[hostname:]portnumber. Passing 0 as the port number will '
5485
'result in a dynamically allocated port. The default port '
5486
'depends on the protocol.',
5503
help='Listen for connections on nominated port. Passing 0 as '
5504
'the port number will result in a dynamically allocated '
5505
'port. The default port depends on the protocol.',
5488
5507
custom_help('directory',
5489
5508
help='Serve contents of this directory.'),
5490
5509
Option('allow-writes',
5500
5519
help='Override the default idle client timeout (5min).'),
5503
def get_host_and_port(self, port):
5504
"""Return the host and port to run the smart server on.
5506
If 'port' is None, None will be returned for the host and port.
5508
If 'port' has a colon in it, the string before the colon will be
5509
interpreted as the host.
5511
:param port: A string of the port to run the server on.
5512
:return: A tuple of (host, port), where 'host' is a host name or IP,
5513
and port is an integer TCP/IP port.
5516
if port is not None:
5518
host, port = port.split(':')
5522
def run(self, port=None, inet=False, directory=None, allow_writes=False,
5523
protocol=None, client_timeout=None):
5522
def run(self, listen=None, port=None, inet=False, directory=None,
5523
allow_writes=False, protocol=None, client_timeout=None):
5524
5524
from bzrlib import transport
5525
5525
if directory is None:
5526
5526
directory = os.getcwd()
5527
5527
if protocol is None:
5528
5528
protocol = transport.transport_server_registry.get()
5529
host, port = self.get_host_and_port(port)
5530
5529
url = transport.location_to_url(directory)
5531
5530
if not allow_writes:
5532
5531
url = 'readonly+' + url
5533
5532
t = transport.get_transport_from_url(url)
5535
protocol(t, host, port, inet, client_timeout)
5534
protocol(t, listen, port, inet, client_timeout)
5536
5535
except TypeError, e:
5537
5536
# We use symbol_versioning.deprecated_in just so that people
5538
5537
# grepping can find it here.
6251
6250
possible_transports=possible_transports,
6252
6251
source_branch=branch).open_branch()
6254
to_branch = lookup_sibling_branch(control_dir, to_location)
6254
to_branch = Branch.open(to_location,
6255
possible_transports=possible_transports)
6256
except errors.NotBranchError:
6257
to_branch = open_sibling_branch(control_dir, to_location,
6258
possible_transports=possible_transports)
6255
6259
if revision is not None:
6256
6260
revision = revision.as_revision_id(to_branch)
6257
6261
switch.switch(control_dir, to_branch, force, revision_id=revision)
6455
6459
takes_args = ["location?"]
6461
takes_options = ['directory']
6457
6463
aliases = ["rmbranch"]
6459
def run(self, location=None):
6460
if location is None:
6462
cdir = controldir.ControlDir.open_containing(location)[0]
6463
cdir.destroy_branch()
6465
def run(self, directory=None, location=None):
6466
br = open_nearby_branch(near=directory, location=location)
6467
br.bzrdir.destroy_branch(br.name)
6466
6470
class cmd_shelve(Command):