~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Patch Queue Manager
  • Date: 2012-03-06 16:45:45 UTC
  • mfrom: (6437.40.2 rmbranch-colo)
  • Revision ID: pqm@pqm.ubuntu.com-20120306164545-6i5cyyfxctiwq11p
(jelmer) Support removing colocated branches in 'bzr rmbranch'. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
    return location
150
150
 
151
151
 
152
 
def lookup_sibling_branch(control_dir, location, possible_transports=None):
153
 
    """Lookup sibling branch.
154
 
    
 
152
def open_sibling_branch(control_dir, location, possible_transports=None):
 
153
    """Open a branch, possibly a sibling.
 
154
 
155
155
    :param control_dir: Control directory relative to which to lookup the
156
156
        location.
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)
 
166
        return Branch.open(
 
167
            urlutils.join(
 
168
                this_url, '..', urlutils.escape(location)))
 
169
 
 
170
 
 
171
def open_nearby_branch(near=None, location=None, possible_transports=None):
 
172
    """Open a nearby branch.
 
173
 
 
174
    :param near: Optional location of container from which to open branch
 
175
    :param location: Location of the branch
 
176
    :return: Branch instance
 
177
    """
 
178
    if near is None:
 
179
        if location is None:
 
180
            location = "."
165
181
        try:
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)
169
 
            return Branch.open(
170
 
                urlutils.join(
171
 
                    this_url, '..', urlutils.escape(location)))
 
185
            near = "."
 
186
    cdir = controldir.ControlDir.open(near,
 
187
        possible_transports=possible_transports)
 
188
    return open_sibling_branch(cdir, location,
 
189
        possible_transports=possible_transports)
172
190
 
173
191
 
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),
 
5500
        Option('listen',
 
5501
               help='Listen for connections on nominated address.', type=str),
5482
5502
        Option('port',
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.',
5487
 
               type=str),
 
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.',
 
5506
               type=int),
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).'),
5501
5520
        ]
5502
5521
 
5503
 
    def get_host_and_port(self, port):
5504
 
        """Return the host and port to run the smart server on.
5505
 
 
5506
 
        If 'port' is None, None will be returned for the host and port.
5507
 
 
5508
 
        If 'port' has a colon in it, the string before the colon will be
5509
 
        interpreted as the host.
5510
 
 
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.
5514
 
        """
5515
 
        host = None
5516
 
        if port is not None:
5517
 
            if ':' in port:
5518
 
                host, port = port.split(':')
5519
 
            port = int(port)
5520
 
        return host, port
5521
 
 
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)
5534
5533
        try:
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()
6253
6252
        else:
6254
 
            to_branch = lookup_sibling_branch(control_dir, to_location)
 
6253
            try:
 
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)
6454
6458
 
6455
6459
    takes_args = ["location?"]
6456
6460
 
 
6461
    takes_options = ['directory']
 
6462
 
6457
6463
    aliases = ["rmbranch"]
6458
6464
 
6459
 
    def run(self, location=None):
6460
 
        if location is None:
6461
 
            location = "."
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)
6464
6468
 
6465
6469
 
6466
6470
class cmd_shelve(Command):