~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Johan Walles
  • Date: 2009-05-06 05:36:28 UTC
  • mfrom: (4332 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4343.
  • Revision ID: johan.walles@gmail.com-20090506053628-tbf1wz4a0m9t684g
MergeĀ fromĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
610
610
                for glob, paths in ignored.items():
611
611
                    match_len += len(paths)
612
612
                self.outf.write("ignored %d file(s).\n" % match_len)
613
 
            self.outf.write("If you wish to add ignored files, "
614
 
                            "please add them explicitly by name. "
615
 
                            "(\"bzr ignored\" gives a list)\n")
 
613
            self.outf.write("If you wish to add some of these files,"
 
614
                            " please add them by name.\n")
616
615
 
617
616
 
618
617
class cmd_mkdir(Command):
883
882
            short_name='d',
884
883
            type=unicode,
885
884
            ),
886
 
        Option('local',
887
 
            help="Perform a local pull in a bound "
888
 
                 "branch.  Local pulls are not applied to "
889
 
                 "the master branch."
890
 
            ),
891
885
        ]
892
886
    takes_args = ['location?']
893
887
    encoding_type = 'replace'
894
888
 
895
889
    def run(self, location=None, remember=False, overwrite=False,
896
890
            revision=None, verbose=False,
897
 
            directory=None, local=False):
 
891
            directory=None):
898
892
        # FIXME: too much stuff is in the command class
899
893
        revision_id = None
900
894
        mergeable = None
906
900
        except errors.NoWorkingTree:
907
901
            tree_to = None
908
902
            branch_to = Branch.open_containing(directory)[0]
909
 
        
910
 
        if local and not branch_to.get_bound_location():
911
 
            raise errors.LocalRequiresBoundBranch()
912
903
 
913
904
        possible_transports = []
914
905
        if location is not None:
957
948
                    unversioned_filter=tree_to.is_ignored, view_info=view_info)
958
949
                result = tree_to.pull(branch_from, overwrite, revision_id,
959
950
                                      change_reporter,
960
 
                                      possible_transports=possible_transports,
961
 
                                      local=local)
 
951
                                      possible_transports=possible_transports)
962
952
            else:
963
 
                result = branch_to.pull(branch_from, overwrite, revision_id,
964
 
                                      local=local)
 
953
                result = branch_to.pull(branch_from, overwrite, revision_id)
965
954
 
966
955
            result.report(self.outf)
967
956
            if verbose and result.old_revid != result.new_revid:
2090
2079
 
2091
2080
      When exploring non-mainline history on large projects with deep
2092
2081
      history, the performance of log can be greatly improved by installing
2093
 
      the historycache plugin. This plugin buffers historical information
 
2082
      the revnocache plugin. This plugin buffers historical information
2094
2083
      trading disk space for faster speed.
2095
2084
    """
2096
2085
    takes_args = ['file*']
2728
2717
class cmd_commit(Command):
2729
2718
    """Commit changes into a new revision.
2730
2719
 
2731
 
    An explanatory message needs to be given for each commit. This is
2732
 
    often done by using the --message option (getting the message from the
2733
 
    command line) or by using the --file option (getting the message from
2734
 
    a file). If neither of these options is given, an editor is opened for
2735
 
    the user to enter the message. To see the changed files in the
2736
 
    boilerplate text loaded into the editor, use the --show-diff option.
2737
 
 
2738
 
    By default, the entire tree is committed and the person doing the
2739
 
    commit is assumed to be the author. These defaults can be overridden
2740
 
    as explained below.
2741
 
 
2742
 
    :Selective commits:
2743
 
 
2744
 
      If selected files are specified, only changes to those files are
2745
 
      committed.  If a directory is specified then the directory and
2746
 
      everything within it is committed.
2747
 
  
2748
 
      When excludes are given, they take precedence over selected files.
2749
 
      For example, to commit only changes within foo, but not changes
2750
 
      within foo/bar::
2751
 
  
2752
 
        bzr commit foo -x foo/bar
2753
 
  
2754
 
      A selective commit after a merge is not yet supported.
2755
 
 
2756
 
    :Custom authors:
2757
 
 
2758
 
      If the author of the change is not the same person as the committer,
2759
 
      you can specify the author's name using the --author option. The
2760
 
      name should be in the same format as a committer-id, e.g.
