~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""builtin bzr commands"""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import os
20
22
 
21
23
import bzrlib.bzrdir
22
24
 
23
 
from bzrlib.lazy_import import lazy_import
24
 
lazy_import(globals(), """
 
25
from bzrlib import lazy_import
 
26
lazy_import.lazy_import(globals(), """
25
27
import cStringIO
26
28
import errno
27
29
import sys
1249
1251
        if location is None:
1250
1252
            stored_loc = br_from.get_push_location()
1251
1253
            if stored_loc is None:
1252
 
                raise errors.BzrCommandError(gettext(
1253
 
                    "No push location known or specified."))
 
1254
                parent_loc = br_from.get_parent()
 
1255
                if parent_loc:
 
1256
                    raise errors.BzrCommandError(gettext(
 
1257
                        "No push location known or specified. To push to the "
 
1258
                        "parent branch (at %s), use 'bzr push :parent'." %
 
1259
                        urlutils.unescape_for_display(parent_loc,
 
1260
                            self.outf.encoding)))
 
1261
                else:
 
1262
                    raise errors.BzrCommandError(gettext(
 
1263
                        "No push location known or specified."))
1254
1264
            else:
1255
1265
                display_url = urlutils.unescape_for_display(stored_loc,
1256
1266
                        self.outf.encoding)
1433
1443
                    self.outf.encoding).rstrip("/"))
1434
1444
        else:
1435
1445
            dir = controldir.ControlDir.open_containing(location)[0]
1436
 
            for branch in dir.list_branches():
1437
 
                if branch.name is None:
1438
 
                    self.outf.write(gettext(" (default)\n"))
 
1446
            try:
 
1447
                active_branch = dir.open_branch(name=None)
 
1448
            except errors.NotBranchError:
 
1449
                active_branch = None
 
1450
            branches = dir.get_branches()
 
1451
            names = {}
 
1452
            for name, branch in branches.iteritems():
 
1453
                if name is None:
 
1454
                    continue
 
1455
                active = (active_branch is not None and
 
1456
                          active_branch.base == branch.base)
 
1457
                names[name] = active
 
1458
            # Only mention the current branch explicitly if it's not
 
1459
            # one of the colocated branches
 
1460
            if not any(names.values()) and active_branch is not None:
 
1461
                self.outf.write("* %s\n" % gettext("(default)"))
 
1462
            for name in sorted(names.keys()):
 
1463
                active = names[name]
 
1464
                if active:
 
1465
                    prefix = "*"
1439
1466
                else:
1440
 
                    self.outf.write(" %s\n" % branch.name.encode(
1441
 
                        self.outf.encoding))
 
1467
                    prefix = " "
 
1468
                self.outf.write("%s %s\n" % (
 
1469
                    prefix, name.encode(self.outf.encoding)))
1442
1470
 
1443
1471
 
1444
1472
class cmd_checkout(Command):
2058
2086
            location = '.'
2059
2087
 
2060
2088
        to_transport = transport.get_transport(location)
2061
 
        to_transport.ensure_base()
2062
2089
 
2063
 
        newdir = format.initialize_on_transport(to_transport)
2064
 
        repo = newdir.create_repository(shared=True)
2065
 
        repo.set_make_working_trees(not no_trees)
 
2090
        (repo, newdir, require_stacking, repository_policy) = (
 
2091
            format.initialize_on_transport_ex(to_transport,
 
2092
            create_prefix=True, make_working_trees=not no_trees,
 
2093
            shared_repo=True, force_new_repo=True,
 
2094
            use_existing_dir=True,
 
2095
            repo_format_name=format.repository_format.get_format_string()))
2066
2096
        if not is_quiet():
2067
2097
            from bzrlib.info import show_bzrdir_info
2068
 
            show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
 
2098
            show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
2069
2099
 
2070
2100
 
2071
2101
class cmd_diff(Command):
3711
3741
            if directory is None:
3712
3742
                # use branch if we're inside one; otherwise global config
3713
3743
                try:
3714
 
                    c = Branch.open_containing(u'.')[0].get_config()
 
3744
                    c = Branch.open_containing(u'.')[0].get_config_stack()
3715
3745
                except errors.NotBranchError:
3716
 
                    c = _mod_config.GlobalConfig()
 
3746
                    c = _mod_config.GlobalStack()
3717
3747
            else:
3718
 
                c = Branch.open(directory).get_config()
 
3748
                c = Branch.open(directory).get_config_stack()
 
3749
            identity = c.get('email')
3719
3750
            if email:
3720
 
                self.outf.write(c.user_email() + '\n')
 
3751
                self.outf.write(_mod_config.extract_email_address(identity)
 
3752
                                + '\n')
3721
3753
            else:
3722
 
                self.outf.write(c.username() + '\n')
 
3754
                self.outf.write(identity + '\n')
3723
3755
            return
3724
3756
 
3725
3757
        if email:
3736
3768
        # use global config unless --branch given
3737
3769
        if branch:
3738
3770
            if directory is None:
3739
 
                c = Branch.open_containing(u'.')[0].get_config()
 
3771
                c = Branch.open_containing(u'.')[0].get_config_stack()
3740
3772
            else:
3741
 
                c = Branch.open(directory).get_config()
 
3773
                c = Branch.open(directory).get_config_stack()
3742
3774
        else:
3743
 
            c = _mod_config.GlobalConfig()
3744
 
        c.set_user_option('email', name)
 
3775
            c = _mod_config.GlobalStack()
 
3776
        c.set('email', name)
3745
3777
 
3746
3778
 
3747
3779
class cmd_nick(Command):
3972
4004
            load_list=None, debugflag=None, starting_with=None, subunit=False,
3973
4005
            parallel=None, lsprof_tests=False,
3974
4006
            sync=False):
 
4007
 
 
4008
        # During selftest, disallow proxying, as it can cause severe
 
4009
        # performance penalties and is only needed for thread
 
4010
        # safety. The selftest command is assumed to not use threads
 
4011
        # too heavily. The call should be as early as possible, as
 
4012
        # error reporting for past duplicate imports won't have useful
 
4013
        # backtraces.
 
4014
        lazy_import.disallow_proxying()
 
4015
 
3975
4016
        from bzrlib import tests
3976
4017
 
3977
4018
        if testspecs_list is not None:
4691
4732
 
4692
4733
    @display_command
4693
4734
    def run(self, context=None):
4694
 
        import shellcomplete
 
4735
        from bzrlib import shellcomplete
4695
4736
        shellcomplete.shellcomplete(context)
4696
4737
 
4697
4738
 
5055
5096
 
5056
5097
    def _run(self, b, revision_id_list, revision):
5057
5098
        import bzrlib.gpg as gpg
5058
 
        gpg_strategy = gpg.GPGStrategy(b.get_config())
 
5099
        gpg_strategy = gpg.GPGStrategy(b.get_config_stack())
5059
5100
        if revision_id_list is not None:
5060
5101
            b.repository.start_write_group()
5061
5102
            try:
5577
5618
                self.outf.writelines(directive.to_lines())
5578
5619
        else:
5579
5620
            message = directive.to_email(mail_to, branch, sign)
5580
 
            s = SMTPConnection(branch.get_config())
 
5621
            s = SMTPConnection(branch.get_config_stack())
5581
5622
            s.send_email(message)
5582
5623
 
5583
5624