/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 15:48:29 UTC
  • mfrom: (6289 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6337.
  • Revision ID: v.ladeuil+lp@free.fr-20111124154829-avowjpsxdl8yp2vz
merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
 
 
21
import bzrlib.bzrdir
 
22
 
21
23
from bzrlib.lazy_import import lazy_import
22
24
lazy_import(globals(), """
23
25
import cStringIO
29
31
    bugtracker,
30
32
    bundle,
31
33
    btree_index,
32
 
    bzrdir,
 
34
    controldir,
33
35
    directory_service,
34
36
    delta,
35
37
    config as _mod_config,
57
59
from bzrlib.revisionspec import RevisionSpec, RevisionInfo
58
60
from bzrlib.smtp_connection import SMTPConnection
59
61
from bzrlib.workingtree import WorkingTree
 
62
from bzrlib.i18n import gettext, ngettext
60
63
""")
61
64
 
62
65
from bzrlib.commands import (
112
115
            if view_files:
113
116
                file_list = view_files
114
117
                view_str = views.view_display_str(view_files)
115
 
                note("Ignoring files outside view. View is %s" % view_str)
 
118
                note(gettext("Ignoring files outside view. View is %s") % view_str)
116
119
    return tree, file_list
117
120
 
118
121
 
120
123
    if revisions is None:
121
124
        return None
122
125
    if len(revisions) != 1:
123
 
        raise errors.BzrCommandError(
124
 
            'bzr %s --revision takes exactly one revision identifier' % (
 
126
        raise errors.BzrCommandError(gettext(
 
127
            'bzr %s --revision takes exactly one revision identifier') % (
125
128
                command_name,))
126
129
    return revisions[0]
127
130
 
196
199
    the --directory option is used to specify a different branch."""
197
200
    if directory is not None:
198
201
        return (None, Branch.open(directory), filename)
199
 
    return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
202
    return controldir.ControlDir.open_containing_tree_or_branch(filename)
200
203
 
201
204
 
202
205
# TODO: Make sure no commands unconditionally use the working directory as a
288
291
        from bzrlib.status import show_tree_status
289
292
 
290
293
        if revision and len(revision) > 2:
291
 
            raise errors.BzrCommandError('bzr status --revision takes exactly'
292
 
                                         ' one or two revision specifiers')
 
294
            raise errors.BzrCommandError(gettext('bzr status --revision takes exactly'
 
295
                                         ' one or two revision specifiers'))
293
296
 
294
297
        tree, relfile_list = WorkingTree.open_containing_paths(file_list)
295
298
        # Avoid asking for specific files when that is not needed.
332
335
    @display_command
333
336
    def run(self, revision_id=None, revision=None, directory=u'.'):
334
337
        if revision_id is not None and revision is not None:
335
 
            raise errors.BzrCommandError('You can only supply one of'
336
 
                                         ' revision_id or --revision')
 
338
            raise errors.BzrCommandError(gettext('You can only supply one of'
 
339
                                         ' revision_id or --revision'))
337
340
        if revision_id is None and revision is None:
338
 
            raise errors.BzrCommandError('You must supply either'
339
 
                                         ' --revision or a revision_id')
 
341
            raise errors.BzrCommandError(gettext('You must supply either'
 
342
                                         ' --revision or a revision_id'))
340
343
 
341
 
        b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
 
344
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
342
345
 
343
346
        revisions = b.repository.revisions
344
347
        if revisions is None:
345
 
            raise errors.BzrCommandError('Repository %r does not support '
346
 
                'access to raw revision texts')
 
348
            raise errors.BzrCommandError(gettext('Repository %r does not support '
 
349
                'access to raw revision texts'))
347
350
 
348
351
        b.repository.lock_read()
349
352
        try:
353
356
                try:
354
357
                    self.print_revision(revisions, revision_id)
355
358
                except errors.NoSuchRevision:
356
 
                    msg = "The repository %s contains no revision %s." % (
 
359
                    msg = gettext("The repository {0} contains no revision {1}.").format(
357
360
                        b.repository.base, revision_id)
358
361
                    raise errors.BzrCommandError(msg)
359
362
            elif revision is not None:
360
363
                for rev in revision:
361
364
                    if rev is None:
362
365
                        raise errors.BzrCommandError(
363
 
                            'You cannot specify a NULL revision.')
 
366
                            gettext('You cannot specify a NULL revision.'))
364
367
                    rev_id = rev.as_revision_id(b)
365
368
                    self.print_revision(revisions, rev_id)
366
369
        finally:
472
475
            location_list=['.']
473
476
 
474
477
        for location in location_list:
475
 
            d = bzrdir.BzrDir.open(location)
476
 
            
 
478
            d = controldir.ControlDir.open(location)
 
479
 
477
480
            try:
478
481
                working = d.open_workingtree()
479
482
            except errors.NoWorkingTree:
480
 
                raise errors.BzrCommandError("No working tree to remove")
 
483
                raise errors.BzrCommandError(gettext("No working tree to remove"))
481
484
            except errors.NotLocalUrl:
482
 
                raise errors.BzrCommandError("You cannot remove the working tree"
483
 
                                             " of a remote path")
 
485
                raise errors.BzrCommandError(gettext("You cannot remove the working tree"
 
486
                                             " of a remote path"))
484
487
            if not force:
485
488
                if (working.has_changes()):
486
489
                    raise errors.UncommittedChanges(working)
488
491
                    raise errors.ShelvedChanges(working)
489
492
 
490
493
            if working.user_url != working.branch.user_url:
491
 
                raise errors.BzrCommandError("You cannot remove the working tree"
492
 
                                             " from a lightweight checkout")
 
494
                raise errors.BzrCommandError(gettext("You cannot remove the working tree"
 
495
                                             " from a lightweight checkout"))
493
496
 
494
497
            d.destroy_workingtree()
495
498
 
527
530
                pass # There seems to be a real error here, so we'll reset
528
531
            else:
529
532
                # Refuse
530
 
                raise errors.BzrCommandError(
 
533
                raise errors.BzrCommandError(gettext(
531
534
                    'The tree does not appear to be corrupt. You probably'
532
535
                    ' want "bzr revert" instead. Use "--force" if you are'
533
 
                    ' sure you want to reset the working tree.')
 
536
                    ' sure you want to reset the working tree.'))
534
537
        if revision is None:
535
538
            revision_ids = None
536
539
        else:
539
542
            tree.reset_state(revision_ids)
540
543
        except errors.BzrError, e:
541
544
            if revision_ids is None:
542
 
                extra = (', the header appears corrupt, try passing -r -1'
543
 
                         ' to set the state to the last commit')
 
545
                extra = (gettext(', the header appears corrupt, try passing -r -1'
 
546
                         ' to set the state to the last commit'))
544
547
            else:
545
548
                extra = ''
546
 
            raise errors.BzrCommandError('failed to reset the tree state'
547
 
                                         + extra)
 
549
            raise errors.BzrCommandError(gettext('failed to reset the tree state{0}').format(extra))
548
550
 
549
551
 
550
552
class cmd_revno(Command):
557
559
    takes_args = ['location?']
558
560
    takes_options = [
559
561
        Option('tree', help='Show revno of working tree'),
 
562
        'revision',
560
563
        ]
561
564
 
562
565
    @display_command
563
 
    def run(self, tree=False, location=u'.'):
 
566
    def run(self, tree=False, location=u'.', revision=None):
 
567
        if revision is not None and tree:
 
568
            raise errors.BzrCommandError(gettext("--tree and --revision can "
 
569
                "not be used together"))
 
570
 
564
571
        if tree:
565
572
            try:
566
573
                wt = WorkingTree.open_containing(location)[0]
567
574
                self.add_cleanup(wt.lock_read().unlock)
568
575
            except (errors.NoWorkingTree, errors.NotLocalUrl):
569
576
                raise errors.NoWorkingTree(location)
 
577
            b = wt.branch
570
578
            revid = wt.last_revision()
571
 
            try:
572
 
                revno_t = wt.branch.revision_id_to_dotted_revno(revid)
573
 
            except errors.NoSuchRevision:
574
 
                revno_t = ('???',)
575
 
            revno = ".".join(str(n) for n in revno_t)
576
579
        else:
577
580
            b = Branch.open_containing(location)[0]
578
581
            self.add_cleanup(b.lock_read().unlock)
579
 
            revno = b.revno()
 
582
            if revision:
 
583
                if len(revision) != 1:
 
584
                    raise errors.BzrCommandError(gettext(
 
585
                        "Tags can only be placed on a single revision, "
 
586
                        "not on a range"))
 
587
                revid = revision[0].as_revision_id(b)
 
588
            else:
 
589
                revid = b.last_revision()
 
590
        try:
 
591
            revno_t = b.revision_id_to_dotted_revno(revid)
 
592
        except errors.NoSuchRevision:
 
593
            revno_t = ('???',)
 
594
        revno = ".".join(str(n) for n in revno_t)
580
595
        self.cleanup_now()
581
 
        self.outf.write(str(revno) + '\n')
 
596
        self.outf.write(revno + '\n')
582
597
 
583
598
 
584
599
class cmd_revision_info(Command):
653
668
    are added.  This search proceeds recursively into versioned
654
669
    directories.  If no names are given '.' is assumed.
655
670
 
 
671
    A warning will be printed when nested trees are encountered,
 
672
    unless they are explicitly ignored.
 
673
 
656
674
    Therefore simply saying 'bzr add' will version all files that
657
675
    are currently unknown.
658
676
 
674
692
    
675
693
    Any files matching patterns in the ignore list will not be added
676
694
    unless they are explicitly mentioned.
 
695
    
 
696
    In recursive mode, files larger than the configuration option 
 
697
    add.maximum_file_size will be skipped. Named items are never skipped due
 
698
    to file size.
677
699
    """
678
700
    takes_args = ['file*']
679
701
    takes_options = [
706
728
            action = bzrlib.add.AddFromBaseAction(base_tree, base_path,
707
729
                          to_file=self.outf, should_print=(not is_quiet()))
708
730
        else:
709
 
            action = bzrlib.add.AddAction(to_file=self.outf,
 
731
            action = bzrlib.add.AddWithSkipLargeAction(to_file=self.outf,
710
732
                should_print=(not is_quiet()))
711
733
 
712
734
        if base_tree:
719
741
            if verbose:
720
742
                for glob in sorted(ignored.keys()):
721
743
                    for path in ignored[glob]:
722
 
                        self.outf.write("ignored %s matching \"%s\"\n"
723
 
                                        % (path, glob))
 
744
                        self.outf.write(
 
745
                         gettext("ignored {0} matching \"{1}\"\n").format(
 
746
                         path, glob))
724
747
 
725
748
 
726
749
class cmd_mkdir(Command):
740
763
            if id != None:
741
764
                os.mkdir(d)
742
765
                wt.add([dd])
743
 
                self.outf.write('added %s\n' % d)
 
766
                if not is_quiet():
 
767
                    self.outf.write(gettext('added %s\n') % d)
744
768
            else:
745
769
                raise errors.NotVersionedError(path=base)
746
770
 
784
808
    @display_command
785
809
    def run(self, revision=None, show_ids=False, kind=None, file_list=None):
786
810
        if kind and kind not in ['file', 'directory', 'symlink']:
787
 
            raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
 
811
            raise errors.BzrCommandError(gettext('invalid kind %r specified') % (kind,))
788
812
 
789
813
        revision = _get_one_revision('inventory', revision)
790
814
        work_tree, file_list = WorkingTree.open_containing_paths(file_list)
854
878
        if auto:
855
879
            return self.run_auto(names_list, after, dry_run)
856
880
        elif dry_run:
857
 
            raise errors.BzrCommandError('--dry-run requires --auto.')
 
881
            raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
858
882
        if names_list is None:
859
883
            names_list = []
860
884
        if len(names_list) < 2:
861
 
            raise errors.BzrCommandError("missing file argument")
 
885
            raise errors.BzrCommandError(gettext("missing file argument"))
862
886
        tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
 
887
        for file_name in rel_names[0:-1]:
 
888
            if file_name == '':
 
889
                raise errors.BzrCommandError(gettext("can not move root of branch"))
863
890
        self.add_cleanup(tree.lock_tree_write().unlock)
864
891
        self._run(tree, names_list, rel_names, after)
865
892
 
866
893
    def run_auto(self, names_list, after, dry_run):
867
894
        if names_list is not None and len(names_list) > 1:
868
 
            raise errors.BzrCommandError('Only one path may be specified to'
869
 
                                         ' --auto.')
 
895
            raise errors.BzrCommandError(gettext('Only one path may be specified to'
 
896
                                         ' --auto.'))
870
897
        if after:
871
 
            raise errors.BzrCommandError('--after cannot be specified with'
872
 
                                         ' --auto.')
 
898
            raise errors.BzrCommandError(gettext('--after cannot be specified with'
 
899
                                         ' --auto.'))
873
900
        work_tree, file_list = WorkingTree.open_containing_paths(
874
901
            names_list, default_directory='.')
875
902
        self.add_cleanup(work_tree.lock_tree_write().unlock)
905
932
                    self.outf.write("%s => %s\n" % (src, dest))
906
933
        else:
907
934
            if len(names_list) != 2:
908
 
                raise errors.BzrCommandError('to mv multiple files the'
 
935
                raise errors.BzrCommandError(gettext('to mv multiple files the'
909
936
                                             ' destination must be a versioned'
910
 
                                             ' directory')
 
937
                                             ' directory'))
911
938
 
912
939
            # for cicp file-systems: the src references an existing inventory
913
940
            # item:
973
1000
    branches have diverged.
974
1001
 
975
1002
    If there is no default location set, the first pull will set it (use
976
 
    --no-remember to avoid settting it). After that, you can omit the
 
1003
    --no-remember to avoid setting it). After that, you can omit the
977
1004
    location to use the default.  To change the default, use --remember. The
978
1005
    value will only be saved if the remote location can be accessed.
979
1006
 
 
1007
    The --verbose option will display the revisions pulled using the log_format
 
1008
    configuration option. You can use a different format by overriding it with
 
1009
    -Olog_format=<other_format>.
 
1010
 
980
1011
    Note: The location can be specified either in the form of a branch,
981
1012
    or in the form of a path to a file containing a merge directive generated
982
1013
    with bzr send.
1019
1050
            self.add_cleanup(branch_to.lock_write().unlock)
1020
1051
 
1021
1052
        if tree_to is None and show_base:
1022
 
            raise errors.BzrCommandError("Need working tree for --show-base.")
 
1053
            raise errors.BzrCommandError(gettext("Need working tree for --show-base."))
1023
1054
 
1024
1055
        if local and not branch_to.get_bound_location():
1025
1056
            raise errors.LocalRequiresBoundBranch()
1035
1066
        stored_loc = branch_to.get_parent()
1036
1067
        if location is None:
1037
1068
            if stored_loc is None:
1038
 
                raise errors.BzrCommandError("No pull location known or"
1039
 
                                             " specified.")
 
1069
                raise errors.BzrCommandError(gettext("No pull location known or"
 
1070
                                             " specified."))
1040
1071
            else:
1041
1072
                display_url = urlutils.unescape_for_display(stored_loc,
1042
1073
                        self.outf.encoding)
1043
1074
                if not is_quiet():
1044
 
                    self.outf.write("Using saved parent location: %s\n" % display_url)
 
1075
                    self.outf.write(gettext("Using saved parent location: %s\n") % display_url)
1045
1076
                location = stored_loc
1046
1077
 
1047
1078
        revision = _get_one_revision('pull', revision)
1048
1079
        if mergeable is not None:
1049
1080
            if revision is not None:
1050
 
                raise errors.BzrCommandError(
1051
 
                    'Cannot use -r with merge directives or bundles')
 
1081
                raise errors.BzrCommandError(gettext(
 
1082
                    'Cannot use -r with merge directives or bundles'))
1052
1083
            mergeable.install_revisions(branch_to.repository)
1053
1084
            base_revision_id, revision_id, verified = \
1054
1085
                mergeable.get_merge_request(branch_to.repository)
1072
1103
                view_info=view_info)
1073
1104
            result = tree_to.pull(
1074
1105
                branch_from, overwrite, revision_id, change_reporter,
1075
 
                possible_transports=possible_transports, local=local,
1076
 
                show_base=show_base)
 
1106
                local=local, show_base=show_base)
1077
1107
        else:
1078
1108
            result = branch_to.pull(
1079
1109
                branch_from, overwrite, revision_id, local=local)
1110
1140
    After that you will be able to do a push without '--overwrite'.
1111
1141
 
1112
1142
    If there is no default push location set, the first push will set it (use
1113
 
    --no-remember to avoid settting it).  After that, you can omit the
 
1143
    --no-remember to avoid setting it).  After that, you can omit the
1114
1144
    location to use the default.  To change the default, use --remember. The
1115
1145
    value will only be saved if the remote location can be accessed.
 
1146
 
 
1147
    The --verbose option will display the revisions pushed using the log_format
 
1148
    configuration option. You can use a different format by overriding it with
 
1149
    -Olog_format=<other_format>.
1116
1150
    """
1117
1151
 
1118
1152
    _see_also = ['pull', 'update', 'working-trees']
1156
1190
            directory = '.'
1157
1191
        # Get the source branch
1158
1192
        (tree, br_from,
1159
 
         _unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
 
1193
         _unused) = controldir.ControlDir.open_containing_tree_or_branch(directory)
1160
1194
        # Get the tip's revision_id
1161
1195
        revision = _get_one_revision('push', revision)
1162
1196
        if revision is not None:
1183
1217
                    # error by the feedback given to them. RBC 20080227.
1184
1218
                    stacked_on = parent_url
1185
1219
            if not stacked_on:
1186
 
                raise errors.BzrCommandError(
1187
 
                    "Could not determine branch to refer to.")
 
1220
                raise errors.BzrCommandError(gettext(
 
1221
                    "Could not determine branch to refer to."))
1188
1222
 
1189
1223
        # Get the destination location
1190
1224
        if location is None:
1191
1225
            stored_loc = br_from.get_push_location()
1192
1226
            if stored_loc is None:
1193
 
                raise errors.BzrCommandError(
1194
 
                    "No push location known or specified.")
 
1227
                raise errors.BzrCommandError(gettext(
 
1228
                    "No push location known or specified."))
1195
1229
            else:
1196
1230
                display_url = urlutils.unescape_for_display(stored_loc,
1197
1231
                        self.outf.encoding)
1198
 
                self.outf.write("Using saved push location: %s\n" % display_url)
 
1232
                note(gettext("Using saved push location: %s") % display_url)
1199
1233
                location = stored_loc
1200
1234
 
1201
1235
        _show_push_branch(br_from, revision_id, location, self.outf,
1259
1293
                deprecated_name=self.invoked_as,
1260
1294
                recommended_name='branch',
1261
1295
                deprecated_in_version='2.4')
1262
 
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
 
1296
        accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1263
1297
            from_location)
1264
1298
        if not (hardlink or files_from):
1265
1299
            # accelerator_tree is usually slower because you have to read N
1278
1312
            # RBC 20060209
1279
1313
            revision_id = br_from.last_revision()
1280
1314
        if to_location is None:
1281
 
            to_location = urlutils.derive_to_location(from_location)
 
1315
            to_location = getattr(br_from, "name", None)
 
1316
            if to_location is None:
 
1317
                to_location = urlutils.derive_to_location(from_location)
1282
1318
        to_transport = transport.get_transport(to_location)
1283
1319
        try:
1284
1320
            to_transport.mkdir('.')
1285
1321
        except errors.FileExists:
1286
 
            if not use_existing_dir:
1287
 
                raise errors.BzrCommandError('Target directory "%s" '
1288
 
                    'already exists.' % to_location)
 
1322
            try:
 
1323
                to_dir = controldir.ControlDir.open_from_transport(
 
1324
                    to_transport)
 
1325
            except errors.NotBranchError:
 
1326
                if not use_existing_dir:
 
1327
                    raise errors.BzrCommandError(gettext('Target directory "%s" '
 
1328
                        'already exists.') % to_location)
 
1329
                else:
 
1330
                    to_dir = None
1289
1331
            else:
1290
1332
                try:
1291
 
                    bzrdir.BzrDir.open_from_transport(to_transport)
 
1333
                    to_dir.open_branch()
1292
1334
                except errors.NotBranchError:
1293
1335
                    pass
1294
1336
                else:
1295
1337
                    raise errors.AlreadyBranchError(to_location)
1296
1338
        except errors.NoSuchFile:
1297
 
            raise errors.BzrCommandError('Parent of "%s" does not exist.'
 
1339
            raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1298
1340
                                         % to_location)
1299
 
        try:
1300
 
            # preserve whatever source format we have.
1301
 
            dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1302
 
                                        possible_transports=[to_transport],
1303
 
                                        accelerator_tree=accelerator_tree,
1304
 
                                        hardlink=hardlink, stacked=stacked,
1305
 
                                        force_new_repo=standalone,
1306
 
                                        create_tree_if_local=not no_tree,
1307
 
                                        source_branch=br_from)
1308
 
            branch = dir.open_branch()
1309
 
        except errors.NoSuchRevision:
1310
 
            to_transport.delete_tree('.')
1311
 
            msg = "The branch %s has no revision %s." % (from_location,
1312
 
                revision)
1313
 
            raise errors.BzrCommandError(msg)
 
1341
        else:
 
1342
            to_dir = None
 
1343
        if to_dir is None:
 
1344
            try:
 
1345
                # preserve whatever source format we have.
 
1346
                to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
 
1347
                                            possible_transports=[to_transport],
 
1348
                                            accelerator_tree=accelerator_tree,
 
1349
                                            hardlink=hardlink, stacked=stacked,
 
1350
                                            force_new_repo=standalone,
 
1351
                                            create_tree_if_local=not no_tree,
 
1352
                                            source_branch=br_from)
 
1353
                branch = to_dir.open_branch()
 
1354
            except errors.NoSuchRevision:
 
1355
                to_transport.delete_tree('.')
 
1356
                msg = gettext("The branch {0} has no revision {1}.").format(
 
1357
                    from_location, revision)
 
1358
                raise errors.BzrCommandError(msg)
 
1359
        else:
 
1360
            branch = br_from.sprout(to_dir, revision_id=revision_id)
1314
1361
        _merge_tags_if_possible(br_from, branch)
1315
1362
        # If the source branch is stacked, the new branch may
1316
1363
        # be stacked whether we asked for that explicitly or not.
1317
1364
        # We therefore need a try/except here and not just 'if stacked:'
1318
1365
        try:
1319
 
            note('Created new stacked branch referring to %s.' %
 
1366
            note(gettext('Created new stacked branch referring to %s.') %
1320
1367
                branch.get_stacked_on_url())
1321
1368
        except (errors.NotStacked, errors.UnstackableBranchFormat,
1322
1369
            errors.UnstackableRepositoryFormat), e:
1323
 
            note('Branched %d revision(s).' % branch.revno())
 
1370
            note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1324
1371
        if bind:
1325
1372
            # Bind to the parent
1326
1373
            parent_branch = Branch.open(from_location)
1327
1374
            branch.bind(parent_branch)
1328
 
            note('New branch bound to %s' % from_location)
 
1375
            note(gettext('New branch bound to %s') % from_location)
1329
1376
        if switch:
1330
1377
            # Switch to the new branch
1331
1378
            wt, _ = WorkingTree.open_containing('.')
1332
1379
            _mod_switch.switch(wt.bzrdir, branch)
1333
 
            note('Switched to branch: %s',
 
1380
            note(gettext('Switched to branch: %s'),
1334
1381
                urlutils.unescape_for_display(branch.base, 'utf-8'))
1335
1382
 
1336
1383
 
 
1384
class cmd_branches(Command):
 
1385
    __doc__ = """List the branches available at the current location.
 
1386
 
 
1387
    This command will print the names of all the branches at the current
 
1388
    location.
 
1389
    """
 
1390
 
 
1391
    takes_args = ['location?']
 
1392
    takes_options = [
 
1393
                  Option('recursive', short_name='R',
 
1394
                         help='Recursively scan for branches rather than '
 
1395
                              'just looking in the specified location.')]
 
1396
 
 
1397
    def run(self, location=".", recursive=False):
 
1398
        if recursive:
 
1399
            t = transport.get_transport(location)
 
1400
            if not t.listable():
 
1401
                raise errors.BzrCommandError(
 
1402
                    "Can't scan this type of location.")
 
1403
            for b in controldir.ControlDir.find_branches(t):
 
1404
                self.outf.write("%s\n" % urlutils.unescape_for_display(
 
1405
                    urlutils.relative_url(t.base, b.base),
 
1406
                    self.outf.encoding).rstrip("/"))
 
1407
        else:
 
1408
            dir = controldir.ControlDir.open_containing(location)[0]
 
1409
            for branch in dir.list_branches():
 
1410
                if branch.name is None:
 
1411
                    self.outf.write(gettext(" (default)\n"))
 
1412
                else:
 
1413
                    self.outf.write(" %s\n" % branch.name.encode(
 
1414
                        self.outf.encoding))
 
1415
 
 
1416
 
1337
1417
class cmd_checkout(Command):
1338
1418
    __doc__ = """Create a new checkout of an existing branch.
1339
1419
 
1378
1458
        if branch_location is None:
1379
1459
            branch_location = osutils.getcwd()
1380
1460
            to_location = branch_location
1381
 
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
 
1461
        accelerator_tree, source = controldir.ControlDir.open_tree_or_branch(
1382
1462
            branch_location)
1383
1463
        if not (hardlink or files_from):
1384
1464
            # accelerator_tree is usually slower because you have to read N
1439
1519
 
1440
1520
 
1441
1521
class cmd_update(Command):
1442
 
    __doc__ = """Update a tree to have the latest code committed to its branch.
1443
 
 
1444
 
    This will perform a merge into the working tree, and may generate
1445
 
    conflicts. If you have any local changes, you will still
1446
 
    need to commit them after the update for the update to be complete.
1447
 
 
1448
 
    If you want to discard your local changes, you can just do a
1449
 
    'bzr revert' instead of 'bzr commit' after the update.
1450
 
 
1451
 
    If you want to restore a file that has been removed locally, use
1452
 
    'bzr revert' instead of 'bzr update'.
1453
 
 
1454
 
    If the tree's branch is bound to a master branch, it will also update
 
1522
    __doc__ = """Update a working tree to a new revision.
 
1523
 
 
1524
    This will perform a merge of the destination revision (the tip of the
 
1525
    branch, or the specified revision) into the working tree, and then make
 
1526
    that revision the basis revision for the working tree.  
 
1527
 
 
1528
    You can use this to visit an older revision, or to update a working tree
 
1529
    that is out of date from its branch.
 
1530
    
 
1531
    If there are any uncommitted changes in the tree, they will be carried
 
1532
    across and remain as uncommitted changes after the update.  To discard
 
1533
    these changes, use 'bzr revert'.  The uncommitted changes may conflict
 
1534
    with the changes brought in by the change in basis revision.
 
1535
 
 
1536
    If the tree's branch is bound to a master branch, bzr will also update
1455
1537
    the branch from the master.
 
1538
 
 
1539
    You cannot update just a single file or directory, because each Bazaar
 
1540
    working tree has just a single basis revision.  If you want to restore a
 
1541
    file that has been removed locally, use 'bzr revert' instead of 'bzr
 
1542
    update'.  If you want to restore a file to its state in a previous
 
1543
    revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
 
1544
    out the old content of that file to a new location.
 
1545
 
 
1546
    The 'dir' argument, if given, must be the location of the root of a
 
1547
    working tree to update.  By default, the working tree that contains the 
 
1548
    current working directory is used.
1456
1549
    """
1457
1550
 
1458
1551
    _see_also = ['pull', 'working-trees', 'status-flags']
1463
1556
                     ]
1464
1557
    aliases = ['up']
1465
1558
 
1466
 
    def run(self, dir='.', revision=None, show_base=None):
 
1559
    def run(self, dir=None, revision=None, show_base=None):
1467
1560
        if revision is not None and len(revision) != 1:
1468
 
            raise errors.BzrCommandError(
1469
 
                        "bzr update --revision takes exactly one revision")
1470
 
        tree = WorkingTree.open_containing(dir)[0]
 
1561
            raise errors.BzrCommandError(gettext(
 
1562
                "bzr update --revision takes exactly one revision"))
 
1563
        if dir is None:
 
1564
            tree = WorkingTree.open_containing('.')[0]
 
1565
        else:
 
1566
            tree, relpath = WorkingTree.open_containing(dir)
 
1567
            if relpath:
 
1568
                # See bug 557886.
 
1569
                raise errors.BzrCommandError(gettext(
 
1570
                    "bzr update can only update a whole tree, "
 
1571
                    "not a file or subdirectory"))
1471
1572
        branch = tree.branch
1472
1573
        possible_transports = []
1473
1574
        master = branch.get_master_branch(
1497
1598
            revision_id = branch.last_revision()
1498
1599
        if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1499
1600
            revno = branch.revision_id_to_dotted_revno(revision_id)
1500
 
            note("Tree is up to date at revision %s of branch %s" %
1501
 
                ('.'.join(map(str, revno)), branch_location))
 
1601
            note(gettext("Tree is up to date at revision {0} of branch {1}"
 
1602
                        ).format('.'.join(map(str, revno)), branch_location))
1502
1603
            return 0
1503
1604
        view_info = _get_view_info_for_change_reporter(tree)
1504
1605
        change_reporter = delta._ChangeReporter(
1512
1613
                old_tip=old_tip,
1513
1614
                show_base=show_base)
1514
1615
        except errors.NoSuchRevision, e:
1515
 
            raise errors.BzrCommandError(
 
1616
            raise errors.BzrCommandError(gettext(
1516
1617
                                  "branch has no revision %s\n"
1517
1618
                                  "bzr update --revision only works"
1518
 
                                  " for a revision in the branch history"
 
1619
                                  " for a revision in the branch history")
1519
1620
                                  % (e.revision))
1520
1621
        revno = tree.branch.revision_id_to_dotted_revno(
1521
1622
            _mod_revision.ensure_null(tree.last_revision()))
1522
 
        note('Updated to revision %s of branch %s' %
1523
 
             ('.'.join(map(str, revno)), branch_location))
 
1623
        note(gettext('Updated to revision {0} of branch {1}').format(
 
1624
             '.'.join(map(str, revno)), branch_location))
1524
1625
        parent_ids = tree.get_parent_ids()
1525
1626
        if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1526
 
            note('Your local commits will now show as pending merges with '
1527
 
                 "'bzr status', and can be committed with 'bzr commit'.")
 
1627
            note(gettext('Your local commits will now show as pending merges with '
 
1628
                 "'bzr status', and can be committed with 'bzr commit'."))
1528
1629
        if conflicts != 0:
1529
1630
            return 1
1530
1631
        else:
1571
1672
        else:
1572
1673
            noise_level = 0
1573
1674
        from bzrlib.info import show_bzrdir_info
1574
 
        show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
 
1675
        show_bzrdir_info(controldir.ControlDir.open_containing(location)[0],
1575
1676
                         verbose=noise_level, outfile=self.outf)
1576
1677
 
1577
1678
 
1602
1703
    def run(self, file_list, verbose=False, new=False,
1603
1704
        file_deletion_strategy='safe'):
1604
1705
        if file_deletion_strategy == 'force':
1605
 
            note("(The --force option is deprecated, rather use --no-backup "
1606
 
                "in future.)")
 
1706
            note(gettext("(The --force option is deprecated, rather use --no-backup "
 
1707
                "in future.)"))
1607
1708
            file_deletion_strategy = 'no-backup'
1608
1709
 
1609
1710
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1619
1720
                specific_files=file_list).added
1620
1721
            file_list = sorted([f[0] for f in added], reverse=True)
1621
1722
            if len(file_list) == 0:
1622
 
                raise errors.BzrCommandError('No matching files.')
 
1723
                raise errors.BzrCommandError(gettext('No matching files.'))
1623
1724
        elif file_list is None:
1624
1725
            # missing files show up in iter_changes(basis) as
1625
1726
            # versioned-with-no-kind.
1709
1810
 
1710
1811
    def run(self, branch=".", canonicalize_chks=False):
1711
1812
        from bzrlib.reconcile import reconcile
1712
 
        dir = bzrdir.BzrDir.open(branch)
 
1813
        dir = controldir.ControlDir.open(branch)
1713
1814
        reconcile(dir, canonicalize_chks=canonicalize_chks)
1714
1815
 
1715
1816
 
1724
1825
    @display_command
1725
1826
    def run(self, location="."):
1726
1827
        branch = Branch.open_containing(location)[0]
1727
 
        for revid in branch.revision_history():
 
1828
        self.add_cleanup(branch.lock_read().unlock)
 
1829
        graph = branch.repository.get_graph()
 
1830
        history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
 
1831
            [_mod_revision.NULL_REVISION]))
 
1832
        for revid in reversed(history):
1728
1833
            self.outf.write(revid)
1729
1834
            self.outf.write('\n')
1730
1835
 
1791
1896
                help='Specify a format for this branch. '
1792
1897
                'See "help formats".',
1793
1898
                lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1794
 
                converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
1899
                converter=lambda name: controldir.format_registry.make_bzrdir(name),
1795
1900
                value_switches=True,
1796
1901
                title="Branch format",
1797
1902
                ),
1804
1909
    def run(self, location=None, format=None, append_revisions_only=False,
1805
1910
            create_prefix=False, no_tree=False):
1806
1911
        if format is None:
1807
 
            format = bzrdir.format_registry.make_bzrdir('default')
 
1912
            format = controldir.format_registry.make_bzrdir('default')
1808
1913
        if location is None:
1809
1914
            location = u'.'
1810
1915
 
1819
1924
            to_transport.ensure_base()
1820
1925
        except errors.NoSuchFile:
1821
1926
            if not create_prefix:
1822
 
                raise errors.BzrCommandError("Parent directory of %s"
 
1927
                raise errors.BzrCommandError(gettext("Parent directory of %s"
1823
1928
                    " does not exist."
1824
1929
                    "\nYou may supply --create-prefix to create all"
1825
 
                    " leading parent directories."
 
1930
                    " leading parent directories.")
1826
1931
                    % location)
1827
1932
            to_transport.create_prefix()
1828
1933
 
1829
1934
        try:
1830
 
            a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
 
1935
            a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
1831
1936
        except errors.NotBranchError:
1832
1937
            # really a NotBzrDir error...
1833
 
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1938
            create_branch = controldir.ControlDir.create_branch_convenience
1834
1939
            if no_tree:
1835
1940
                force_new_tree = False
1836
1941
            else:
1847
1952
                        raise errors.BranchExistsWithoutWorkingTree(location)
1848
1953
                raise errors.AlreadyBranchError(location)
1849
1954
            branch = a_bzrdir.create_branch()
1850
 
            if not no_tree:
 
1955
            if not no_tree and not a_bzrdir.has_workingtree():
1851
1956
                a_bzrdir.create_workingtree()
1852
1957
        if append_revisions_only:
1853
1958
            try:
1854
1959
                branch.set_append_revisions_only(True)
1855
1960
            except errors.UpgradeRequired:
1856
 
                raise errors.BzrCommandError('This branch format cannot be set'
1857
 
                    ' to append-revisions-only.  Try --default.')
 
1961
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
 
1962
                    ' to append-revisions-only.  Try --default.'))
1858
1963
        if not is_quiet():
1859
1964
            from bzrlib.info import describe_layout, describe_format
1860
1965
            try:
1864
1969
            repository = branch.repository
1865
1970
            layout = describe_layout(repository, branch, tree).lower()
1866
1971
            format = describe_format(a_bzrdir, repository, branch, tree)
1867
 
            self.outf.write("Created a %s (format: %s)\n" % (layout, format))
 
1972
            self.outf.write(gettext("Created a {0} (format: {1})\n").format(
 
1973
                  layout, format))
1868
1974
            if repository.is_shared():
1869
1975
                #XXX: maybe this can be refactored into transport.path_or_url()
1870
1976
                url = repository.bzrdir.root_transport.external_url()
1872
1978
                    url = urlutils.local_path_from_url(url)
1873
1979
                except errors.InvalidURL:
1874
1980
                    pass
1875
 
                self.outf.write("Using shared repository: %s\n" % url)
 
1981
                self.outf.write(gettext("Using shared repository: %s\n") % url)
1876
1982
 
1877
1983
 
1878
1984
class cmd_init_repository(Command):
1908
2014
    takes_options = [RegistryOption('format',
1909
2015
                            help='Specify a format for this repository. See'
1910
2016
                                 ' "bzr help formats" for details.',
1911
 
                            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1912
 
                            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
2017
                            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
2018
                            converter=lambda name: controldir.format_registry.make_bzrdir(name),
1913
2019
                            value_switches=True, title='Repository format'),
1914
2020
                     Option('no-trees',
1915
2021
                             help='Branches in the repository will default to'
1919
2025
 
1920
2026
    def run(self, location, format=None, no_trees=False):
1921
2027
        if format is None:
1922
 
            format = bzrdir.format_registry.make_bzrdir('default')
 
2028
            format = controldir.format_registry.make_bzrdir('default')
1923
2029
 
1924
2030
        if location is None:
1925
2031
            location = '.'
2069
2175
        elif ':' in prefix:
2070
2176
            old_label, new_label = prefix.split(":")
2071
2177
        else:
2072
 
            raise errors.BzrCommandError(
 
2178
            raise errors.BzrCommandError(gettext(
2073
2179
                '--prefix expects two values separated by a colon'
2074
 
                ' (eg "old/:new/")')
 
2180
                ' (eg "old/:new/")'))
2075
2181
 
2076
2182
        if revision and len(revision) > 2:
2077
 
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
2078
 
                                         ' one or two revision specifiers')
 
2183
            raise errors.BzrCommandError(gettext('bzr diff --revision takes exactly'
 
2184
                                         ' one or two revision specifiers'))
2079
2185
 
2080
2186
        if using is not None and format is not None:
2081
 
            raise errors.BzrCommandError('--using and --format are mutually '
2082
 
                'exclusive.')
 
2187
            raise errors.BzrCommandError(gettext(
 
2188
                '{0} and {1} are mutually exclusive').format(
 
2189
                '--using', '--format'))
2083
2190
 
2084
2191
        (old_tree, new_tree,
2085
2192
         old_branch, new_branch,
2193
2300
    try:
2194
2301
        return int(limitstring)
2195
2302
    except ValueError:
2196
 
        msg = "The limit argument must be an integer."
 
2303
        msg = gettext("The limit argument must be an integer.")
2197
2304
        raise errors.BzrCommandError(msg)
2198
2305
 
2199
2306
 
2201
2308
    try:
2202
2309
        return int(s)
2203
2310
    except ValueError:
2204
 
        msg = "The levels argument must be an integer."
 
2311
        msg = gettext("The levels argument must be an integer.")
2205
2312
        raise errors.BzrCommandError(msg)
2206
2313
 
2207
2314
 
2317
2424
 
2318
2425
    :Other filtering:
2319
2426
 
2320
 
      The --message option can be used for finding revisions that match a
2321
 
      regular expression in a commit message.
 
2427
      The --match option can be used for finding revisions that match a
 
2428
      regular expression in a commit message, committer, author or bug.
 
2429
      Specifying the option several times will match any of the supplied
 
2430
      expressions. --match-author, --match-bugs, --match-committer and
 
2431
      --match-message can be used to only match a specific field.
2322
2432
 
2323
2433
    :Tips & tricks:
2324
2434
 
2384
2494
                   argname='N',
2385
2495
                   type=_parse_levels),
2386
2496
            Option('message',
2387
 
                   short_name='m',
2388
2497
                   help='Show revisions whose message matches this '
2389
2498
                        'regular expression.',
2390
 
                   type=str),
 
2499
                   type=str,
 
2500
                   hidden=True),
2391
2501
            Option('limit',
2392
2502
                   short_name='l',
2393
2503
                   help='Limit the output to the first N revisions.',
2396
2506
            Option('show-diff',
2397
2507
                   short_name='p',
2398
2508
                   help='Show changes made in each revision as a patch.'),
2399
 
            Option('include-merges',
 
2509
            Option('include-merged',
2400
2510
                   help='Show merged revisions like --levels 0 does.'),
 
2511
            Option('include-merges', hidden=True,
 
2512
                   help='Historical alias for --include-merged.'),
 
2513
            Option('omit-merges',
 
2514
                   help='Do not report commits with more than one parent.'),
2401
2515
            Option('exclude-common-ancestry',
2402
2516
                   help='Display only the revisions that are not part'
2403
2517
                   ' of both ancestries (require -rX..Y)'
2404
2518
                   ),
2405
2519
            Option('signatures',
2406
2520
                   help='Show digital signature validity'),
 
2521
            ListOption('match',
 
2522
                short_name='m',
 
2523
                help='Show revisions whose properties match this '
 
2524
                'expression.',
 
2525
                type=str),
 
2526
            ListOption('match-message',
 
2527
                   help='Show revisions whose message matches this '
 
2528
                   'expression.',
 
2529
                type=str),
 
2530
            ListOption('match-committer',
 
2531
                   help='Show revisions whose committer matches this '
 
2532
                   'expression.',
 
2533
                type=str),
 
2534
            ListOption('match-author',
 
2535
                   help='Show revisions whose authors match this '
 
2536
                   'expression.',
 
2537
                type=str),
 
2538
            ListOption('match-bugs',
 
2539
                   help='Show revisions whose bugs match this '
 
2540
                   'expression.',
 
2541
                type=str)
2407
2542
            ]
2408
2543
    encoding_type = 'replace'
2409
2544
 
2419
2554
            message=None,
2420
2555
            limit=None,
2421
2556
            show_diff=False,
2422
 
            include_merges=False,
 
2557
            include_merged=None,
2423
2558
            authors=None,
2424
2559
            exclude_common_ancestry=False,
2425
2560
            signatures=False,
 
2561
            match=None,
 
2562
            match_message=None,
 
2563
            match_committer=None,
 
2564
            match_author=None,
 
2565
            match_bugs=None,
 
2566
            omit_merges=False,
 
2567
            include_merges=symbol_versioning.DEPRECATED_PARAMETER,
2426
2568
            ):
2427
2569
        from bzrlib.log import (
2428
2570
            Logger,
2430
2572
            _get_info_for_log_files,
2431
2573
            )
2432
2574
        direction = (forward and 'forward') or 'reverse'
 
2575
        if symbol_versioning.deprecated_passed(include_merges):
 
2576
            ui.ui_factory.show_user_warning(
 
2577
                'deprecated_command_option',
 
2578
                deprecated_name='--include-merges',
 
2579
                recommended_name='--include-merged',
 
2580
                deprecated_in_version='2.5',
 
2581
                command=self.invoked_as)
 
2582
            if include_merged is None:
 
2583
                include_merged = include_merges
 
2584
            else:
 
2585
                raise errors.BzrCommandError(gettext(
 
2586
                    '{0} and {1} are mutually exclusive').format(
 
2587
                    '--include-merges', '--include-merged'))
 
2588
        if include_merged is None:
 
2589
            include_merged = False
2433
2590
        if (exclude_common_ancestry
2434
2591
            and (revision is None or len(revision) != 2)):
2435
 
            raise errors.BzrCommandError(
2436
 
                '--exclude-common-ancestry requires -r with two revisions')
2437
 
        if include_merges:
 
2592
            raise errors.BzrCommandError(gettext(
 
2593
                '--exclude-common-ancestry requires -r with two revisions'))
 
2594
        if include_merged:
2438
2595
            if levels is None:
2439
2596
                levels = 0
2440
2597
            else:
2441
 
                raise errors.BzrCommandError(
2442
 
                    '--levels and --include-merges are mutually exclusive')
 
2598
                raise errors.BzrCommandError(gettext(
 
2599
                    '{0} and {1} are mutually exclusive').format(
 
2600
                    '--levels', '--include-merged'))
2443
2601
 
2444
2602
        if change is not None:
2445
2603
            if len(change) > 1:
2446
2604
                raise errors.RangeInChangeOption()
2447
2605
            if revision is not None:
2448
 
                raise errors.BzrCommandError(
2449
 
                    '--revision and --change are mutually exclusive')
 
2606
                raise errors.BzrCommandError(gettext(
 
2607
                    '{0} and {1} are mutually exclusive').format(
 
2608
                    '--revision', '--change'))
2450
2609
            else:
2451
2610
                revision = change
2452
2611
 
2458
2617
                revision, file_list, self.add_cleanup)
2459
2618
            for relpath, file_id, kind in file_info_list:
2460
2619
                if file_id is None:
2461
 
                    raise errors.BzrCommandError(
2462
 
                        "Path unknown at end or start of revision range: %s" %
 
2620
                    raise errors.BzrCommandError(gettext(
 
2621
                        "Path unknown at end or start of revision range: %s") %
2463
2622
                        relpath)
2464
2623
                # If the relpath is the top of the tree, we log everything
2465
2624
                if relpath == '':
2477
2636
                location = revision[0].get_branch()
2478
2637
            else:
2479
2638
                location = '.'
2480
 
            dir, relpath = bzrdir.BzrDir.open_containing(location)
 
2639
            dir, relpath = controldir.ControlDir.open_containing(location)
2481
2640
            b = dir.open_branch()
2482
2641
            self.add_cleanup(b.lock_read().unlock)
2483
2642
            rev1, rev2 = _get_revision_range(revision, b, self.name())
2531
2690
        match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2532
2691
            or delta_type or partial_history)
2533
2692
 
 
2693
        match_dict = {}
 
2694
        if match:
 
2695
            match_dict[''] = match
 
2696
        if match_message:
 
2697
            match_dict['message'] = match_message
 
2698
        if match_committer:
 
2699
            match_dict['committer'] = match_committer
 
2700
        if match_author:
 
2701
            match_dict['author'] = match_author
 
2702
        if match_bugs:
 
2703
            match_dict['bugs'] = match_bugs
 
2704
 
2534
2705
        # Build the LogRequest and execute it
2535
2706
        if len(file_ids) == 0:
2536
2707
            file_ids = None
2539
2710
            start_revision=rev1, end_revision=rev2, limit=limit,
2540
2711
            message_search=message, delta_type=delta_type,
2541
2712
            diff_type=diff_type, _match_using_deltas=match_using_deltas,
2542
 
            exclude_common_ancestry=exclude_common_ancestry,
2543
 
            signature=signatures
 
2713
            exclude_common_ancestry=exclude_common_ancestry, match=match_dict,
 
2714
            signature=signatures, omit_merges=omit_merges,
2544
2715
            )
2545
2716
        Logger(b, rqst).show(lf)
2546
2717
 
2563
2734
            # b is taken from revision[0].get_branch(), and
2564
2735
            # show_log will use its revision_history. Having
2565
2736
            # different branches will lead to weird behaviors.
2566
 
            raise errors.BzrCommandError(
 
2737
            raise errors.BzrCommandError(gettext(
2567
2738
                "bzr %s doesn't accept two revisions in different"
2568
 
                " branches." % command_name)
 
2739
                " branches.") % command_name)
2569
2740
        if start_spec.spec is None:
2570
2741
            # Avoid loading all the history.
2571
2742
            rev1 = RevisionInfo(branch, None, None)
2579
2750
        else:
2580
2751
            rev2 = end_spec.in_history(branch)
2581
2752
    else:
2582
 
        raise errors.BzrCommandError(
2583
 
            'bzr %s --revision takes one or two values.' % command_name)
 
2753
        raise errors.BzrCommandError(gettext(
 
2754
            'bzr %s --revision takes one or two values.') % command_name)
2584
2755
    return rev1, rev2
2585
2756
 
2586
2757
 
2657
2828
            null=False, kind=None, show_ids=False, path=None, directory=None):
2658
2829
 
2659
2830
        if kind and kind not in ('file', 'directory', 'symlink'):
2660
 
            raise errors.BzrCommandError('invalid kind specified')
 
2831
            raise errors.BzrCommandError(gettext('invalid kind specified'))
2661
2832
 
2662
2833
        if verbose and null:
2663
 
            raise errors.BzrCommandError('Cannot set both --verbose and --null')
 
2834
            raise errors.BzrCommandError(gettext('Cannot set both --verbose and --null'))
2664
2835
        all = not (unknown or versioned or ignored)
2665
2836
 
2666
2837
        selection = {'I':ignored, '?':unknown, 'V':versioned}
2669
2840
            fs_path = '.'
2670
2841
        else:
2671
2842
            if from_root:
2672
 
                raise errors.BzrCommandError('cannot specify both --from-root'
2673
 
                                             ' and PATH')
 
2843
                raise errors.BzrCommandError(gettext('cannot specify both --from-root'
 
2844
                                             ' and PATH'))
2674
2845
            fs_path = path
2675
2846
        tree, branch, relpath = \
2676
2847
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
2692
2863
            if view_files:
2693
2864
                apply_view = True
2694
2865
                view_str = views.view_display_str(view_files)
2695
 
                note("Ignoring files outside view. View is %s" % view_str)
 
2866
                note(gettext("Ignoring files outside view. View is %s") % view_str)
2696
2867
 
2697
2868
        self.add_cleanup(tree.lock_read().unlock)
2698
2869
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
2845
3016
                self.outf.write("%s\n" % pattern)
2846
3017
            return
2847
3018
        if not name_pattern_list:
2848
 
            raise errors.BzrCommandError("ignore requires at least one "
2849
 
                "NAME_PATTERN or --default-rules.")
 
3019
            raise errors.BzrCommandError(gettext("ignore requires at least one "
 
3020
                "NAME_PATTERN or --default-rules."))
2850
3021
        name_pattern_list = [globbing.normalize_pattern(p)
2851
3022
                             for p in name_pattern_list]
2852
3023
        bad_patterns = ''
 
3024
        bad_patterns_count = 0
2853
3025
        for p in name_pattern_list:
2854
3026
            if not globbing.Globster.is_pattern_valid(p):
 
3027
                bad_patterns_count += 1
2855
3028
                bad_patterns += ('\n  %s' % p)
2856
3029
        if bad_patterns:
2857
 
            msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
 
3030
            msg = (ngettext('Invalid ignore pattern found. %s', 
 
3031
                            'Invalid ignore patterns found. %s',
 
3032
                            bad_patterns_count) % bad_patterns)
2858
3033
            ui.ui_factory.show_error(msg)
2859
3034
            raise errors.InvalidPattern('')
2860
3035
        for name_pattern in name_pattern_list:
2861
3036
            if (name_pattern[0] == '/' or
2862
3037
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2863
 
                raise errors.BzrCommandError(
2864
 
                    "NAME_PATTERN should not be an absolute path")
 
3038
                raise errors.BzrCommandError(gettext(
 
3039
                    "NAME_PATTERN should not be an absolute path"))
2865
3040
        tree, relpath = WorkingTree.open_containing(directory)
2866
3041
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2867
3042
        ignored = globbing.Globster(name_pattern_list)
2874
3049
                if ignored.match(filename):
2875
3050
                    matches.append(filename)
2876
3051
        if len(matches) > 0:
2877
 
            self.outf.write("Warning: the following files are version controlled and"
2878
 
                  " match your ignore pattern:\n%s"
 
3052
            self.outf.write(gettext("Warning: the following files are version "
 
3053
                  "controlled and match your ignore pattern:\n%s"
2879
3054
                  "\nThese files will continue to be version controlled"
2880
 
                  " unless you 'bzr remove' them.\n" % ("\n".join(matches),))
 
3055
                  " unless you 'bzr remove' them.\n") % ("\n".join(matches),))
2881
3056
 
2882
3057
 
2883
3058
class cmd_ignored(Command):
2922
3097
        try:
2923
3098
            revno = int(revno)
2924
3099
        except ValueError:
2925
 
            raise errors.BzrCommandError("not a valid revision-number: %r"
 
3100
            raise errors.BzrCommandError(gettext("not a valid revision-number: %r")
2926
3101
                                         % revno)
2927
3102
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2928
3103
        self.outf.write("%s\n" % revid)
2989
3164
            export(rev_tree, dest, format, root, subdir, filtered=filters,
2990
3165
                   per_file_timestamps=per_file_timestamps)
2991
3166
        except errors.NoSuchExportFormat, e:
2992
 
            raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
 
3167
            raise errors.BzrCommandError(gettext('Unsupported export format: %s') % e.format)
2993
3168
 
2994
3169
 
2995
3170
class cmd_cat(Command):
3015
3190
    def run(self, filename, revision=None, name_from_revision=False,
3016
3191
            filters=False, directory=None):
3017
3192
        if revision is not None and len(revision) != 1:
3018
 
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
3019
 
                                         " one revision specifier")
 
3193
            raise errors.BzrCommandError(gettext("bzr cat --revision takes exactly"
 
3194
                                         " one revision specifier"))
3020
3195
        tree, branch, relpath = \
3021
3196
            _open_directory_or_containing_tree_or_branch(filename, directory)
3022
3197
        self.add_cleanup(branch.lock_read().unlock)
3032
3207
 
3033
3208
        old_file_id = rev_tree.path2id(relpath)
3034
3209
 
 
3210
        # TODO: Split out this code to something that generically finds the
 
3211
        # best id for a path across one or more trees; it's like
 
3212
        # find_ids_across_trees but restricted to find just one. -- mbp
 
3213
        # 20110705.
3035
3214
        if name_from_revision:
3036
3215
            # Try in revision if requested
3037
3216
            if old_file_id is None:
3038
 
                raise errors.BzrCommandError(
3039
 
                    "%r is not present in revision %s" % (
 
3217
                raise errors.BzrCommandError(gettext(
 
3218
                    "{0!r} is not present in revision {1}").format(
3040
3219
                        filename, rev_tree.get_revision_id()))
3041
3220
            else:
3042
 
                content = rev_tree.get_file_text(old_file_id)
 
3221
                actual_file_id = old_file_id
3043
3222
        else:
3044
3223
            cur_file_id = tree.path2id(relpath)
3045
 
            found = False
3046
 
            if cur_file_id is not None:
3047
 
                # Then try with the actual file id
3048
 
                try:
3049
 
                    content = rev_tree.get_file_text(cur_file_id)
3050
 
                    found = True
3051
 
                except errors.NoSuchId:
3052
 
                    # The actual file id didn't exist at that time
3053
 
                    pass
3054
 
            if not found and old_file_id is not None:
3055
 
                # Finally try with the old file id
3056
 
                content = rev_tree.get_file_text(old_file_id)
3057
 
                found = True
3058
 
            if not found:
3059
 
                # Can't be found anywhere
3060
 
                raise errors.BzrCommandError(
3061
 
                    "%r is not present in revision %s" % (
 
3224
            if cur_file_id is not None and rev_tree.has_id(cur_file_id):
 
3225
                actual_file_id = cur_file_id
 
3226
            elif old_file_id is not None:
 
3227
                actual_file_id = old_file_id
 
3228
            else:
 
3229
                raise errors.BzrCommandError(gettext(
 
3230
                    "{0!r} is not present in revision {1}").format(
3062
3231
                        filename, rev_tree.get_revision_id()))
3063
3232
        if filtered:
3064
 
            from bzrlib.filters import (
3065
 
                ContentFilterContext,
3066
 
                filtered_output_bytes,
3067
 
                )
3068
 
            filters = rev_tree._content_filter_stack(relpath)
3069
 
            chunks = content.splitlines(True)
3070
 
            content = filtered_output_bytes(chunks, filters,
3071
 
                ContentFilterContext(relpath, rev_tree))
3072
 
            self.cleanup_now()
3073
 
            self.outf.writelines(content)
 
3233
            from bzrlib.filter_tree import ContentFilterTree
 
3234
            filter_tree = ContentFilterTree(rev_tree,
 
3235
                rev_tree._content_filter_stack)
 
3236
            content = filter_tree.get_file_text(actual_file_id)
3074
3237
        else:
3075
 
            self.cleanup_now()
3076
 
            self.outf.write(content)
 
3238
            content = rev_tree.get_file_text(actual_file_id)
 
3239
        self.cleanup_now()
 
3240
        self.outf.write(content)
3077
3241
 
3078
3242
 
3079
3243
class cmd_local_time_offset(Command):
3186
3350
    aliases = ['ci', 'checkin']
3187
3351
 
3188
3352
    def _iter_bug_fix_urls(self, fixes, branch):
 
3353
        default_bugtracker  = None
3189
3354
        # Configure the properties for bug fixing attributes.
3190
3355
        for fixed_bug in fixes:
3191
3356
            tokens = fixed_bug.split(':')
3192
 
            if len(tokens) != 2:
3193
 
                raise errors.BzrCommandError(
 
3357
            if len(tokens) == 1:
 
3358
                if default_bugtracker is None:
 
3359
                    branch_config = branch.get_config()
 
3360
                    default_bugtracker = branch_config.get_user_option(
 
3361
                        "bugtracker")
 
3362
                if default_bugtracker is None:
 
3363
                    raise errors.BzrCommandError(gettext(
 
3364
                        "No tracker specified for bug %s. Use the form "
 
3365
                        "'tracker:id' or specify a default bug tracker "
 
3366
                        "using the `bugtracker` option.\nSee "
 
3367
                        "\"bzr help bugs\" for more information on this "
 
3368
                        "feature. Commit refused.") % fixed_bug)
 
3369
                tag = default_bugtracker
 
3370
                bug_id = tokens[0]
 
3371
            elif len(tokens) != 2:
 
3372
                raise errors.BzrCommandError(gettext(
3194
3373
                    "Invalid bug %s. Must be in the form of 'tracker:id'. "
3195
3374
                    "See \"bzr help bugs\" for more information on this "
3196
 
                    "feature.\nCommit refused." % fixed_bug)
3197
 
            tag, bug_id = tokens
 
3375
                    "feature.\nCommit refused.") % fixed_bug)
 
3376
            else:
 
3377
                tag, bug_id = tokens
3198
3378
            try:
3199
3379
                yield bugtracker.get_bug_url(tag, branch, bug_id)
3200
3380
            except errors.UnknownBugTrackerAbbreviation:
3201
 
                raise errors.BzrCommandError(
3202
 
                    'Unrecognized bug %s. Commit refused.' % fixed_bug)
 
3381
                raise errors.BzrCommandError(gettext(
 
3382
                    'Unrecognized bug %s. Commit refused.') % fixed_bug)
3203
3383
            except errors.MalformedBugIdentifier, e:
3204
 
                raise errors.BzrCommandError(
3205
 
                    "%s\nCommit refused." % (str(e),))
 
3384
                raise errors.BzrCommandError(gettext(
 
3385
                    "%s\nCommit refused.") % (str(e),))
3206
3386
 
3207
3387
    def run(self, message=None, file=None, verbose=False, selected_list=None,
3208
3388
            unchanged=False, strict=False, local=False, fixes=None,
3225
3405
            try:
3226
3406
                commit_stamp, offset = timestamp.parse_patch_date(commit_time)
3227
3407
            except ValueError, e:
3228
 
                raise errors.BzrCommandError(
3229
 
                    "Could not parse --commit-time: " + str(e))
 
3408
                raise errors.BzrCommandError(gettext(
 
3409
                    "Could not parse --commit-time: " + str(e)))
3230
3410
 
3231
3411
        properties = {}
3232
3412
 
3265
3445
                message = message.replace('\r\n', '\n')
3266
3446
                message = message.replace('\r', '\n')
3267
3447
            if file:
3268
 
                raise errors.BzrCommandError(
3269
 
                    "please specify either --message or --file")
 
3448
                raise errors.BzrCommandError(gettext(
 
3449
                    "please specify either --message or --file"))
3270
3450
 
3271
3451
        def get_message(commit_obj):
3272
3452
            """Callback to get commit message"""
3295
3475
                    my_message = edit_commit_message_encoded(text,
3296
3476
                        start_message=start_message)
3297
3477
                if my_message is None:
3298
 
                    raise errors.BzrCommandError("please specify a commit"
3299
 
                        " message with either --message or --file")
3300
 
            if my_message == "":
3301
 
                raise errors.BzrCommandError("empty commit message specified")
 
3478
                    raise errors.BzrCommandError(gettext("please specify a commit"
 
3479
                        " message with either --message or --file"))
 
3480
                if my_message == "":
 
3481
                    raise errors.BzrCommandError(gettext("Empty commit message specified."
 
3482
                            " Please specify a commit message with either"
 
3483
                            " --message or --file or leave a blank message"
 
3484
                            " with --message \"\"."))
3302
3485
            return my_message
3303
3486
 
3304
3487
        # The API permits a commit with a filter of [] to mean 'select nothing'
3315
3498
                        exclude=tree.safe_relpath_files(exclude),
3316
3499
                        lossy=lossy)
3317
3500
        except PointlessCommit:
3318
 
            raise errors.BzrCommandError("No changes to commit."
 
3501
            raise errors.BzrCommandError(gettext("No changes to commit."
3319
3502
                " Please 'bzr add' the files you want to commit, or use"
3320
 
                " --unchanged to force an empty commit.")
 
3503
                " --unchanged to force an empty commit."))
3321
3504
        except ConflictsInTree:
3322
 
            raise errors.BzrCommandError('Conflicts detected in working '
 
3505
            raise errors.BzrCommandError(gettext('Conflicts detected in working '
3323
3506
                'tree.  Use "bzr conflicts" to list, "bzr resolve FILE" to'
3324
 
                ' resolve.')
 
3507
                ' resolve.'))
3325
3508
        except StrictCommitFailed:
3326
 
            raise errors.BzrCommandError("Commit refused because there are"
3327
 
                              " unknown files in the working tree.")
 
3509
            raise errors.BzrCommandError(gettext("Commit refused because there are"
 
3510
                              " unknown files in the working tree."))
3328
3511
        except errors.BoundBranchOutOfDate, e:
3329
 
            e.extra_help = ("\n"
 
3512
            e.extra_help = (gettext("\n"
3330
3513
                'To commit to master branch, run update and then commit.\n'
3331
3514
                'You can also pass --local to commit to continue working '
3332
 
                'disconnected.')
 
3515
                'disconnected.'))
3333
3516
            raise
3334
3517
 
3335
3518
 
3442
3625
        RegistryOption('format',
3443
3626
            help='Upgrade to a specific format.  See "bzr help'
3444
3627
                 ' formats" for details.',
3445
 
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3446
 
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3628
            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
3629
            converter=lambda name: controldir.format_registry.make_bzrdir(name),
3447
3630
            value_switches=True, title='Branch format'),
3448
3631
        Option('clean',
3449
3632
            help='Remove the backup.bzr directory if successful.'),
3502
3685
            return
3503
3686
 
3504
3687
        if email:
3505
 
            raise errors.BzrCommandError("--email can only be used to display existing "
3506
 
                                         "identity")
 
3688
            raise errors.BzrCommandError(gettext("--email can only be used to display existing "
 
3689
                                         "identity"))
3507
3690
 
3508
3691
        # display a warning if an email address isn't included in the given name.
3509
3692
        try:
3588
3771
 
3589
3772
    def remove_alias(self, alias_name):
3590
3773
        if alias_name is None:
3591
 
            raise errors.BzrCommandError(
3592
 
                'bzr alias --remove expects an alias to remove.')
 
3774
            raise errors.BzrCommandError(gettext(
 
3775
                'bzr alias --remove expects an alias to remove.'))
3593
3776
        # If alias is not found, print something like:
3594
3777
        # unalias: foo: not found
3595
3778
        c = _mod_config.GlobalConfig()
3761
3944
            try:
3762
3945
                from bzrlib.tests import SubUnitBzrRunner
3763
3946
            except ImportError:
3764
 
                raise errors.BzrCommandError("subunit not available. subunit "
3765
 
                    "needs to be installed to use --subunit.")
 
3947
                raise errors.BzrCommandError(gettext("subunit not available. subunit "
 
3948
                    "needs to be installed to use --subunit."))
3766
3949
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3767
3950
            # On Windows, disable automatic conversion of '\n' to '\r\n' in
3768
3951
            # stdout, which would corrupt the subunit stream. 
3777
3960
            self.additional_selftest_args.setdefault(
3778
3961
                'suite_decorators', []).append(parallel)
3779
3962
        if benchmark:
3780
 
            raise errors.BzrCommandError(
 
3963
            raise errors.BzrCommandError(gettext(
3781
3964
                "--benchmark is no longer supported from bzr 2.2; "
3782
 
                "use bzr-usertest instead")
 
3965
                "use bzr-usertest instead"))
3783
3966
        test_suite_factory = None
3784
3967
        if not exclude:
3785
3968
            exclude_pattern = None
3848
4031
 
3849
4032
    @display_command
3850
4033
    def run(self):
3851
 
        self.outf.write("It sure does!\n")
 
4034
        self.outf.write(gettext("It sure does!\n"))
3852
4035
 
3853
4036
 
3854
4037
class cmd_find_merge_base(Command):
3872
4055
        graph = branch1.repository.get_graph(branch2.repository)
3873
4056
        base_rev_id = graph.find_unique_lca(last1, last2)
3874
4057
 
3875
 
        self.outf.write('merge base is revision %s\n' % base_rev_id)
 
4058
        self.outf.write(gettext('merge base is revision %s\n') % base_rev_id)
3876
4059
 
3877
4060
 
3878
4061
class cmd_merge(Command):
3911
4094
    Use bzr resolve when you have fixed a problem.  See also bzr conflicts.
3912
4095
 
3913
4096
    If there is no default branch set, the first merge will set it (use
3914
 
    --no-remember to avoid settting it). After that, you can omit the branch
 
4097
    --no-remember to avoid setting it). After that, you can omit the branch
3915
4098
    to use the default.  To change the default, use --remember. The value will
3916
4099
    only be saved if the remote location can be accessed.
3917
4100
 
4003
4186
 
4004
4187
        tree = WorkingTree.open_containing(directory)[0]
4005
4188
        if tree.branch.revno() == 0:
4006
 
            raise errors.BzrCommandError('Merging into empty branches not currently supported, '
4007
 
                                         'https://bugs.launchpad.net/bzr/+bug/308562')
 
4189
            raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
 
4190
                                         'https://bugs.launchpad.net/bzr/+bug/308562'))
4008
4191
 
4009
4192
        try:
4010
4193
            basis_tree = tree.revision_tree(tree.last_revision())
4030
4213
                mergeable = None
4031
4214
            else:
4032
4215
                if uncommitted:
4033
 
                    raise errors.BzrCommandError('Cannot use --uncommitted'
4034
 
                        ' with bundles or merge directives.')
 
4216
                    raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
 
4217
                        ' with bundles or merge directives.'))
4035
4218
 
4036
4219
                if revision is not None:
4037
 
                    raise errors.BzrCommandError(
4038
 
                        'Cannot use -r with merge directives or bundles')
 
4220
                    raise errors.BzrCommandError(gettext(
 
4221
                        'Cannot use -r with merge directives or bundles'))
4039
4222
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
4040
4223
                   mergeable, None)
4041
4224
 
4042
4225
        if merger is None and uncommitted:
4043
4226
            if revision is not None and len(revision) > 0:
4044
 
                raise errors.BzrCommandError('Cannot use --uncommitted and'
4045
 
                    ' --revision at the same time.')
 
4227
                raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
 
4228
                    ' --revision at the same time.'))
4046
4229
            merger = self.get_merger_from_uncommitted(tree, location, None)
4047
4230
            allow_pending = False
4048
4231
 
4061
4244
            if merger.interesting_files:
4062
4245
                if not merger.other_tree.has_filename(
4063
4246
                    merger.interesting_files[0]):
4064
 
                    note("merger: " + str(merger))
 
4247
                    note(gettext("merger: ") + str(merger))
4065
4248
                    raise errors.PathsDoNotExist([location])
4066
 
            note('Nothing to do.')
 
4249
            note(gettext('Nothing to do.'))
4067
4250
            return 0
4068
4251
        if pull and not preview:
4069
4252
            if merger.interesting_files is not None:
4070
 
                raise errors.BzrCommandError('Cannot pull individual files')
 
4253
                raise errors.BzrCommandError(gettext('Cannot pull individual files'))
4071
4254
            if (merger.base_rev_id == tree.last_revision()):
4072
4255
                result = tree.pull(merger.other_branch, False,
4073
4256
                                   merger.other_rev_id)
4074
4257
                result.report(self.outf)
4075
4258
                return 0
4076
4259
        if merger.this_basis is None:
4077
 
            raise errors.BzrCommandError(
 
4260
            raise errors.BzrCommandError(gettext(
4078
4261
                "This branch has no commits."
4079
 
                " (perhaps you would prefer 'bzr pull')")
 
4262
                " (perhaps you would prefer 'bzr pull')"))
4080
4263
        if preview:
4081
4264
            return self._do_preview(merger)
4082
4265
        elif interactive:
4133
4316
    def sanity_check_merger(self, merger):
4134
4317
        if (merger.show_base and
4135
4318
            not merger.merge_type is _mod_merge.Merge3Merger):
4136
 
            raise errors.BzrCommandError("Show-base is not supported for this"
4137
 
                                         " merge type. %s" % merger.merge_type)
 
4319
            raise errors.BzrCommandError(gettext("Show-base is not supported for this"
 
4320
                                         " merge type. %s") % merger.merge_type)
4138
4321
        if merger.reprocess is None:
4139
4322
            if merger.show_base:
4140
4323
                merger.reprocess = False
4142
4325
                # Use reprocess if the merger supports it
4143
4326
                merger.reprocess = merger.merge_type.supports_reprocess
4144
4327
        if merger.reprocess and not merger.merge_type.supports_reprocess:
4145
 
            raise errors.BzrCommandError("Conflict reduction is not supported"
4146
 
                                         " for merge type %s." %
 
4328
            raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
 
4329
                                         " for merge type %s.") %
4147
4330
                                         merger.merge_type)
4148
4331
        if merger.reprocess and merger.show_base:
4149
 
            raise errors.BzrCommandError("Cannot do conflict reduction and"
4150
 
                                         " show base.")
 
4332
            raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
 
4333
                                         " show base."))
4151
4334
 
4152
4335
    def _get_merger_from_branch(self, tree, location, revision, remember,
4153
4336
                                possible_transports, pb):
4257
4440
            stored_location_type = "parent"
4258
4441
        mutter("%s", stored_location)
4259
4442
        if stored_location is None:
4260
 
            raise errors.BzrCommandError("No location specified or remembered")
 
4443
            raise errors.BzrCommandError(gettext("No location specified or remembered"))
4261
4444
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4262
 
        note(u"%s remembered %s location %s", verb_string,
4263
 
                stored_location_type, display_url)
 
4445
        note(gettext("{0} remembered {1} location {2}").format(verb_string,
 
4446
                stored_location_type, display_url))
4264
4447
        return stored_location
4265
4448
 
4266
4449
 
4303
4486
        self.add_cleanup(tree.lock_write().unlock)
4304
4487
        parents = tree.get_parent_ids()
4305
4488
        if len(parents) != 2:
4306
 
            raise errors.BzrCommandError("Sorry, remerge only works after normal"
 
4489
            raise errors.BzrCommandError(gettext("Sorry, remerge only works after normal"
4307
4490
                                         " merges.  Not cherrypicking or"
4308
 
                                         " multi-merges.")
 
4491
                                         " multi-merges."))
4309
4492
        repository = tree.branch.repository
4310
4493
        interesting_ids = None
4311
4494
        new_conflicts = []
4530
4713
            type=_parse_revision_str,
4531
4714
            help='Filter on local branch revisions (inclusive). '
4532
4715
                'See "help revisionspec" for details.'),
4533
 
        Option('include-merges',
 
4716
        Option('include-merged',
4534
4717
               'Show all revisions in addition to the mainline ones.'),
 
4718
        Option('include-merges', hidden=True,
 
4719
               help='Historical alias for --include-merged.'),
4535
4720
        ]
4536
4721
    encoding_type = 'replace'
4537
4722
 
4540
4725
            theirs_only=False,
4541
4726
            log_format=None, long=False, short=False, line=False,
4542
4727
            show_ids=False, verbose=False, this=False, other=False,
4543
 
            include_merges=False, revision=None, my_revision=None,
4544
 
            directory=u'.'):
 
4728
            include_merged=None, revision=None, my_revision=None,
 
4729
            directory=u'.',
 
4730
            include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4545
4731
        from bzrlib.missing import find_unmerged, iter_log_revisions
4546
4732
        def message(s):
4547
4733
            if not is_quiet():
4548
4734
                self.outf.write(s)
4549
4735
 
 
4736
        if symbol_versioning.deprecated_passed(include_merges):
 
4737
            ui.ui_factory.show_user_warning(
 
4738
                'deprecated_command_option',
 
4739
                deprecated_name='--include-merges',
 
4740
                recommended_name='--include-merged',
 
4741
                deprecated_in_version='2.5',
 
4742
                command=self.invoked_as)
 
4743
            if include_merged is None:
 
4744
                include_merged = include_merges
 
4745
            else:
 
4746
                raise errors.BzrCommandError(gettext(
 
4747
                    '{0} and {1} are mutually exclusive').format(
 
4748
                    '--include-merges', '--include-merged'))
 
4749
        if include_merged is None:
 
4750
            include_merged = False
4550
4751
        if this:
4551
4752
            mine_only = this
4552
4753
        if other:
4567
4768
        if other_branch is None:
4568
4769
            other_branch = parent
4569
4770
            if other_branch is None:
4570
 
                raise errors.BzrCommandError("No peer location known"
4571
 
                                             " or specified.")
 
4771
                raise errors.BzrCommandError(gettext("No peer location known"
 
4772
                                             " or specified."))
4572
4773
            display_url = urlutils.unescape_for_display(parent,
4573
4774
                                                        self.outf.encoding)
4574
 
            message("Using saved parent location: "
4575
 
                    + display_url + "\n")
 
4775
            message(gettext("Using saved parent location: {0}\n").format(
 
4776
                    display_url))
4576
4777
 
4577
4778
        remote_branch = Branch.open(other_branch)
4578
4779
        if remote_branch.base == local_branch.base:
4591
4792
        local_extra, remote_extra = find_unmerged(
4592
4793
            local_branch, remote_branch, restrict,
4593
4794
            backward=not reverse,
4594
 
            include_merges=include_merges,
 
4795
            include_merged=include_merged,
4595
4796
            local_revid_range=local_revid_range,
4596
4797
            remote_revid_range=remote_revid_range)
4597
4798
 
4604
4805
 
4605
4806
        status_code = 0
4606
4807
        if local_extra and not theirs_only:
4607
 
            message("You have %d extra revision(s):\n" %
 
4808
            message(ngettext("You have %d extra revision:\n",
 
4809
                             "You have %d extra revisions:\n", 
 
4810
                             len(local_extra)) %
4608
4811
                len(local_extra))
4609
4812
            for revision in iter_log_revisions(local_extra,
4610
4813
                                local_branch.repository,
4618
4821
        if remote_extra and not mine_only:
4619
4822
            if printed_local is True:
4620
4823
                message("\n\n\n")
4621
 
            message("You are missing %d revision(s):\n" %
 
4824
            message(ngettext("You are missing %d revision:\n",
 
4825
                             "You are missing %d revisions:\n",
 
4826
                             len(remote_extra)) %
4622
4827
                len(remote_extra))
4623
4828
            for revision in iter_log_revisions(remote_extra,
4624
4829
                                remote_branch.repository,
4628
4833
 
4629
4834
        if mine_only and not local_extra:
4630
4835
            # We checked local, and found nothing extra
4631
 
            message('This branch is up to date.\n')
 
4836
            message(gettext('This branch has no new revisions.\n'))
4632
4837
        elif theirs_only and not remote_extra:
4633
4838
            # We checked remote, and found nothing extra
4634
 
            message('Other branch is up to date.\n')
 
4839
            message(gettext('Other branch has no new revisions.\n'))
4635
4840
        elif not (mine_only or theirs_only or local_extra or
4636
4841
                  remote_extra):
4637
4842
            # We checked both branches, and neither one had extra
4638
4843
            # revisions
4639
 
            message("Branches are up to date.\n")
 
4844
            message(gettext("Branches are up to date.\n"))
4640
4845
        self.cleanup_now()
4641
4846
        if not status_code and parent is None and other_branch is not None:
4642
4847
            self.add_cleanup(local_branch.lock_write().unlock)
4672
4877
        ]
4673
4878
 
4674
4879
    def run(self, branch_or_repo='.', clean_obsolete_packs=False):
4675
 
        dir = bzrdir.BzrDir.open_containing(branch_or_repo)[0]
 
4880
        dir = controldir.ControlDir.open_containing(branch_or_repo)[0]
4676
4881
        try:
4677
4882
            branch = dir.open_branch()
4678
4883
            repository = branch.repository
4803
5008
 
4804
5009
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
4805
5010
        if revision_id_list is not None and revision is not None:
4806
 
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
 
5011
            raise errors.BzrCommandError(gettext('You can only supply one of revision_id or --revision'))
4807
5012
        if revision_id_list is None and revision is None:
4808
 
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
 
5013
            raise errors.BzrCommandError(gettext('You must supply either --revision or a revision_id'))
4809
5014
        b = WorkingTree.open_containing(directory)[0].branch
4810
5015
        self.add_cleanup(b.lock_write().unlock)
4811
5016
        return self._run(b, revision_id_list, revision)
4843
5048
                if to_revid is None:
4844
5049
                    to_revno = b.revno()
4845
5050
                if from_revno is None or to_revno is None:
4846
 
                    raise errors.BzrCommandError('Cannot sign a range of non-revision-history revisions')
 
5051
                    raise errors.BzrCommandError(gettext('Cannot sign a range of non-revision-history revisions'))
4847
5052
                b.repository.start_write_group()
4848
5053
                try:
4849
5054
                    for revno in range(from_revno, to_revno + 1):
4855
5060
                else:
4856
5061
                    b.repository.commit_write_group()
4857
5062
            else:
4858
 
                raise errors.BzrCommandError('Please supply either one revision, or a range.')
 
5063
                raise errors.BzrCommandError(gettext('Please supply either one revision, or a range.'))
4859
5064
 
4860
5065
 
4861
5066
class cmd_bind(Command):
4880
5085
            try:
4881
5086
                location = b.get_old_bound_location()
4882
5087
            except errors.UpgradeRequired:
4883
 
                raise errors.BzrCommandError('No location supplied.  '
4884
 
                    'This format does not remember old locations.')
 
5088
                raise errors.BzrCommandError(gettext('No location supplied.  '
 
5089
                    'This format does not remember old locations.'))
4885
5090
            else:
4886
5091
                if location is None:
4887
5092
                    if b.get_bound_location() is not None:
4888
 
                        raise errors.BzrCommandError('Branch is already bound')
 
5093
                        raise errors.BzrCommandError(gettext('Branch is already bound'))
4889
5094
                    else:
4890
 
                        raise errors.BzrCommandError('No location supplied '
4891
 
                            'and no previous location known')
 
5095
                        raise errors.BzrCommandError(gettext('No location supplied '
 
5096
                            'and no previous location known'))
4892
5097
        b_other = Branch.open(location)
4893
5098
        try:
4894
5099
            b.bind(b_other)
4895
5100
        except errors.DivergedBranches:
4896
 
            raise errors.BzrCommandError('These branches have diverged.'
4897
 
                                         ' Try merging, and then bind again.')
 
5101
            raise errors.BzrCommandError(gettext('These branches have diverged.'
 
5102
                                         ' Try merging, and then bind again.'))
4898
5103
        if b.get_config().has_explicit_nickname():
4899
5104
            b.nick = b_other.nick
4900
5105
 
4913
5118
    def run(self, directory=u'.'):
4914
5119
        b, relpath = Branch.open_containing(directory)
4915
5120
        if not b.unbind():
4916
 
            raise errors.BzrCommandError('Local branch is not bound')
 
5121
            raise errors.BzrCommandError(gettext('Local branch is not bound'))
4917
5122
 
4918
5123
 
4919
5124
class cmd_uncommit(Command):
4940
5145
    takes_options = ['verbose', 'revision',
4941
5146
                    Option('dry-run', help='Don\'t actually make changes.'),
4942
5147
                    Option('force', help='Say yes to all questions.'),
 
5148
                    Option('keep-tags',
 
5149
                           help='Keep tags that point to removed revisions.'),
4943
5150
                    Option('local',
4944
5151
                           help="Only remove the commits from the local branch"
4945
5152
                                " when in a checkout."
4949
5156
    aliases = []
4950
5157
    encoding_type = 'replace'
4951
5158
 
4952
 
    def run(self, location=None,
4953
 
            dry_run=False, verbose=False,
4954
 
            revision=None, force=False, local=False):
 
5159
    def run(self, location=None, dry_run=False, verbose=False,
 
5160
            revision=None, force=False, local=False, keep_tags=False):
4955
5161
        if location is None:
4956
5162
            location = u'.'
4957
 
        control, relpath = bzrdir.BzrDir.open_containing(location)
 
5163
        control, relpath = controldir.ControlDir.open_containing(location)
4958
5164
        try:
4959
5165
            tree = control.open_workingtree()
4960
5166
            b = tree.branch
4966
5172
            self.add_cleanup(tree.lock_write().unlock)
4967
5173
        else:
4968
5174
            self.add_cleanup(b.lock_write().unlock)
4969
 
        return self._run(b, tree, dry_run, verbose, revision, force, local=local)
 
5175
        return self._run(b, tree, dry_run, verbose, revision, force,
 
5176
                         local, keep_tags)
4970
5177
 
4971
 
    def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
 
5178
    def _run(self, b, tree, dry_run, verbose, revision, force, local,
 
5179
             keep_tags):
4972
5180
        from bzrlib.log import log_formatter, show_log
4973
5181
        from bzrlib.uncommit import uncommit
4974
5182
 
4989
5197
                rev_id = b.get_rev_id(revno)
4990
5198
 
4991
5199
        if rev_id is None or _mod_revision.is_null(rev_id):
4992
 
            self.outf.write('No revisions to uncommit.\n')
 
5200
            self.outf.write(gettext('No revisions to uncommit.\n'))
4993
5201
            return 1
4994
5202
 
4995
5203
        lf = log_formatter('short',
5004
5212
                 end_revision=last_revno)
5005
5213
 
5006
5214
        if dry_run:
5007
 
            self.outf.write('Dry-run, pretending to remove'
5008
 
                            ' the above revisions.\n')
 
5215
            self.outf.write(gettext('Dry-run, pretending to remove'
 
5216
                            ' the above revisions.\n'))
5009
5217
        else:
5010
 
            self.outf.write('The above revision(s) will be removed.\n')
 
5218
            self.outf.write(gettext('The above revision(s) will be removed.\n'))
5011
5219
 
5012
5220
        if not force:
5013
5221
            if not ui.ui_factory.confirm_action(
5014
 
                    u'Uncommit these revisions',
 
5222
                    gettext(u'Uncommit these revisions'),
5015
5223
                    'bzrlib.builtins.uncommit',
5016
5224
                    {}):
5017
 
                self.outf.write('Canceled\n')
 
5225
                self.outf.write(gettext('Canceled\n'))
5018
5226
                return 0
5019
5227
 
5020
5228
        mutter('Uncommitting from {%s} to {%s}',
5021
5229
               last_rev_id, rev_id)
5022
5230
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5023
 
                 revno=revno, local=local)
5024
 
        self.outf.write('You can restore the old tip by running:\n'
5025
 
             '  bzr pull . -r revid:%s\n' % last_rev_id)
 
5231
                 revno=revno, local=local, keep_tags=keep_tags)
 
5232
        self.outf.write(gettext('You can restore the old tip by running:\n'
 
5233
             '  bzr pull . -r revid:%s\n') % last_rev_id)
5026
5234
 
5027
5235
 
5028
5236
class cmd_break_lock(Command):
5062
5270
            conf = _mod_config.LockableConfig(file_name=location)
5063
5271
            conf.break_lock()
5064
5272
        else:
5065
 
            control, relpath = bzrdir.BzrDir.open_containing(location)
 
5273
            control, relpath = controldir.ControlDir.open_containing(location)
5066
5274
            try:
5067
5275
                control.break_lock()
5068
5276
            except NotImplementedError:
5112
5320
                    'option leads to global uncontrolled write access to your '
5113
5321
                    'file system.'
5114
5322
                ),
 
5323
        Option('client-timeout', type=float,
 
5324
               help='Override the default idle client timeout (5min).'),
5115
5325
        ]
5116
5326
 
5117
5327
    def get_host_and_port(self, port):
5134
5344
        return host, port
5135
5345
 
5136
5346
    def run(self, port=None, inet=False, directory=None, allow_writes=False,
5137
 
            protocol=None):
 
5347
            protocol=None, client_timeout=None):
5138
5348
        from bzrlib import transport
5139
5349
        if directory is None:
5140
5350
            directory = os.getcwd()
5141
5351
        if protocol is None:
5142
5352
            protocol = transport.transport_server_registry.get()
5143
5353
        host, port = self.get_host_and_port(port)
5144
 
        url = urlutils.local_path_to_url(directory)
 
5354
        url = transport.location_to_url(directory)
5145
5355
        if not allow_writes:
5146
5356
            url = 'readonly+' + url
5147
 
        t = transport.get_transport(url)
5148
 
        protocol(t, host, port, inet)
 
5357
        t = transport.get_transport_from_url(url)
 
5358
        try:
 
5359
            protocol(t, host, port, inet, client_timeout)
 
5360
        except TypeError, e:
 
5361
            # We use symbol_versioning.deprecated_in just so that people
 
5362
            # grepping can find it here.
 
5363
            # symbol_versioning.deprecated_in((2, 5, 0))
 
5364
            symbol_versioning.warn(
 
5365
                'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
 
5366
                'Most likely it needs to be updated to support a'
 
5367
                ' "timeout" parameter (added in bzr 2.5.0)'
 
5368
                % (e, protocol.__module__, protocol),
 
5369
                DeprecationWarning)
 
5370
            protocol(t, host, port, inet)
5149
5371
 
5150
5372
 
5151
5373
class cmd_join(Command):
5174
5396
        containing_tree = WorkingTree.open_containing(parent_dir)[0]
5175
5397
        repo = containing_tree.branch.repository
5176
5398
        if not repo.supports_rich_root():
5177
 
            raise errors.BzrCommandError(
 
5399
            raise errors.BzrCommandError(gettext(
5178
5400
                "Can't join trees because %s doesn't support rich root data.\n"
5179
 
                "You can use bzr upgrade on the repository."
 
5401
                "You can use bzr upgrade on the repository.")
5180
5402
                % (repo,))
5181
5403
        if reference:
5182
5404
            try:
5184
5406
            except errors.BadReferenceTarget, e:
5185
5407
                # XXX: Would be better to just raise a nicely printable
5186
5408
                # exception from the real origin.  Also below.  mbp 20070306
5187
 
                raise errors.BzrCommandError("Cannot join %s.  %s" %
5188
 
                                             (tree, e.reason))
 
5409
                raise errors.BzrCommandError(
 
5410
                       gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5189
5411
        else:
5190
5412
            try:
5191
5413
                containing_tree.subsume(sub_tree)
5192
5414
            except errors.BadSubsumeSource, e:
5193
 
                raise errors.BzrCommandError("Cannot join %s.  %s" %
5194
 
                                             (tree, e.reason))
 
5415
                raise errors.BzrCommandError(
 
5416
                       gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5195
5417
 
5196
5418
 
5197
5419
class cmd_split(Command):
5281
5503
        if submit_branch is None:
5282
5504
            submit_branch = branch.get_parent()
5283
5505
        if submit_branch is None:
5284
 
            raise errors.BzrCommandError('No submit branch specified or known')
 
5506
            raise errors.BzrCommandError(gettext('No submit branch specified or known'))
5285
5507
 
5286
5508
        stored_public_branch = branch.get_public_branch()
5287
5509
        if public_branch is None:
5289
5511
        elif stored_public_branch is None:
5290
5512
            branch.set_public_branch(public_branch)
5291
5513
        if not include_bundle and public_branch is None:
5292
 
            raise errors.BzrCommandError('No public branch specified or'
5293
 
                                         ' known')
 
5514
            raise errors.BzrCommandError(gettext('No public branch specified or'
 
5515
                                         ' known'))
5294
5516
        base_revision_id = None
5295
5517
        if revision is not None:
5296
5518
            if len(revision) > 2:
5297
 
                raise errors.BzrCommandError('bzr merge-directive takes '
5298
 
                    'at most two one revision identifiers')
 
5519
                raise errors.BzrCommandError(gettext('bzr merge-directive takes '
 
5520
                    'at most two one revision identifiers'))
5299
5521
            revision_id = revision[-1].as_revision_id(branch)
5300
5522
            if len(revision) == 2:
5301
5523
                base_revision_id = revision[0].as_revision_id(branch)
5303
5525
            revision_id = branch.last_revision()
5304
5526
        revision_id = ensure_null(revision_id)
5305
5527
        if revision_id == NULL_REVISION:
5306
 
            raise errors.BzrCommandError('No revisions to bundle.')
 
5528
            raise errors.BzrCommandError(gettext('No revisions to bundle.'))
5307
5529
        directive = merge_directive.MergeDirective2.from_objects(
5308
5530
            branch.repository, revision_id, time.time(),
5309
5531
            osutils.local_time_offset(), submit_branch,
5355
5577
 
5356
5578
    Both the submit branch and the public branch follow the usual behavior with
5357
5579
    respect to --remember: If there is no default location set, the first send
5358
 
    will set it (use --no-remember to avoid settting it). After that, you can
 
5580
    will set it (use --no-remember to avoid setting it). After that, you can
5359
5581
    omit the location to use the default.  To change the default, use
5360
5582
    --remember. The value will only be saved if the location can be accessed.
5361
5583
 
5563
5785
        self.add_cleanup(branch.lock_write().unlock)
5564
5786
        if delete:
5565
5787
            if tag_name is None:
5566
 
                raise errors.BzrCommandError("No tag specified to delete.")
 
5788
                raise errors.BzrCommandError(gettext("No tag specified to delete."))
5567
5789
            branch.tags.delete_tag(tag_name)
5568
 
            note('Deleted tag %s.' % tag_name)
 
5790
            note(gettext('Deleted tag %s.') % tag_name)
5569
5791
        else:
5570
5792
            if revision:
5571
5793
                if len(revision) != 1:
5572
 
                    raise errors.BzrCommandError(
 
5794
                    raise errors.BzrCommandError(gettext(
5573
5795
                        "Tags can only be placed on a single revision, "
5574
 
                        "not on a range")
 
5796
                        "not on a range"))
5575
5797
                revision_id = revision[0].as_revision_id(branch)
5576
5798
            else:
5577
5799
                revision_id = branch.last_revision()
5578
5800
            if tag_name is None:
5579
5801
                tag_name = branch.automatic_tag_name(revision_id)
5580
5802
                if tag_name is None:
5581
 
                    raise errors.BzrCommandError(
5582
 
                        "Please specify a tag name.")
5583
 
            if (not force) and branch.tags.has_tag(tag_name):
 
5803
                    raise errors.BzrCommandError(gettext(
 
5804
                        "Please specify a tag name."))
 
5805
            try:
 
5806
                existing_target = branch.tags.lookup_tag(tag_name)
 
5807
            except errors.NoSuchTag:
 
5808
                existing_target = None
 
5809
            if not force and existing_target not in (None, revision_id):
5584
5810
                raise errors.TagAlreadyExists(tag_name)
5585
 
            branch.tags.set_tag(tag_name, revision_id)
5586
 
            note('Created tag %s.' % tag_name)
 
5811
            if existing_target == revision_id:
 
5812
                note(gettext('Tag %s already exists for that revision.') % tag_name)
 
5813
            else:
 
5814
                branch.tags.set_tag(tag_name, revision_id)
 
5815
                if existing_target is None:
 
5816
                    note(gettext('Created tag %s.') % tag_name)
 
5817
                else:
 
5818
                    note(gettext('Updated tag %s.') % tag_name)
5587
5819
 
5588
5820
 
5589
5821
class cmd_tags(Command):
5627
5859
                    revno = branch.revision_id_to_dotted_revno(revid)
5628
5860
                    if isinstance(revno, tuple):
5629
5861
                        revno = '.'.join(map(str, revno))
5630
 
                except (errors.NoSuchRevision, errors.GhostRevisionsHaveNoRevno):
 
5862
                except (errors.NoSuchRevision,
 
5863
                        errors.GhostRevisionsHaveNoRevno,
 
5864
                        errors.UnsupportedOperation):
5631
5865
                    # Bad tag data/merges can lead to tagged revisions
5632
5866
                    # which are not in this branch. Fail gracefully ...
5633
5867
                    revno = '?'
5681
5915
    takes_args = ['location?']
5682
5916
    takes_options = [
5683
5917
        RegistryOption.from_kwargs(
5684
 
            'target_type',
5685
 
            title='Target type',
5686
 
            help='The type to reconfigure the directory to.',
 
5918
            'tree_type',
 
5919
            title='Tree type',
 
5920
            help='The relation between branch and tree.',
5687
5921
            value_switches=True, enum_switch=False,
5688
5922
            branch='Reconfigure to be an unbound branch with no working tree.',
5689
5923
            tree='Reconfigure to be an unbound branch with a working tree.',
5690
5924
            checkout='Reconfigure to be a bound branch with a working tree.',
5691
5925
            lightweight_checkout='Reconfigure to be a lightweight'
5692
5926
                ' checkout (with no local history).',
 
5927
            ),
 
5928
        RegistryOption.from_kwargs(
 
5929
            'repository_type',
 
5930
            title='Repository type',
 
5931
            help='Location fo the repository.',
 
5932
            value_switches=True, enum_switch=False,
5693
5933
            standalone='Reconfigure to be a standalone branch '
5694
5934
                '(i.e. stop using shared repository).',
5695
5935
            use_shared='Reconfigure to use a shared repository.',
 
5936
            ),
 
5937
        RegistryOption.from_kwargs(
 
5938
            'repository_trees',
 
5939
            title='Trees in Repository',
 
5940
            help='Whether new branches in the repository have trees.',
 
5941
            value_switches=True, enum_switch=False,
5696
5942
            with_trees='Reconfigure repository to create '
5697
5943
                'working trees on branches by default.',
5698
5944
            with_no_trees='Reconfigure repository to not create '
5712
5958
            ),
5713
5959
        ]
5714
5960
 
5715
 
    def run(self, location=None, target_type=None, bind_to=None, force=False,
5716
 
            stacked_on=None,
5717
 
            unstacked=None):
5718
 
        directory = bzrdir.BzrDir.open(location)
 
5961
    def run(self, location=None, bind_to=None, force=False,
 
5962
            tree_type=None, repository_type=None, repository_trees=None,
 
5963
            stacked_on=None, unstacked=None):
 
5964
        directory = controldir.ControlDir.open(location)
5719
5965
        if stacked_on and unstacked:
5720
 
            raise errors.BzrCommandError("Can't use both --stacked-on and --unstacked")
 
5966
            raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5721
5967
        elif stacked_on is not None:
5722
5968
            reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5723
5969
        elif unstacked:
5725
5971
        # At the moment you can use --stacked-on and a different
5726
5972
        # reconfiguration shape at the same time; there seems no good reason
5727
5973
        # to ban it.
5728
 
        if target_type is None:
 
5974
        if (tree_type is None and
 
5975
            repository_type is None and
 
5976
            repository_trees is None):
5729
5977
            if stacked_on or unstacked:
5730
5978
                return
5731
5979
            else:
5732
 
                raise errors.BzrCommandError('No target configuration '
5733
 
                    'specified')
5734
 
        elif target_type == 'branch':
 
5980
                raise errors.BzrCommandError(gettext('No target configuration '
 
5981
                    'specified'))
 
5982
        reconfiguration = None
 
5983
        if tree_type == 'branch':
5735
5984
            reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5736
 
        elif target_type == 'tree':
 
5985
        elif tree_type == 'tree':
5737
5986
            reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5738
 
        elif target_type == 'checkout':
 
5987
        elif tree_type == 'checkout':
5739
5988
            reconfiguration = reconfigure.Reconfigure.to_checkout(
5740
5989
                directory, bind_to)
5741
 
        elif target_type == 'lightweight-checkout':
 
5990
        elif tree_type == 'lightweight-checkout':
5742
5991
            reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5743
5992
                directory, bind_to)
5744
 
        elif target_type == 'use-shared':
 
5993
        if reconfiguration:
 
5994
            reconfiguration.apply(force)
 
5995
            reconfiguration = None
 
5996
        if repository_type == 'use-shared':
5745
5997
            reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5746
 
        elif target_type == 'standalone':
 
5998
        elif repository_type == 'standalone':
5747
5999
            reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5748
 
        elif target_type == 'with-trees':
 
6000
        if reconfiguration:
 
6001
            reconfiguration.apply(force)
 
6002
            reconfiguration = None
 
6003
        if repository_trees == 'with-trees':
5749
6004
            reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5750
6005
                directory, True)
5751
 
        elif target_type == 'with-no-trees':
 
6006
        elif repository_trees == 'with-no-trees':
5752
6007
            reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5753
6008
                directory, False)
5754
 
        reconfiguration.apply(force)
 
6009
        if reconfiguration:
 
6010
            reconfiguration.apply(force)
 
6011
            reconfiguration = None
5755
6012
 
5756
6013
 
5757
6014
class cmd_switch(Command):
5792
6049
        from bzrlib import switch
5793
6050
        tree_location = directory
5794
6051
        revision = _get_one_revision('switch', revision)
5795
 
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
 
6052
        control_dir = controldir.ControlDir.open_containing(tree_location)[0]
5796
6053
        if to_location is None:
5797
6054
            if revision is None:
5798
 
                raise errors.BzrCommandError('You must supply either a'
5799
 
                                             ' revision or a location')
 
6055
                raise errors.BzrCommandError(gettext('You must supply either a'
 
6056
                                             ' revision or a location'))
5800
6057
            to_location = tree_location
5801
6058
        try:
5802
6059
            branch = control_dir.open_branch()
5806
6063
            had_explicit_nick = False
5807
6064
        if create_branch:
5808
6065
            if branch is None:
5809
 
                raise errors.BzrCommandError('cannot create branch without'
5810
 
                                             ' source branch')
 
6066
                raise errors.BzrCommandError(gettext('cannot create branch without'
 
6067
                                             ' source branch'))
5811
6068
            to_location = directory_service.directories.dereference(
5812
6069
                              to_location)
5813
6070
            if '/' not in to_location and '\\' not in to_location:
5814
6071
                # This path is meant to be relative to the existing branch
5815
6072
                this_url = self._get_branch_location(control_dir)
5816
 
                to_location = urlutils.join(this_url, '..', to_location)
 
6073
                # Perhaps the target control dir supports colocated branches?
 
6074
                try:
 
6075
                    root = controldir.ControlDir.open(this_url,
 
6076
                        possible_transports=[control_dir.user_transport])
 
6077
                except errors.NotBranchError:
 
6078
                    colocated = False
 
6079
                else:
 
6080
                    colocated = root._format.colocated_branches
 
6081
                if colocated:
 
6082
                    to_location = urlutils.join_segment_parameters(this_url,
 
6083
                        {"branch": urlutils.escape(to_location)})
 
6084
                else:
 
6085
                    to_location = urlutils.join(
 
6086
                        this_url, '..', urlutils.escape(to_location))
5817
6087
            to_branch = branch.bzrdir.sprout(to_location,
5818
6088
                                 possible_transports=[branch.bzrdir.root_transport],
5819
6089
                                 source_branch=branch).open_branch()
5820
6090
        else:
 
6091
            # Perhaps it's a colocated branch?
5821
6092
            try:
5822
 
                to_branch = Branch.open(to_location)
5823
 
            except errors.NotBranchError:
5824
 
                this_url = self._get_branch_location(control_dir)
5825
 
                to_branch = Branch.open(
5826
 
                    urlutils.join(this_url, '..', to_location))
 
6093
                to_branch = control_dir.open_branch(to_location)
 
6094
            except (errors.NotBranchError, errors.NoColocatedBranchSupport):
 
6095
                try:
 
6096
                    to_branch = Branch.open(to_location)
 
6097
                except errors.NotBranchError:
 
6098
                    this_url = self._get_branch_location(control_dir)
 
6099
                    to_branch = Branch.open(
 
6100
                        urlutils.join(
 
6101
                            this_url, '..', urlutils.escape(to_location)))
5827
6102
        if revision is not None:
5828
6103
            revision = revision.as_revision_id(to_branch)
5829
6104
        switch.switch(control_dir, to_branch, force, revision_id=revision)
5830
6105
        if had_explicit_nick:
5831
6106
            branch = control_dir.open_branch() #get the new branch!
5832
6107
            branch.nick = to_branch.nick
5833
 
        note('Switched to branch: %s',
 
6108
        note(gettext('Switched to branch: %s'),
5834
6109
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5835
6110
 
5836
6111
    def _get_branch_location(self, control_dir):
5945
6220
            name = current_view
5946
6221
        if delete:
5947
6222
            if file_list:
5948
 
                raise errors.BzrCommandError(
5949
 
                    "Both --delete and a file list specified")
 
6223
                raise errors.BzrCommandError(gettext(
 
6224
                    "Both --delete and a file list specified"))
5950
6225
            elif switch:
5951
 
                raise errors.BzrCommandError(
5952
 
                    "Both --delete and --switch specified")
 
6226
                raise errors.BzrCommandError(gettext(
 
6227
                    "Both --delete and --switch specified"))
5953
6228
            elif all:
5954
6229
                tree.views.set_view_info(None, {})
5955
 
                self.outf.write("Deleted all views.\n")
 
6230
                self.outf.write(gettext("Deleted all views.\n"))
5956
6231
            elif name is None:
5957
 
                raise errors.BzrCommandError("No current view to delete")
 
6232
                raise errors.BzrCommandError(gettext("No current view to delete"))
5958
6233
            else:
5959
6234
                tree.views.delete_view(name)
5960
 
                self.outf.write("Deleted '%s' view.\n" % name)
 
6235
                self.outf.write(gettext("Deleted '%s' view.\n") % name)
5961
6236
        elif switch:
5962
6237
            if file_list:
5963
 
                raise errors.BzrCommandError(
5964
 
                    "Both --switch and a file list specified")
 
6238
                raise errors.BzrCommandError(gettext(
 
6239
                    "Both --switch and a file list specified"))
5965
6240
            elif all:
5966
 
                raise errors.BzrCommandError(
5967
 
                    "Both --switch and --all specified")
 
6241
                raise errors.BzrCommandError(gettext(
 
6242
                    "Both --switch and --all specified"))
5968
6243
            elif switch == 'off':
5969
6244
                if current_view is None:
5970
 
                    raise errors.BzrCommandError("No current view to disable")
 
6245
                    raise errors.BzrCommandError(gettext("No current view to disable"))
5971
6246
                tree.views.set_view_info(None, view_dict)
5972
 
                self.outf.write("Disabled '%s' view.\n" % (current_view))
 
6247
                self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
5973
6248
            else:
5974
6249
                tree.views.set_view_info(switch, view_dict)
5975
6250
                view_str = views.view_display_str(tree.views.lookup_view())
5976
 
                self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
 
6251
                self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
5977
6252
        elif all:
5978
6253
            if view_dict:
5979
 
                self.outf.write('Views defined:\n')
 
6254
                self.outf.write(gettext('Views defined:\n'))
5980
6255
                for view in sorted(view_dict):
5981
6256
                    if view == current_view:
5982
6257
                        active = "=>"
5985
6260
                    view_str = views.view_display_str(view_dict[view])
5986
6261
                    self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5987
6262
            else:
5988
 
                self.outf.write('No views defined.\n')
 
6263
                self.outf.write(gettext('No views defined.\n'))
5989
6264
        elif file_list:
5990
6265
            if name is None:
5991
6266
                # No name given and no current view set
5992
6267
                name = 'my'
5993
6268
            elif name == 'off':
5994
 
                raise errors.BzrCommandError(
5995
 
                    "Cannot change the 'off' pseudo view")
 
6269
                raise errors.BzrCommandError(gettext(
 
6270
                    "Cannot change the 'off' pseudo view"))
5996
6271
            tree.views.set_view(name, sorted(file_list))
5997
6272
            view_str = views.view_display_str(tree.views.lookup_view())
5998
 
            self.outf.write("Using '%s' view: %s\n" % (name, view_str))
 
6273
            self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
5999
6274
        else:
6000
6275
            # list the files
6001
6276
            if name is None:
6002
6277
                # No name given and no current view set
6003
 
                self.outf.write('No current view.\n')
 
6278
                self.outf.write(gettext('No current view.\n'))
6004
6279
            else:
6005
6280
                view_str = views.view_display_str(tree.views.lookup_view(name))
6006
 
                self.outf.write("'%s' view is: %s\n" % (name, view_str))
 
6281
                self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
6007
6282
 
6008
6283
 
6009
6284
class cmd_hooks(Command):
6023
6298
                        self.outf.write("    %s\n" %
6024
6299
                                        (some_hooks.get_hook_name(hook),))
6025
6300
                else:
6026
 
                    self.outf.write("    <no hooks installed>\n")
 
6301
                    self.outf.write(gettext("    <no hooks installed>\n"))
6027
6302
 
6028
6303
 
6029
6304
class cmd_remove_branch(Command):
6130
6405
        manager = tree.get_shelf_manager()
6131
6406
        shelves = manager.active_shelves()
6132
6407
        if len(shelves) == 0:
6133
 
            note('No shelved changes.')
 
6408
            note(gettext('No shelved changes.'))
6134
6409
            return 0
6135
6410
        for shelf_id in reversed(shelves):
6136
6411
            message = manager.get_metadata(shelf_id).get('message')
6225
6500
        if path is not None:
6226
6501
            branchdir = path
6227
6502
        tree, branch, relpath =(
6228
 
            bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
 
6503
            controldir.ControlDir.open_containing_tree_or_branch(branchdir))
6229
6504
        if path is not None:
6230
6505
            path = relpath
6231
6506
        if tree is None:
6259
6534
    __doc__ = """Export command helps and error messages in po format."""
6260
6535
 
6261
6536
    hidden = True
 
6537
    takes_options = [Option('plugin', 
 
6538
                            help='Export help text from named command '\
 
6539
                                 '(defaults to all built in commands).',
 
6540
                            type=str)]
6262
6541
 
6263
 
    def run(self):
 
6542
    def run(self, plugin=None):
6264
6543
        from bzrlib.export_pot import export_pot
6265
 
        export_pot(self.outf)
 
6544
        export_pot(self.outf, plugin)
6266
6545
 
6267
6546
 
6268
6547
def _register_lazy_builtins():