2761
 
      "John Doe <jdoe@example.com>". If there is more than one author of
2762
 
      the change you can specify the option multiple times, once for each
2763
 
      author.
2764
 
  
2765
 
    :Checks:
2766
 
 
2767
 
      A common mistake is to forget to add a new file or directory before
2768
 
      running the commit command. The --strict option checks for unknown
2769
 
      files and aborts the commit if any are found. More advanced pre-commit
2770
 
      checks can be implemented by defining hooks. See ``bzr help hooks``
2771
 
      for details.
2772
 
 
2773
 
    :Things to note:
2774
 
 
2775
 
      If you accidentially commit the wrong changes or make a spelling
2776
 
      mistake in the commit message say, you can use the uncommit command
2777
 
      to undo it. See ``bzr help uncommit`` for details.
2778
 
 
2779
 
      Hooks can also be configured to run after a commit. This allows you
2780
 
      to trigger updates to external systems like bug trackers. The --fixes
2781
 
      option can be used to record the association between a revision and
2782
 
      one or more bugs. See ``bzr help bugs`` for details.
2783
 
 
2784
 
      A selective commit may fail in some cases where the committed
2785
 
      tree would be invalid. Consider::
2786
 
  
2787
 
        bzr init foo
2788
 
        mkdir foo/bar
2789
 
        bzr add foo/bar
2790
 
        bzr commit foo -m "committing foo"
2791
 
        bzr mv foo/bar foo/baz
2792
 
        mkdir foo/bar
2793
 
        bzr add foo/bar
2794
 
        bzr commit foo/bar -m "committing bar but not baz"
2795
 
  
2796
 
      In the example above, the last commit will fail by design. This gives
2797
 
      the user the opportunity to decide whether they want to commit the
