~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)))
6232
6250
                 possible_transports=possible_transports,
6233
6251
                 source_branch=branch).open_branch()
6234
6252
        else:
6235
 
            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)
6236
6259
        if revision is not None:
6237
6260
            revision = revision.as_revision_id(to_branch)
6238
6261
        switch.switch(control_dir, to_branch, force, revision_id=revision)
6435
6458
 
6436
6459
    takes_args = ["location?"]
6437
6460
 
 
6461
    takes_options = ['directory']
 
6462
 
6438
6463
    aliases = ["rmbranch"]
6439
6464
 
6440
 
    def run(self, location=None):
6441
 
        if location is None:
6442
 
            location = "."
6443
 
        cdir = controldir.ControlDir.open_containing(location)[0]
6444
 
        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)
6445
6468
 
6446
6469
 
6447
6470
class cmd_shelve(Command):