~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-23 16:48:41 UTC
  • mto: (6437.41.3 rmbranch-active)
  • mto: This revision was merged to the branch mainline in revision 6481.
  • Revision ID: jelmer@samba.org-20120223164841-eyy9xljbpblkchba
Support colocated branches in 'bzr rmbranch'.

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)))
6247
6265
                 possible_transports=possible_transports,
6248
6266
                 source_branch=branch).open_branch()
6249
6267
        else:
6250
 
            to_branch = lookup_sibling_branch(control_dir, to_location)
 
6268
            try:
 
6269
                to_branch = Branch.open(to_location,
 
6270
                    possible_transports=possible_transports)
 
6271
            except errors.NotBranchError:
 
6272
                to_branch = open_sibling_branch(control_dir, to_location,
 
6273
                    possible_transports=possible_transports)
6251
6274
        if revision is not None:
6252
6275
            revision = revision.as_revision_id(to_branch)
6253
6276
        switch.switch(control_dir, to_branch, force, revision_id=revision)
6450
6473
 
6451
6474
    takes_args = ["location?"]
6452
6475
 
 
6476
    takes_options = ['directory']
 
6477
 
6453
6478
    aliases = ["rmbranch"]
6454
6479
 
6455
 
    def run(self, location=None):
6456
 
        if location is None:
6457
 
            location = "."
6458
 
        cdir = controldir.ControlDir.open_containing(location)[0]
6459
 
        cdir.destroy_branch()
 
6480
    def run(self, directory=None, location=None):
 
6481
        br = open_nearby_branch(near=directory, location=location)
 
6482
        br.bzrdir.destroy_branch(br.name)
6460
6483
 
6461
6484
 
6462
6485
class cmd_shelve(Command):