2798
 
      rename at the same time, separately first, or not at all. (As a general
2799
 
      rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
 
2720
    If no arguments are given, the entire tree is committed.
 
2721
 
 
2722
    If selected files are specified, only changes to those files are
 
2723
    committed.  If a directory is specified then the directory and everything
 
2724
    within it is committed.
 
2725
 
 
2726
    When excludes are given, they take precedence over selected files.
 
2727
    For example, too commit only changes within foo, but not changes within
 
2728
    foo/bar::
 
2729
 
 
2730
      bzr commit foo -x foo/bar
 
2731
 
 
2732
    If author of the change is not the same person as the committer, you can
 
2733
    specify the author's name using the --author option. The name should be
 
2734
    in the same format as a committer-id, e.g. "John Doe <jdoe@example.com>".
 
2735
    If there is more than one author of the change you can specify the option
 
2736
    multiple times, once for each author.
 
2737
 
 
2738
    A selected-file commit may fail in some cases where the committed
 
2739
    tree would be invalid. Consider::
 
2740
 
 
2741
      bzr init foo
 
2742
      mkdir foo/bar
 
2743
      bzr add foo/bar
 
2744
      bzr commit foo -m "committing foo"
 
2745
      bzr mv foo/bar foo/baz
 
2746
      mkdir foo/bar
 
2747
      bzr add foo/bar
 
2748
      bzr commit foo/bar -m "committing bar but not baz"
 
2749
 
 
2750
    In the example above, the last commit will fail by design. This gives
 
2751
    the user the opportunity to decide whether they want to commit the
 
2752
    rename at the same time, separately first, or not at all. (As a general
 
2753
    rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
 
2754
 
 
2755
    Note: A selected-file commit after a merge is not yet supported.
2800
2756
    """
2801
2757
    # TODO: Run hooks on tree to-be-committed, and after commit.
2802
2758
 
2807
2763
 
2808
2764
    # XXX: verbose currently does nothing
2809
2765
 
2810
 
    _see_also = ['add', 'bugs', 'hooks', 'uncommit']
 
2766
    _see_also = ['bugs', 'uncommit']
2811
2767
    takes_args = ['selected*']
2812
2768
    takes_options = [
2813
2769
            ListOption('exclude', type=str, short_name='x',
2934
2890
        except PointlessCommit:
2935
2891
            # FIXME: This should really happen before the file is read in;
2936
2892
            # perhaps prepare the commit; get the message; then actually commit
2937
 
            raise errors.BzrCommandError("No changes to commit."
2938
 
                              " Use --unchanged to commit anyhow.")
 
2893
            raise errors.BzrCommandError("no changes to commit."
 
2894
                              " use --unchanged to commit anyhow")
2939
2895
        except ConflictsInTree:
2940
2896
            raise errors.BzrCommandError('Conflicts detected in working '
2941
2897
                'tree.  Use "bzr conflicts" to list, "bzr resolve FILE" to'
4541
4497
    takes_options = [
4542
4498
        Option('inet',
4543
4499
               help='Serve on stdin/out for use from inetd or sshd.'),
4544
 
        RegistryOption('protocol', 
4545
 
               help="Protocol to serve.", 
4546
 
               lazy_registry=('bzrlib.transport', 'transport_server_registry'),
4547
 
               value_switches=True),
4548
4500
        Option('port',
4549
4501
               help='Listen for connections on nominated port of the form '
4550
4502
                    '[hostname:]portnumber.  Passing 0 as the port number will '
4551
 
                    'result in a dynamically allocated port.  The default port '
4552
 
                    'depends on the protocol.',
 
4503
                    'result in a dynamically allocated port.  The default port is '
 
4504
                    '4155.',
4553
4505
               type=str),
4554
4506
        Option('directory',
4555
4507
               help='Serve contents of this directory.',
4561
4513
                ),
4562
4514
        ]
4563
4515
 
 
4516
    def run_smart_server(self, smart_server):
 
4517
        """Run 'smart_server' forever, with no UI output at all."""
 
4518
        # For the duration of this server, no UI output is permitted. note
 
4519
        # that this may cause problems with blackbox tests. This should be
 
4520
        # changed with care though, as we dont want to use bandwidth sending
 
4521
        # progress over stderr to smart server clients!
 
4522
        from bzrlib import lockdir
 
4523
        old_factory = ui.ui_factory
 
4524
        old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
 
4525
        try:
 
4526
            ui.ui_factory = ui.SilentUIFactory()
 
4527
            lockdir._DEFAULT_TIMEOUT_SECONDS = 0
 
4528
            smart_server.serve()
 
4529
        finally:
 
4530
            ui.ui_factory = old_factory
 
4531
            lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
 
4532
 
4564
4533
    def get_host_and_port(self, port):
4565
4534
        """Return the host and port to run the smart server on.
4566
4535
 
4567
 
        If 'port' is None, None will be returned for the host and port.
 
4536
        If 'port' is None, the default host (`medium.BZR_DEFAULT_INTERFACE`)
 
4537
        and port (`medium.BZR_DEFAULT_PORT`) will be used.
4568
4538
 
4569
4539
        If 'port' has a colon in it, the string before the colon will be
4570
4540
        interpreted as the host.
4573
4543
        :return: A tuple of (host, port), where 'host' is a host name or IP,
4574
4544
            and port is an integer TCP/IP port.
4575
4545
        """
4576
 
        host = None
4577
 
        if port is not None:
 
4546
        from bzrlib.smart import medium
 
4547
        host = medium.BZR_DEFAULT_INTERFACE
 
4548
        if port is None:
 
4549
            port = medium.BZR_DEFAULT_PORT
 
4550
        else:
4578
4551
            if ':' in port:
4579
4552
                host, port = port.split(':')
4580
4553
            port = int(port)
4581
4554
        return host, port
4582
4555
 
4583
 
    def run(self, port=None, inet=False, directory=None, allow_writes=False,
4584
 
            protocol=None):
4585
 
        from bzrlib.transport import get_transport, transport_server_registry
 
4556
    def get_smart_server(self, transport, inet, port):
 
4557
        """Construct a smart server.
 
4558
 
 
4559
        :param transport: The base transport from which branches will be
 
4560
            served.
 
4561
        :param inet: If True, serve over stdin and stdout. Used for running
 
4562
            from inet.
 
4563
        :param port: The port to listen on. By default, it's `
 
4564
            medium.BZR_DEFAULT_PORT`. See `get_host_and_port` for more
 
4565
            information.
 
4566
        :return: A smart server.
 
4567
        """
 
4568
        from bzrlib.smart import medium, server
 
4569
        if inet:
 
4570
            smart_server = medium.SmartServerPipeStreamMedium(
 
4571
                sys.stdin, sys.stdout, transport)
 
4572
        else:
 
4573
            host, port = self.get_host_and_port(port)
 
4574
            smart_server = server.SmartTCPServer(
 
4575
                transport, host=host, port=port)
 
4576
            note('listening on port: %s' % smart_server.port)
 
4577
        return smart_server
 
4578
 
 
4579
    def run(self, port=None, inet=False, directory=None, allow_writes=False):
 
4580
        from bzrlib.transport import get_transport
 
4581
        from bzrlib.transport.chroot import ChrootServer
4586
4582
        if directory is None:
4587
4583
            directory = os.getcwd()
4588
 
        if protocol is None:
4589
 
            protocol = transport_server_registry.get()
4590
 
        host, port = self.get_host_and_port(port)
4591
4584
        url = urlutils.local_path_to_url(directory)
4592
4585
        if not allow_writes:
4593
4586
            url = 'readonly+' + url
4594
 
        transport = get_transport(url)
4595
 
        protocol(transport, host, port, inet)
 
4587
        chroot_server = ChrootServer(get_transport(url))
 
4588
        chroot_server.setUp()
 
4589
        t = get_transport(chroot_server.get_url())
 
4590
        smart_server = self.get_smart_server(t, inet, port)
 
4591
        self.run_smart_server(smart_server)
4596
4592
 
4597
4593
 
4598
4594
class cmd_join(Command):
4844
4840
        'revision',
4845
4841
        'message',
4846
4842
        Option('body', help='Body for the email.', type=unicode),
4847
 
        RegistryOption('format',
4848
 
                       help='Use the specified output format.', 
4849
 
                       lazy_registry=('bzrlib.send', 'format_registry'))
 
4843
        RegistryOption.from_kwargs('format',
 
4844
        'Use the specified output format.',
 
4845
        **{'4': 'Bundle format 4, Merge Directive 2 (default)',
 
4846
           '0.9': 'Bundle format 0.9, Merge Directive 1',})
4850
4847
        ]
4851
4848
 
4852
4849
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4853
4850
            no_patch=False, revision=None, remember=False, output=None,
4854
 
            format=None, mail_to=None, message=None, body=None, **kwargs):
4855
 
        from bzrlib.send import send
4856
 
        return send(submit_branch, revision, public_branch, remember,
 
4851
            format='4', mail_to=None, message=None, body=None, **kwargs):
 
4852
        return self._run(submit_branch, revision, public_branch, remember,
4857
4853
                         format, no_bundle, no_patch, output,
4858
 
                         kwargs.get('from', '.'), mail_to, message, body,
4859
 
                         self.outf)
 
4854
                         kwargs.get('from', '.'), mail_to, message, body)
 
4855
 
 
4856
    def _run(self, submit_branch, revision, public_branch, remember, format,
 
4857
             no_bundle, no_patch, output, from_, mail_to, message, body):
 
4858
        from bzrlib.revision import NULL_REVISION
 
4859
        branch = Branch.open_containing(from_)[0]
 
4860
        if output is None:
 
4861
            outfile = cStringIO.StringIO()
 
4862
        elif output == '-':
 
4863
            outfile = self.outf
 
4864
        else:
 
4865
            outfile = open(output, 'wb')
 
4866
        # we may need to write data into branch's repository to calculate
 
4867
        # the data to send.
 
4868
        branch.lock_write()
 
4869
        try:
 
4870
            if output is None:
 
4871
                config = branch.get_config()
 
4872
                if mail_to is None:
 
4873
                    mail_to = config.get_user_option('submit_to')
 
4874
                mail_client = config.get_mail_client()
 
4875
                if (not getattr(mail_client, 'supports_body', False)
 
4876
                    and body is not None):
 
4877
                    raise errors.BzrCommandError(
 
4878
                        'Mail client "%s" does not support specifying body' %
 
4879
                        mail_client.__class__.__name__)
 
4880
            if remember and submit_branch is None:
 
4881
                raise errors.BzrCommandError(
 
4882
                    '--remember requires a branch to be specified.')
 
4883
            stored_submit_branch = branch.get_submit_branch()
 
4884
            remembered_submit_branch = None
 
4885
            if submit_branch is None:
 
4886
                submit_branch = stored_submit_branch
 
4887
                remembered_submit_branch = "submit"
 
4888
            else:
 
4889
                if stored_submit_branch is None or remember:
 
4890
                    branch.set_submit_branch(submit_branch)
 
4891
            if submit_branch is None:
 
4892
                submit_branch = branch.get_parent()
 
4893
                remembered_submit_branch = "parent"
 
4894
            if submit_branch is None:
 
4895
                raise errors.BzrCommandError('No submit branch known or'
 
4896
                                             ' specified')
 
4897
            if remembered_submit_branch is not None:
 
4898
                note('Using saved %s location "%s" to determine what '
 
4899
                        'changes to submit.', remembered_submit_branch,
 
4900
                        submit_branch)
 
4901
 
 
4902
            if mail_to is None:
 
4903
                submit_config = Branch.open(submit_branch).get_config()
 
4904
                mail_to = submit_config.get_user_option("child_submit_to")
 
4905
 
 
4906
            stored_public_branch = branch.get_public_branch()
 
4907
            if public_branch is None:
 
4908
                public_branch = stored_public_branch
 
4909
            elif stored_public_branch is None or remember:
 
4910
                branch.set_public_branch(public_branch)
 
4911
            if no_bundle and public_branch is None:
 
4912
                raise errors.BzrCommandError('No public branch specified or'
 
4913
                                             ' known')
 
4914
            base_revision_id = None
 
4915
            revision_id = None
 
4916
            if revision is not None:
 
4917
                if len(revision) > 2:
 
4918
                    raise errors.BzrCommandError('bzr send takes '
 
4919
                        'at most two one revision identifiers')
 
4920
                revision_id = revision[-1].as_revision_id(branch)
 
4921
                if len(revision) == 2:
 
4922
                    base_revision_id = revision[0].as_revision_id(branch)
 
4923
            if revision_id is None:
 
4924
                revision_id = branch.last_revision()
 
4925
            if revision_id == NULL_REVISION:
 
4926
                raise errors.BzrCommandError('No revisions to submit.')
 
4927
            if format == '4':
 
4928
                directive = merge_directive.MergeDirective2.from_objects(
 
4929
                    branch.repository, revision_id, time.time(),
 
4930
                    osutils.local_time_offset(), submit_branch,
 
4931
                    public_branch=public_branch, include_patch=not no_patch,
 
4932
                    include_bundle=not no_bundle, message=message,
 
4933
                    base_revision_id=base_revision_id)
 
4934
            elif format == '0.9':
 
4935
                if not no_bundle:
 
4936
                    if not no_patch:
 
4937
                        patch_type = 'bundle'
 
4938
                    else:
 
4939
                        raise errors.BzrCommandError('Format 0.9 does not'
 
4940
                            ' permit bundle with no patch')
 
4941
                else:
 
4942
                    if not no_patch:
 
4943
                        patch_type = 'diff'
 
4944
                    else:
 
4945
                        patch_type = None
 
4946
                directive = merge_directive.MergeDirective.from_objects(
 
4947
                    branch.repository, revision_id, time.time(),
 
4948
                    osutils.local_time_offset(), submit_branch,
 
4949
                    public_branch=public_branch, patch_type=patch_type,
 
4950
                    message=message)
 
4951
 
 
4952
            outfile.writelines(directive.to_lines())
 
4953
            if output is None:
 
4954
                subject = '[MERGE] '
 
4955
                if message is not None:
 
4956
                    subject += message
 
4957
                else:
 
4958
                    revision = branch.repository.get_revision(revision_id)
 
4959
                    subject += revision.get_summary()
 
4960
                basename = directive.get_disk_name(branch)
 
4961
                mail_client.compose_merge_request(mail_to, subject,
 
4962
                                                  outfile.getvalue(),
 
4963
                                                  basename, body)
 
4964
        finally:
 
4965
            if output != '-':
 
4966
                outfile.close()
 
4967
            branch.unlock()
4860
4968
 
4861
4969
 
4862
4970
class cmd_bundle_revisions(cmd_send):
 
4971
 
4863
4972
    """Create a merge-directive for submitting changes.
4864
4973
 
4865
4974
    A merge directive provides many things needed for requesting merges:
4907
5016
        Option('output', short_name='o', help='Write directive to this file.',
4908
5017
               type=unicode),
4909
5018
        'revision',
4910
 
        RegistryOption('format',
4911
 
                       help='Use the specified output format.',
4912
 
                       lazy_registry=('bzrlib.send', 'format_registry')),
 
5019
        RegistryOption.from_kwargs('format',
 
5020
        'Use the specified output format.',
 
5021
        **{'4': 'Bundle format 4, Merge Directive 2 (default)',
 
5022
           '0.9': 'Bundle format 0.9, Merge Directive 1',})
4913
5023
        ]
4914
5024
    aliases = ['bundle']
4915
5025
 
4919
5029
 
4920
5030
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4921
5031
            no_patch=False, revision=None, remember=False, output=None,
4922
 
            format=None, **kwargs):
 
5032
            format='4', **kwargs):
4923
5033
        if output is None:
4924
5034
            output = '-'
4925
 
        from bzrlib.send import send
4926
 
        return send(submit_branch, revision, public_branch, remember,
 
5035
        return self._run(submit_branch, revision, public_branch, remember,
4927
5036
                         format, no_bundle, no_patch, output,
4928
 
                         kwargs.get('from', '.'), None, None, None,
4929
 
                         self.outf)
 
5037
                         kwargs.get('from', '.'), None, None, None)
4930
5038
 
4931
5039
 
4932
5040
class cmd_tag(Command):
5053
5161
            tags.sort(key=lambda x: timestamps[x[1]])
5054
5162
        if not show_ids:
5055
5163
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5056
 
            for index, (tag, revid) in enumerate(tags):
5057
 
                try:
5058
 
                    revno = branch.revision_id_to_dotted_revno(revid)
5059
 
                    if isinstance(revno, tuple):
5060
 
                        revno = '.'.join(map(str, revno))
5061
 
                except errors.NoSuchRevision:
5062
 
                    # Bad tag data/merges can lead to tagged revisions
5063
 
                    # which are not in this branch. Fail gracefully ...
5064
 
                    revno = '?'
5065
 
                tags[index] = (tag, revno)
 
5164
            revno_map = branch.get_revision_id_to_revno_map()
 
5165
            tags = [ (tag, '.'.join(map(str, revno_map.get(revid, ('?',)))))
 
5166
                        for tag, revid in tags ]
5066
5167
        for tag, revspec in tags:
5067
5168
            self.outf.write('%-20s %s\n' % (tag, revspec))
5068
5169
 
5167
5268
        from bzrlib import switch
5168
5269
        tree_location = '.'
5169
5270
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5170
 
        try:
5171
 
            branch = control_dir.open_branch()
5172
 
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5173
 
        except errors.NotBranchError:
5174
 
            had_explicit_nick = False
 
5271
        branch = control_dir.open_branch()
5175
5272
        try:
5176
5273
            to_branch = Branch.open(to_location)
5177
5274
        except errors.NotBranchError:
5178
 
            this_url = self._get_branch_location(control_dir)
 
5275
            this_branch = control_dir.open_branch()
 
5276
            # This may be a heavy checkout, where we want the master branch
 
5277
            this_url = this_branch.get_bound_location()
 
5278
            # If not, use a local sibling
 
5279
            if this_url is None:
 
5280
                this_url = this_branch.base
5179
5281
            to_branch = Branch.open(
5180
5282
                urlutils.join(this_url, '..', to_location))
5181
5283
        switch.switch(control_dir, to_branch, force)
5182
 
        if had_explicit_nick:
 
5284
        if branch.get_config().has_explicit_nickname():
5183
5285
            branch = control_dir.open_branch() #get the new branch!
5184
5286
            branch.nick = to_branch.nick
5185
5287
        note('Switched to branch: %s',
5186
5288
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5187
5289
 
5188
 
    def _get_branch_location(self, control_dir):
5189
 
        """Return location of branch for this control dir."""
5190
 
        try:
5191
 
            this_branch = control_dir.open_branch()
5192
 
            # This may be a heavy checkout, where we want the master branch
5193
 
            master_location = this_branch.get_bound_location()
5194
 
            if master_location is not None:
5195
 
                return master_location
5196
 
            # If not, use a local sibling
5197
 
            return this_branch.base
5198
 
        except errors.NotBranchError:
5199
 
            format = control_dir.find_branch_format()
5200
 
            if getattr(format, 'get_reference', None) is not None:
5201
 
                return format.get_reference(control_dir)
5202
 
            else:
5203
 
                return control_dir.root_transport.base
5204
 
 
5205
5290
 
5206
5291
class cmd_view(Command):
5207
5292
    """Manage filtered views.