~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""builtin bzr commands"""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import os
20
22
 
21
 
from bzrlib.lazy_import import lazy_import
22
 
lazy_import(globals(), """
 
23
import bzrlib.bzrdir
 
24
 
 
25
from bzrlib import lazy_import
 
26
lazy_import.lazy_import(globals(), """
23
27
import cStringIO
 
28
import errno
24
29
import sys
25
30
import time
26
31
 
29
34
    bugtracker,
30
35
    bundle,
31
36
    btree_index,
32
 
    bzrdir,
 
37
    controldir,
33
38
    directory_service,
34
39
    delta,
35
40
    config as _mod_config,
49
54
    ui,
50
55
    urlutils,
51
56
    views,
 
57
    gpg,
52
58
    )
53
59
from bzrlib.branch import Branch
54
60
from bzrlib.conflicts import ConflictList
56
62
from bzrlib.revisionspec import RevisionSpec, RevisionInfo
57
63
from bzrlib.smtp_connection import SMTPConnection
58
64
from bzrlib.workingtree import WorkingTree
 
65
from bzrlib.i18n import gettext, ngettext
59
66
""")
60
67
 
61
68
from bzrlib.commands import (
111
118
            if view_files:
112
119
                file_list = view_files
113
120
                view_str = views.view_display_str(view_files)
114
 
                note("Ignoring files outside view. View is %s" % view_str)
 
121
                note(gettext("Ignoring files outside view. View is %s") % view_str)
115
122
    return tree, file_list
116
123
 
117
124
 
119
126
    if revisions is None:
120
127
        return None
121
128
    if len(revisions) != 1:
122
 
        raise errors.BzrCommandError(
123
 
            'bzr %s --revision takes exactly one revision identifier' % (
 
129
        raise errors.BzrCommandError(gettext(
 
130
            'bzr %s --revision takes exactly one revision identifier') % (
124
131
                command_name,))
125
132
    return revisions[0]
126
133
 
195
202
    the --directory option is used to specify a different branch."""
196
203
    if directory is not None:
197
204
        return (None, Branch.open(directory), filename)
198
 
    return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
205
    return controldir.ControlDir.open_containing_tree_or_branch(filename)
199
206
 
200
207
 
201
208
# TODO: Make sure no commands unconditionally use the working directory as a
231
238
    unknown
232
239
        Not versioned and not matching an ignore pattern.
233
240
 
234
 
    Additionally for directories, symlinks and files with an executable
235
 
    bit, Bazaar indicates their type using a trailing character: '/', '@'
236
 
    or '*' respectively.
 
241
    Additionally for directories, symlinks and files with a changed
 
242
    executable bit, Bazaar indicates their type using a trailing
 
243
    character: '/', '@' or '*' respectively. These decorations can be
 
244
    disabled using the '--no-classify' option.
237
245
 
238
246
    To see ignored files use 'bzr ignored'.  For details on the
239
247
    changes to file texts, use 'bzr diff'.
270
278
                            short_name='V'),
271
279
                     Option('no-pending', help='Don\'t show pending merges.',
272
280
                           ),
 
281
                     Option('no-classify',
 
282
                            help='Do not mark object type using indicator.',
 
283
                           ),
273
284
                     ]
274
285
    aliases = ['st', 'stat']
275
286
 
278
289
 
279
290
    @display_command
280
291
    def run(self, show_ids=False, file_list=None, revision=None, short=False,
281
 
            versioned=False, no_pending=False, verbose=False):
 
292
            versioned=False, no_pending=False, verbose=False,
 
293
            no_classify=False):
282
294
        from bzrlib.status import show_tree_status
283
295
 
284
296
        if revision and len(revision) > 2:
285
 
            raise errors.BzrCommandError('bzr status --revision takes exactly'
286
 
                                         ' one or two revision specifiers')
 
297
            raise errors.BzrCommandError(gettext('bzr status --revision takes exactly'
 
298
                                         ' one or two revision specifiers'))
287
299
 
288
300
        tree, relfile_list = WorkingTree.open_containing_paths(file_list)
289
301
        # Avoid asking for specific files when that is not needed.
298
310
        show_tree_status(tree, show_ids=show_ids,
299
311
                         specific_files=relfile_list, revision=revision,
300
312
                         to_file=self.outf, short=short, versioned=versioned,
301
 
                         show_pending=(not no_pending), verbose=verbose)
 
313
                         show_pending=(not no_pending), verbose=verbose,
 
314
                         classify=not no_classify)
302
315
 
303
316
 
304
317
class cmd_cat_revision(Command):
325
338
    @display_command
326
339
    def run(self, revision_id=None, revision=None, directory=u'.'):
327
340
        if revision_id is not None and revision is not None:
328
 
            raise errors.BzrCommandError('You can only supply one of'
329
 
                                         ' revision_id or --revision')
 
341
            raise errors.BzrCommandError(gettext('You can only supply one of'
 
342
                                         ' revision_id or --revision'))
330
343
        if revision_id is None and revision is None:
331
 
            raise errors.BzrCommandError('You must supply either'
332
 
                                         ' --revision or a revision_id')
 
344
            raise errors.BzrCommandError(gettext('You must supply either'
 
345
                                         ' --revision or a revision_id'))
333
346
 
334
 
        b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
 
347
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
335
348
 
336
349
        revisions = b.repository.revisions
337
350
        if revisions is None:
338
 
            raise errors.BzrCommandError('Repository %r does not support '
339
 
                'access to raw revision texts')
 
351
            raise errors.BzrCommandError(gettext('Repository %r does not support '
 
352
                'access to raw revision texts'))
340
353
 
341
354
        b.repository.lock_read()
342
355
        try:
346
359
                try:
347
360
                    self.print_revision(revisions, revision_id)
348
361
                except errors.NoSuchRevision:
349
 
                    msg = "The repository %s contains no revision %s." % (
 
362
                    msg = gettext("The repository {0} contains no revision {1}.").format(
350
363
                        b.repository.base, revision_id)
351
364
                    raise errors.BzrCommandError(msg)
352
365
            elif revision is not None:
353
366
                for rev in revision:
354
367
                    if rev is None:
355
368
                        raise errors.BzrCommandError(
356
 
                            'You cannot specify a NULL revision.')
 
369
                            gettext('You cannot specify a NULL revision.'))
357
370
                    rev_id = rev.as_revision_id(b)
358
371
                    self.print_revision(revisions, rev_id)
359
372
        finally:
465
478
            location_list=['.']
466
479
 
467
480
        for location in location_list:
468
 
            d = bzrdir.BzrDir.open(location)
469
 
            
 
481
            d = controldir.ControlDir.open(location)
 
482
 
470
483
            try:
471
484
                working = d.open_workingtree()
472
485
            except errors.NoWorkingTree:
473
 
                raise errors.BzrCommandError("No working tree to remove")
 
486
                raise errors.BzrCommandError(gettext("No working tree to remove"))
474
487
            except errors.NotLocalUrl:
475
 
                raise errors.BzrCommandError("You cannot remove the working tree"
476
 
                                             " of a remote path")
 
488
                raise errors.BzrCommandError(gettext("You cannot remove the working tree"
 
489
                                             " of a remote path"))
477
490
            if not force:
478
491
                if (working.has_changes()):
479
492
                    raise errors.UncommittedChanges(working)
481
494
                    raise errors.ShelvedChanges(working)
482
495
 
483
496
            if working.user_url != working.branch.user_url:
484
 
                raise errors.BzrCommandError("You cannot remove the working tree"
485
 
                                             " from a lightweight checkout")
 
497
                raise errors.BzrCommandError(gettext("You cannot remove the working tree"
 
498
                                             " from a lightweight checkout"))
486
499
 
487
500
            d.destroy_workingtree()
488
501
 
520
533
                pass # There seems to be a real error here, so we'll reset
521
534
            else:
522
535
                # Refuse
523
 
                raise errors.BzrCommandError(
 
536
                raise errors.BzrCommandError(gettext(
524
537
                    'The tree does not appear to be corrupt. You probably'
525
538
                    ' want "bzr revert" instead. Use "--force" if you are'
526
 
                    ' sure you want to reset the working tree.')
 
539
                    ' sure you want to reset the working tree.'))
527
540
        if revision is None:
528
541
            revision_ids = None
529
542
        else:
532
545
            tree.reset_state(revision_ids)
533
546
        except errors.BzrError, e:
534
547
            if revision_ids is None:
535
 
                extra = (', the header appears corrupt, try passing -r -1'
536
 
                         ' to set the state to the last commit')
 
548
                extra = (gettext(', the header appears corrupt, try passing -r -1'
 
549
                         ' to set the state to the last commit'))
537
550
            else:
538
551
                extra = ''
539
 
            raise errors.BzrCommandError('failed to reset the tree state'
540
 
                                         + extra)
 
552
            raise errors.BzrCommandError(gettext('failed to reset the tree state{0}').format(extra))
541
553
 
542
554
 
543
555
class cmd_revno(Command):
549
561
    _see_also = ['info']
550
562
    takes_args = ['location?']
551
563
    takes_options = [
552
 
        Option('tree', help='Show revno of working tree'),
 
564
        Option('tree', help='Show revno of working tree.'),
 
565
        'revision',
553
566
        ]
554
567
 
555
568
    @display_command
556
 
    def run(self, tree=False, location=u'.'):
 
569
    def run(self, tree=False, location=u'.', revision=None):
 
570
        if revision is not None and tree:
 
571
            raise errors.BzrCommandError(gettext("--tree and --revision can "
 
572
                "not be used together"))
 
573
 
557
574
        if tree:
558
575
            try:
559
576
                wt = WorkingTree.open_containing(location)[0]
560
577
                self.add_cleanup(wt.lock_read().unlock)
561
578
            except (errors.NoWorkingTree, errors.NotLocalUrl):
562
579
                raise errors.NoWorkingTree(location)
 
580
            b = wt.branch
563
581
            revid = wt.last_revision()
564
 
            try:
565
 
                revno_t = wt.branch.revision_id_to_dotted_revno(revid)
566
 
            except errors.NoSuchRevision:
567
 
                revno_t = ('???',)
568
 
            revno = ".".join(str(n) for n in revno_t)
569
582
        else:
570
583
            b = Branch.open_containing(location)[0]
571
584
            self.add_cleanup(b.lock_read().unlock)
572
 
            revno = b.revno()
 
585
            if revision:
 
586
                if len(revision) != 1:
 
587
                    raise errors.BzrCommandError(gettext(
 
588
                        "Tags can only be placed on a single revision, "
 
589
                        "not on a range"))
 
590
                revid = revision[0].as_revision_id(b)
 
591
            else:
 
592
                revid = b.last_revision()
 
593
        try:
 
594
            revno_t = b.revision_id_to_dotted_revno(revid)
 
595
        except errors.NoSuchRevision:
 
596
            revno_t = ('???',)
 
597
        revno = ".".join(str(n) for n in revno_t)
573
598
        self.cleanup_now()
574
 
        self.outf.write(str(revno) + '\n')
 
599
        self.outf.write(revno + '\n')
575
600
 
576
601
 
577
602
class cmd_revision_info(Command):
584
609
        custom_help('directory',
585
610
            help='Branch to examine, '
586
611
                 'rather than the one containing the working directory.'),
587
 
        Option('tree', help='Show revno of working tree'),
 
612
        Option('tree', help='Show revno of working tree.'),
588
613
        ]
589
614
 
590
615
    @display_command
646
671
    are added.  This search proceeds recursively into versioned
647
672
    directories.  If no names are given '.' is assumed.
648
673
 
 
674
    A warning will be printed when nested trees are encountered,
 
675
    unless they are explicitly ignored.
 
676
 
649
677
    Therefore simply saying 'bzr add' will version all files that
650
678
    are currently unknown.
651
679
 
667
695
    
668
696
    Any files matching patterns in the ignore list will not be added
669
697
    unless they are explicitly mentioned.
 
698
    
 
699
    In recursive mode, files larger than the configuration option 
 
700
    add.maximum_file_size will be skipped. Named items are never skipped due
 
701
    to file size.
670
702
    """
671
703
    takes_args = ['file*']
672
704
    takes_options = [
699
731
            action = bzrlib.add.AddFromBaseAction(base_tree, base_path,
700
732
                          to_file=self.outf, should_print=(not is_quiet()))
701
733
        else:
702
 
            action = bzrlib.add.AddAction(to_file=self.outf,
 
734
            action = bzrlib.add.AddWithSkipLargeAction(to_file=self.outf,
703
735
                should_print=(not is_quiet()))
704
736
 
705
737
        if base_tree:
712
744
            if verbose:
713
745
                for glob in sorted(ignored.keys()):
714
746
                    for path in ignored[glob]:
715
 
                        self.outf.write("ignored %s matching \"%s\"\n"
716
 
                                        % (path, glob))
 
747
                        self.outf.write(
 
748
                         gettext("ignored {0} matching \"{1}\"\n").format(
 
749
                         path, glob))
717
750
 
718
751
 
719
752
class cmd_mkdir(Command):
723
756
    """
724
757
 
725
758
    takes_args = ['dir+']
 
759
    takes_options = [
 
760
        Option(
 
761
            'parents',
 
762
            help='No error if existing, make parent directories as needed.',
 
763
            short_name='p'
 
764
            )
 
765
        ]
726
766
    encoding_type = 'replace'
727
767
 
728
 
    def run(self, dir_list):
729
 
        for d in dir_list:
730
 
            wt, dd = WorkingTree.open_containing(d)
731
 
            base = os.path.dirname(dd)
732
 
            id = wt.path2id(base)
733
 
            if id != None:
734
 
                os.mkdir(d)
735
 
                wt.add([dd])
736
 
                self.outf.write('added %s\n' % d)
 
768
    @classmethod
 
769
    def add_file_with_parents(cls, wt, relpath):
 
770
        if wt.path2id(relpath) is not None:
 
771
            return
 
772
        cls.add_file_with_parents(wt, osutils.dirname(relpath))
 
773
        wt.add([relpath])
 
774
 
 
775
    @classmethod
 
776
    def add_file_single(cls, wt, relpath):
 
777
        wt.add([relpath])
 
778
 
 
779
    def run(self, dir_list, parents=False):
 
780
        if parents:
 
781
            add_file = self.add_file_with_parents
 
782
        else:
 
783
            add_file = self.add_file_single
 
784
        for dir in dir_list:
 
785
            wt, relpath = WorkingTree.open_containing(dir)
 
786
            if parents:
 
787
                try:
 
788
                    os.makedirs(dir)
 
789
                except OSError, e:
 
790
                    if e.errno != errno.EEXIST:
 
791
                        raise
737
792
            else:
738
 
                raise errors.NotVersionedError(path=base)
 
793
                os.mkdir(dir)
 
794
            add_file(wt, relpath)
 
795
            if not is_quiet():
 
796
                self.outf.write(gettext('added %s\n') % dir)
739
797
 
740
798
 
741
799
class cmd_relpath(Command):
777
835
    @display_command
778
836
    def run(self, revision=None, show_ids=False, kind=None, file_list=None):
779
837
        if kind and kind not in ['file', 'directory', 'symlink']:
780
 
            raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
 
838
            raise errors.BzrCommandError(gettext('invalid kind %r specified') % (kind,))
781
839
 
782
840
        revision = _get_one_revision('inventory', revision)
783
841
        work_tree, file_list = WorkingTree.open_containing_paths(file_list)
796
854
                                      require_versioned=True)
797
855
            # find_ids_across_trees may include some paths that don't
798
856
            # exist in 'tree'.
799
 
            entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
800
 
                             for file_id in file_ids if file_id in tree)
 
857
            entries = sorted(
 
858
                (tree.id2path(file_id), tree.inventory[file_id])
 
859
                for file_id in file_ids if tree.has_id(file_id))
801
860
        else:
802
861
            entries = tree.inventory.entries()
803
862
 
846
905
        if auto:
847
906
            return self.run_auto(names_list, after, dry_run)
848
907
        elif dry_run:
849
 
            raise errors.BzrCommandError('--dry-run requires --auto.')
 
908
            raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
850
909
        if names_list is None:
851
910
            names_list = []
852
911
        if len(names_list) < 2:
853
 
            raise errors.BzrCommandError("missing file argument")
 
912
            raise errors.BzrCommandError(gettext("missing file argument"))
854
913
        tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
 
914
        for file_name in rel_names[0:-1]:
 
915
            if file_name == '':
 
916
                raise errors.BzrCommandError(gettext("can not move root of branch"))
855
917
        self.add_cleanup(tree.lock_tree_write().unlock)
856
918
        self._run(tree, names_list, rel_names, after)
857
919
 
858
920
    def run_auto(self, names_list, after, dry_run):
859
921
        if names_list is not None and len(names_list) > 1:
860
 
            raise errors.BzrCommandError('Only one path may be specified to'
861
 
                                         ' --auto.')
 
922
            raise errors.BzrCommandError(gettext('Only one path may be specified to'
 
923
                                         ' --auto.'))
862
924
        if after:
863
 
            raise errors.BzrCommandError('--after cannot be specified with'
864
 
                                         ' --auto.')
 
925
            raise errors.BzrCommandError(gettext('--after cannot be specified with'
 
926
                                         ' --auto.'))
865
927
        work_tree, file_list = WorkingTree.open_containing_paths(
866
928
            names_list, default_directory='.')
867
929
        self.add_cleanup(work_tree.lock_tree_write().unlock)
897
959
                    self.outf.write("%s => %s\n" % (src, dest))
898
960
        else:
899
961
            if len(names_list) != 2:
900
 
                raise errors.BzrCommandError('to mv multiple files the'
 
962
                raise errors.BzrCommandError(gettext('to mv multiple files the'
901
963
                                             ' destination must be a versioned'
902
 
                                             ' directory')
 
964
                                             ' directory'))
903
965
 
904
966
            # for cicp file-systems: the src references an existing inventory
905
967
            # item:
965
1027
    branches have diverged.
966
1028
 
967
1029
    If there is no default location set, the first pull will set it (use
968
 
    --no-remember to avoid settting it). After that, you can omit the
 
1030
    --no-remember to avoid setting it). After that, you can omit the
969
1031
    location to use the default.  To change the default, use --remember. The
970
1032
    value will only be saved if the remote location can be accessed.
971
1033
 
 
1034
    The --verbose option will display the revisions pulled using the log_format
 
1035
    configuration option. You can use a different format by overriding it with
 
1036
    -Olog_format=<other_format>.
 
1037
 
972
1038
    Note: The location can be specified either in the form of a branch,
973
1039
    or in the form of a path to a file containing a merge directive generated
974
1040
    with bzr send.
1011
1077
            self.add_cleanup(branch_to.lock_write().unlock)
1012
1078
 
1013
1079
        if tree_to is None and show_base:
1014
 
            raise errors.BzrCommandError("Need working tree for --show-base.")
 
1080
            raise errors.BzrCommandError(gettext("Need working tree for --show-base."))
1015
1081
 
1016
1082
        if local and not branch_to.get_bound_location():
1017
1083
            raise errors.LocalRequiresBoundBranch()
1027
1093
        stored_loc = branch_to.get_parent()
1028
1094
        if location is None:
1029
1095
            if stored_loc is None:
1030
 
                raise errors.BzrCommandError("No pull location known or"
1031
 
                                             " specified.")
 
1096
                raise errors.BzrCommandError(gettext("No pull location known or"
 
1097
                                             " specified."))
1032
1098
            else:
1033
1099
                display_url = urlutils.unescape_for_display(stored_loc,
1034
1100
                        self.outf.encoding)
1035
1101
                if not is_quiet():
1036
 
                    self.outf.write("Using saved parent location: %s\n" % display_url)
 
1102
                    self.outf.write(gettext("Using saved parent location: %s\n") % display_url)
1037
1103
                location = stored_loc
1038
1104
 
1039
1105
        revision = _get_one_revision('pull', revision)
1040
1106
        if mergeable is not None:
1041
1107
            if revision is not None:
1042
 
                raise errors.BzrCommandError(
1043
 
                    'Cannot use -r with merge directives or bundles')
 
1108
                raise errors.BzrCommandError(gettext(
 
1109
                    'Cannot use -r with merge directives or bundles'))
1044
1110
            mergeable.install_revisions(branch_to.repository)
1045
1111
            base_revision_id, revision_id, verified = \
1046
1112
                mergeable.get_merge_request(branch_to.repository)
1064
1130
                view_info=view_info)
1065
1131
            result = tree_to.pull(
1066
1132
                branch_from, overwrite, revision_id, change_reporter,
1067
 
                possible_transports=possible_transports, local=local,
1068
 
                show_base=show_base)
 
1133
                local=local, show_base=show_base)
1069
1134
        else:
1070
1135
            result = branch_to.pull(
1071
1136
                branch_from, overwrite, revision_id, local=local)
1102
1167
    After that you will be able to do a push without '--overwrite'.
1103
1168
 
1104
1169
    If there is no default push location set, the first push will set it (use
1105
 
    --no-remember to avoid settting it).  After that, you can omit the
 
1170
    --no-remember to avoid setting it).  After that, you can omit the
1106
1171
    location to use the default.  To change the default, use --remember. The
1107
1172
    value will only be saved if the remote location can be accessed.
 
1173
 
 
1174
    The --verbose option will display the revisions pushed using the log_format
 
1175
    configuration option. You can use a different format by overriding it with
 
1176
    -Olog_format=<other_format>.
1108
1177
    """
1109
1178
 
1110
1179
    _see_also = ['pull', 'update', 'working-trees']
1148
1217
            directory = '.'
1149
1218
        # Get the source branch
1150
1219
        (tree, br_from,
1151
 
         _unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
 
1220
         _unused) = controldir.ControlDir.open_containing_tree_or_branch(directory)
1152
1221
        # Get the tip's revision_id
1153
1222
        revision = _get_one_revision('push', revision)
1154
1223
        if revision is not None:
1175
1244
                    # error by the feedback given to them. RBC 20080227.
1176
1245
                    stacked_on = parent_url
1177
1246
            if not stacked_on:
1178
 
                raise errors.BzrCommandError(
1179
 
                    "Could not determine branch to refer to.")
 
1247
                raise errors.BzrCommandError(gettext(
 
1248
                    "Could not determine branch to refer to."))
1180
1249
 
1181
1250
        # Get the destination location
1182
1251
        if location is None:
1183
1252
            stored_loc = br_from.get_push_location()
1184
1253
            if stored_loc is None:
1185
 
                raise errors.BzrCommandError(
1186
 
                    "No push location known or specified.")
 
1254
                parent_loc = br_from.get_parent()
 
1255
                if parent_loc:
 
1256
                    raise errors.BzrCommandError(gettext(
 
1257
                        "No push location known or specified. To push to the "
 
1258
                        "parent branch (at %s), use 'bzr push :parent'." %
 
1259
                        urlutils.unescape_for_display(parent_loc,
 
1260
                            self.outf.encoding)))
 
1261
                else:
 
1262
                    raise errors.BzrCommandError(gettext(
 
1263
                        "No push location known or specified."))
1187
1264
            else:
1188
1265
                display_url = urlutils.unescape_for_display(stored_loc,
1189
1266
                        self.outf.encoding)
1190
 
                self.outf.write("Using saved push location: %s\n" % display_url)
 
1267
                note(gettext("Using saved push location: %s") % display_url)
1191
1268
                location = stored_loc
1192
1269
 
1193
1270
        _show_push_branch(br_from, revision_id, location, self.outf,
1251
1328
                deprecated_name=self.invoked_as,
1252
1329
                recommended_name='branch',
1253
1330
                deprecated_in_version='2.4')
1254
 
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
 
1331
        accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1255
1332
            from_location)
1256
1333
        if not (hardlink or files_from):
1257
1334
            # accelerator_tree is usually slower because you have to read N
1270
1347
            # RBC 20060209
1271
1348
            revision_id = br_from.last_revision()
1272
1349
        if to_location is None:
1273
 
            to_location = urlutils.derive_to_location(from_location)
 
1350
            to_location = getattr(br_from, "name", None)
 
1351
            if to_location is None:
 
1352
                to_location = urlutils.derive_to_location(from_location)
1274
1353
        to_transport = transport.get_transport(to_location)
1275
1354
        try:
1276
1355
            to_transport.mkdir('.')
1277
1356
        except errors.FileExists:
1278
 
            if not use_existing_dir:
1279
 
                raise errors.BzrCommandError('Target directory "%s" '
1280
 
                    'already exists.' % to_location)
 
1357
            try:
 
1358
                to_dir = controldir.ControlDir.open_from_transport(
 
1359
                    to_transport)
 
1360
            except errors.NotBranchError:
 
1361
                if not use_existing_dir:
 
1362
                    raise errors.BzrCommandError(gettext('Target directory "%s" '
 
1363
                        'already exists.') % to_location)
 
1364
                else:
 
1365
                    to_dir = None
1281
1366
            else:
1282
1367
                try:
1283
 
                    bzrdir.BzrDir.open_from_transport(to_transport)
 
1368
                    to_dir.open_branch()
1284
1369
                except errors.NotBranchError:
1285
1370
                    pass
1286
1371
                else:
1287
1372
                    raise errors.AlreadyBranchError(to_location)
1288
1373
        except errors.NoSuchFile:
1289
 
            raise errors.BzrCommandError('Parent of "%s" does not exist.'
 
1374
            raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1290
1375
                                         % to_location)
1291
 
        try:
1292
 
            # preserve whatever source format we have.
1293
 
            dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1294
 
                                        possible_transports=[to_transport],
1295
 
                                        accelerator_tree=accelerator_tree,
1296
 
                                        hardlink=hardlink, stacked=stacked,
1297
 
                                        force_new_repo=standalone,
1298
 
                                        create_tree_if_local=not no_tree,
1299
 
                                        source_branch=br_from)
1300
 
            branch = dir.open_branch()
1301
 
        except errors.NoSuchRevision:
1302
 
            to_transport.delete_tree('.')
1303
 
            msg = "The branch %s has no revision %s." % (from_location,
1304
 
                revision)
1305
 
            raise errors.BzrCommandError(msg)
 
1376
        else:
 
1377
            to_dir = None
 
1378
        if to_dir is None:
 
1379
            try:
 
1380
                # preserve whatever source format we have.
 
1381
                to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
 
1382
                                            possible_transports=[to_transport],
 
1383
                                            accelerator_tree=accelerator_tree,
 
1384
                                            hardlink=hardlink, stacked=stacked,
 
1385
                                            force_new_repo=standalone,
 
1386
                                            create_tree_if_local=not no_tree,
 
1387
                                            source_branch=br_from)
 
1388
                branch = to_dir.open_branch(
 
1389
                    possible_transports=[
 
1390
                        br_from.bzrdir.root_transport, to_transport])
 
1391
            except errors.NoSuchRevision:
 
1392
                to_transport.delete_tree('.')
 
1393
                msg = gettext("The branch {0} has no revision {1}.").format(
 
1394
                    from_location, revision)
 
1395
                raise errors.BzrCommandError(msg)
 
1396
        else:
 
1397
            branch = br_from.sprout(to_dir, revision_id=revision_id)
1306
1398
        _merge_tags_if_possible(br_from, branch)
1307
1399
        # If the source branch is stacked, the new branch may
1308
1400
        # be stacked whether we asked for that explicitly or not.
1309
1401
        # We therefore need a try/except here and not just 'if stacked:'
1310
1402
        try:
1311
 
            note('Created new stacked branch referring to %s.' %
 
1403
            note(gettext('Created new stacked branch referring to %s.') %
1312
1404
                branch.get_stacked_on_url())
1313
1405
        except (errors.NotStacked, errors.UnstackableBranchFormat,
1314
1406
            errors.UnstackableRepositoryFormat), e:
1315
 
            note('Branched %d revision(s).' % branch.revno())
 
1407
            note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1316
1408
        if bind:
1317
1409
            # Bind to the parent
1318
1410
            parent_branch = Branch.open(from_location)
1319
1411
            branch.bind(parent_branch)
1320
 
            note('New branch bound to %s' % from_location)
 
1412
            note(gettext('New branch bound to %s') % from_location)
1321
1413
        if switch:
1322
1414
            # Switch to the new branch
1323
1415
            wt, _ = WorkingTree.open_containing('.')
1324
1416
            _mod_switch.switch(wt.bzrdir, branch)
1325
 
            note('Switched to branch: %s',
 
1417
            note(gettext('Switched to branch: %s'),
1326
1418
                urlutils.unescape_for_display(branch.base, 'utf-8'))
1327
1419
 
1328
1420
 
 
1421
class cmd_branches(Command):
 
1422
    __doc__ = """List the branches available at the current location.
 
1423
 
 
1424
    This command will print the names of all the branches at the current
 
1425
    location.
 
1426
    """
 
1427
 
 
1428
    takes_args = ['location?']
 
1429
    takes_options = [
 
1430
                  Option('recursive', short_name='R',
 
1431
                         help='Recursively scan for branches rather than '
 
1432
                              'just looking in the specified location.')]
 
1433
 
 
1434
    def run(self, location=".", recursive=False):
 
1435
        if recursive:
 
1436
            t = transport.get_transport(location)
 
1437
            if not t.listable():
 
1438
                raise errors.BzrCommandError(
 
1439
                    "Can't scan this type of location.")
 
1440
            for b in controldir.ControlDir.find_branches(t):
 
1441
                self.outf.write("%s\n" % urlutils.unescape_for_display(
 
1442
                    urlutils.relative_url(t.base, b.base),
 
1443
                    self.outf.encoding).rstrip("/"))
 
1444
        else:
 
1445
            dir = controldir.ControlDir.open_containing(location)[0]
 
1446
            try:
 
1447
                active_branch = dir.open_branch(name=None)
 
1448
            except errors.NotBranchError:
 
1449
                active_branch = None
 
1450
            branches = dir.get_branches()
 
1451
            names = {}
 
1452
            for name, branch in branches.iteritems():
 
1453
                if name is None:
 
1454
                    continue
 
1455
                active = (active_branch is not None and
 
1456
                          active_branch.base == branch.base)
 
1457
                names[name] = active
 
1458
            # Only mention the current branch explicitly if it's not
 
1459
            # one of the colocated branches
 
1460
            if not any(names.values()) and active_branch is not None:
 
1461
                self.outf.write("* %s\n" % gettext("(default)"))
 
1462
            for name in sorted(names.keys()):
 
1463
                active = names[name]
 
1464
                if active:
 
1465
                    prefix = "*"
 
1466
                else:
 
1467
                    prefix = " "
 
1468
                self.outf.write("%s %s\n" % (
 
1469
                    prefix, name.encode(self.outf.encoding)))
 
1470
 
 
1471
 
1329
1472
class cmd_checkout(Command):
1330
1473
    __doc__ = """Create a new checkout of an existing branch.
1331
1474
 
1370
1513
        if branch_location is None:
1371
1514
            branch_location = osutils.getcwd()
1372
1515
            to_location = branch_location
1373
 
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
 
1516
        accelerator_tree, source = controldir.ControlDir.open_tree_or_branch(
1374
1517
            branch_location)
1375
1518
        if not (hardlink or files_from):
1376
1519
            # accelerator_tree is usually slower because you have to read N
1431
1574
 
1432
1575
 
1433
1576
class cmd_update(Command):
1434
 
    __doc__ = """Update a tree to have the latest code committed to its branch.
1435
 
 
1436
 
    This will perform a merge into the working tree, and may generate
1437
 
    conflicts. If you have any local changes, you will still
1438
 
    need to commit them after the update for the update to be complete.
1439
 
 
1440
 
    If you want to discard your local changes, you can just do a
1441
 
    'bzr revert' instead of 'bzr commit' after the update.
1442
 
 
1443
 
    If you want to restore a file that has been removed locally, use
1444
 
    'bzr revert' instead of 'bzr update'.
1445
 
 
1446
 
    If the tree's branch is bound to a master branch, it will also update
 
1577
    __doc__ = """Update a working tree to a new revision.
 
1578
 
 
1579
    This will perform a merge of the destination revision (the tip of the
 
1580
    branch, or the specified revision) into the working tree, and then make
 
1581
    that revision the basis revision for the working tree.  
 
1582
 
 
1583
    You can use this to visit an older revision, or to update a working tree
 
1584
    that is out of date from its branch.
 
1585
    
 
1586
    If there are any uncommitted changes in the tree, they will be carried
 
1587
    across and remain as uncommitted changes after the update.  To discard
 
1588
    these changes, use 'bzr revert'.  The uncommitted changes may conflict
 
1589
    with the changes brought in by the change in basis revision.
 
1590
 
 
1591
    If the tree's branch is bound to a master branch, bzr will also update
1447
1592
    the branch from the master.
 
1593
 
 
1594
    You cannot update just a single file or directory, because each Bazaar
 
1595
    working tree has just a single basis revision.  If you want to restore a
 
1596
    file that has been removed locally, use 'bzr revert' instead of 'bzr
 
1597
    update'.  If you want to restore a file to its state in a previous
 
1598
    revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
 
1599
    out the old content of that file to a new location.
 
1600
 
 
1601
    The 'dir' argument, if given, must be the location of the root of a
 
1602
    working tree to update.  By default, the working tree that contains the 
 
1603
    current working directory is used.
1448
1604
    """
1449
1605
 
1450
1606
    _see_also = ['pull', 'working-trees', 'status-flags']
1455
1611
                     ]
1456
1612
    aliases = ['up']
1457
1613
 
1458
 
    def run(self, dir='.', revision=None, show_base=None):
 
1614
    def run(self, dir=None, revision=None, show_base=None):
1459
1615
        if revision is not None and len(revision) != 1:
1460
 
            raise errors.BzrCommandError(
1461
 
                        "bzr update --revision takes exactly one revision")
1462
 
        tree = WorkingTree.open_containing(dir)[0]
 
1616
            raise errors.BzrCommandError(gettext(
 
1617
                "bzr update --revision takes exactly one revision"))
 
1618
        if dir is None:
 
1619
            tree = WorkingTree.open_containing('.')[0]
 
1620
        else:
 
1621
            tree, relpath = WorkingTree.open_containing(dir)
 
1622
            if relpath:
 
1623
                # See bug 557886.
 
1624
                raise errors.BzrCommandError(gettext(
 
1625
                    "bzr update can only update a whole tree, "
 
1626
                    "not a file or subdirectory"))
1463
1627
        branch = tree.branch
1464
1628
        possible_transports = []
1465
1629
        master = branch.get_master_branch(
1489
1653
            revision_id = branch.last_revision()
1490
1654
        if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1491
1655
            revno = branch.revision_id_to_dotted_revno(revision_id)
1492
 
            note("Tree is up to date at revision %s of branch %s" %
1493
 
                ('.'.join(map(str, revno)), branch_location))
 
1656
            note(gettext("Tree is up to date at revision {0} of branch {1}"
 
1657
                        ).format('.'.join(map(str, revno)), branch_location))
1494
1658
            return 0
1495
1659
        view_info = _get_view_info_for_change_reporter(tree)
1496
1660
        change_reporter = delta._ChangeReporter(
1504
1668
                old_tip=old_tip,
1505
1669
                show_base=show_base)
1506
1670
        except errors.NoSuchRevision, e:
1507
 
            raise errors.BzrCommandError(
 
1671
            raise errors.BzrCommandError(gettext(
1508
1672
                                  "branch has no revision %s\n"
1509
1673
                                  "bzr update --revision only works"
1510
 
                                  " for a revision in the branch history"
 
1674
                                  " for a revision in the branch history")
1511
1675
                                  % (e.revision))
1512
1676
        revno = tree.branch.revision_id_to_dotted_revno(
1513
1677
            _mod_revision.ensure_null(tree.last_revision()))
1514
 
        note('Updated to revision %s of branch %s' %
1515
 
             ('.'.join(map(str, revno)), branch_location))
 
1678
        note(gettext('Updated to revision {0} of branch {1}').format(
 
1679
             '.'.join(map(str, revno)), branch_location))
1516
1680
        parent_ids = tree.get_parent_ids()
1517
1681
        if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1518
 
            note('Your local commits will now show as pending merges with '
1519
 
                 "'bzr status', and can be committed with 'bzr commit'.")
 
1682
            note(gettext('Your local commits will now show as pending merges with '
 
1683
                 "'bzr status', and can be committed with 'bzr commit'."))
1520
1684
        if conflicts != 0:
1521
1685
            return 1
1522
1686
        else:
1563
1727
        else:
1564
1728
            noise_level = 0
1565
1729
        from bzrlib.info import show_bzrdir_info
1566
 
        show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
 
1730
        show_bzrdir_info(controldir.ControlDir.open_containing(location)[0],
1567
1731
                         verbose=noise_level, outfile=self.outf)
1568
1732
 
1569
1733
 
1594
1758
    def run(self, file_list, verbose=False, new=False,
1595
1759
        file_deletion_strategy='safe'):
1596
1760
        if file_deletion_strategy == 'force':
1597
 
            note("(The --force option is deprecated, rather use --no-backup "
1598
 
                "in future.)")
 
1761
            note(gettext("(The --force option is deprecated, rather use --no-backup "
 
1762
                "in future.)"))
1599
1763
            file_deletion_strategy = 'no-backup'
1600
1764
 
1601
1765
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1611
1775
                specific_files=file_list).added
1612
1776
            file_list = sorted([f[0] for f in added], reverse=True)
1613
1777
            if len(file_list) == 0:
1614
 
                raise errors.BzrCommandError('No matching files.')
 
1778
                raise errors.BzrCommandError(gettext('No matching files.'))
1615
1779
        elif file_list is None:
1616
1780
            # missing files show up in iter_changes(basis) as
1617
1781
            # versioned-with-no-kind.
1701
1865
 
1702
1866
    def run(self, branch=".", canonicalize_chks=False):
1703
1867
        from bzrlib.reconcile import reconcile
1704
 
        dir = bzrdir.BzrDir.open(branch)
 
1868
        dir = controldir.ControlDir.open(branch)
1705
1869
        reconcile(dir, canonicalize_chks=canonicalize_chks)
1706
1870
 
1707
1871
 
1716
1880
    @display_command
1717
1881
    def run(self, location="."):
1718
1882
        branch = Branch.open_containing(location)[0]
1719
 
        for revid in branch.revision_history():
 
1883
        self.add_cleanup(branch.lock_read().unlock)
 
1884
        graph = branch.repository.get_graph()
 
1885
        history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
 
1886
            [_mod_revision.NULL_REVISION]))
 
1887
        for revid in reversed(history):
1720
1888
            self.outf.write(revid)
1721
1889
            self.outf.write('\n')
1722
1890
 
1740
1908
            b = wt.branch
1741
1909
            last_revision = wt.last_revision()
1742
1910
 
1743
 
        revision_ids = b.repository.get_ancestry(last_revision)
1744
 
        revision_ids.pop(0)
1745
 
        for revision_id in revision_ids:
 
1911
        self.add_cleanup(b.repository.lock_read().unlock)
 
1912
        graph = b.repository.get_graph()
 
1913
        revisions = [revid for revid, parents in
 
1914
            graph.iter_ancestry([last_revision])]
 
1915
        for revision_id in reversed(revisions):
 
1916
            if _mod_revision.is_null(revision_id):
 
1917
                continue
1746
1918
            self.outf.write(revision_id + '\n')
1747
1919
 
1748
1920
 
1779
1951
                help='Specify a format for this branch. '
1780
1952
                'See "help formats".',
1781
1953
                lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1782
 
                converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
1954
                converter=lambda name: controldir.format_registry.make_bzrdir(name),
1783
1955
                value_switches=True,
1784
1956
                title="Branch format",
1785
1957
                ),
1792
1964
    def run(self, location=None, format=None, append_revisions_only=False,
1793
1965
            create_prefix=False, no_tree=False):
1794
1966
        if format is None:
1795
 
            format = bzrdir.format_registry.make_bzrdir('default')
 
1967
            format = controldir.format_registry.make_bzrdir('default')
1796
1968
        if location is None:
1797
1969
            location = u'.'
1798
1970
 
1807
1979
            to_transport.ensure_base()
1808
1980
        except errors.NoSuchFile:
1809
1981
            if not create_prefix:
1810
 
                raise errors.BzrCommandError("Parent directory of %s"
 
1982
                raise errors.BzrCommandError(gettext("Parent directory of %s"
1811
1983
                    " does not exist."
1812
1984
                    "\nYou may supply --create-prefix to create all"
1813
 
                    " leading parent directories."
 
1985
                    " leading parent directories.")
1814
1986
                    % location)
1815
1987
            to_transport.create_prefix()
1816
1988
 
1817
1989
        try:
1818
 
            a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
 
1990
            a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
1819
1991
        except errors.NotBranchError:
1820
1992
            # really a NotBzrDir error...
1821
 
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1993
            create_branch = controldir.ControlDir.create_branch_convenience
1822
1994
            if no_tree:
1823
1995
                force_new_tree = False
1824
1996
            else:
1835
2007
                        raise errors.BranchExistsWithoutWorkingTree(location)
1836
2008
                raise errors.AlreadyBranchError(location)
1837
2009
            branch = a_bzrdir.create_branch()
1838
 
            if not no_tree:
 
2010
            if not no_tree and not a_bzrdir.has_workingtree():
1839
2011
                a_bzrdir.create_workingtree()
1840
2012
        if append_revisions_only:
1841
2013
            try:
1842
2014
                branch.set_append_revisions_only(True)
1843
2015
            except errors.UpgradeRequired:
1844
 
                raise errors.BzrCommandError('This branch format cannot be set'
1845
 
                    ' to append-revisions-only.  Try --default.')
 
2016
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
 
2017
                    ' to append-revisions-only.  Try --default.'))
1846
2018
        if not is_quiet():
1847
2019
            from bzrlib.info import describe_layout, describe_format
1848
2020
            try:
1852
2024
            repository = branch.repository
1853
2025
            layout = describe_layout(repository, branch, tree).lower()
1854
2026
            format = describe_format(a_bzrdir, repository, branch, tree)
1855
 
            self.outf.write("Created a %s (format: %s)\n" % (layout, format))
 
2027
            self.outf.write(gettext("Created a {0} (format: {1})\n").format(
 
2028
                  layout, format))
1856
2029
            if repository.is_shared():
1857
2030
                #XXX: maybe this can be refactored into transport.path_or_url()
1858
2031
                url = repository.bzrdir.root_transport.external_url()
1860
2033
                    url = urlutils.local_path_from_url(url)
1861
2034
                except errors.InvalidURL:
1862
2035
                    pass
1863
 
                self.outf.write("Using shared repository: %s\n" % url)
 
2036
                self.outf.write(gettext("Using shared repository: %s\n") % url)
1864
2037
 
1865
2038
 
1866
2039
class cmd_init_repository(Command):
1896
2069
    takes_options = [RegistryOption('format',
1897
2070
                            help='Specify a format for this repository. See'
1898
2071
                                 ' "bzr help formats" for details.',
1899
 
                            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1900
 
                            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
2072
                            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
2073
                            converter=lambda name: controldir.format_registry.make_bzrdir(name),
1901
2074
                            value_switches=True, title='Repository format'),
1902
2075
                     Option('no-trees',
1903
2076
                             help='Branches in the repository will default to'
1907
2080
 
1908
2081
    def run(self, location, format=None, no_trees=False):
1909
2082
        if format is None:
1910
 
            format = bzrdir.format_registry.make_bzrdir('default')
 
2083
            format = controldir.format_registry.make_bzrdir('default')
1911
2084
 
1912
2085
        if location is None:
1913
2086
            location = '.'
1914
2087
 
1915
2088
        to_transport = transport.get_transport(location)
1916
 
        to_transport.ensure_base()
1917
2089
 
1918
 
        newdir = format.initialize_on_transport(to_transport)
1919
 
        repo = newdir.create_repository(shared=True)
1920
 
        repo.set_make_working_trees(not no_trees)
 
2090
        (repo, newdir, require_stacking, repository_policy) = (
 
2091
            format.initialize_on_transport_ex(to_transport,
 
2092
            create_prefix=True, make_working_trees=not no_trees,
 
2093
            shared_repo=True, force_new_repo=True,
 
2094
            use_existing_dir=True,
 
2095
            repo_format_name=format.repository_format.get_format_string()))
1921
2096
        if not is_quiet():
1922
2097
            from bzrlib.info import show_bzrdir_info
1923
 
            show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
 
2098
            show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
1924
2099
 
1925
2100
 
1926
2101
class cmd_diff(Command):
2057
2232
        elif ':' in prefix:
2058
2233
            old_label, new_label = prefix.split(":")
2059
2234
        else:
2060
 
            raise errors.BzrCommandError(
 
2235
            raise errors.BzrCommandError(gettext(
2061
2236
                '--prefix expects two values separated by a colon'
2062
 
                ' (eg "old/:new/")')
 
2237
                ' (eg "old/:new/")'))
2063
2238
 
2064
2239
        if revision and len(revision) > 2:
2065
 
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
2066
 
                                         ' one or two revision specifiers')
 
2240
            raise errors.BzrCommandError(gettext('bzr diff --revision takes exactly'
 
2241
                                         ' one or two revision specifiers'))
2067
2242
 
2068
2243
        if using is not None and format is not None:
2069
 
            raise errors.BzrCommandError('--using and --format are mutually '
2070
 
                'exclusive.')
 
2244
            raise errors.BzrCommandError(gettext(
 
2245
                '{0} and {1} are mutually exclusive').format(
 
2246
                '--using', '--format'))
2071
2247
 
2072
2248
        (old_tree, new_tree,
2073
2249
         old_branch, new_branch,
2150
2326
        basis_inv = basis.inventory
2151
2327
        inv = wt.inventory
2152
2328
        for file_id in inv:
2153
 
            if file_id in basis_inv:
 
2329
            if basis_inv.has_id(file_id):
2154
2330
                continue
2155
2331
            if inv.is_root(file_id) and len(basis_inv) == 0:
2156
2332
                continue
2181
2357
    try:
2182
2358
        return int(limitstring)
2183
2359
    except ValueError:
2184
 
        msg = "The limit argument must be an integer."
 
2360
        msg = gettext("The limit argument must be an integer.")
2185
2361
        raise errors.BzrCommandError(msg)
2186
2362
 
2187
2363
 
2189
2365
    try:
2190
2366
        return int(s)
2191
2367
    except ValueError:
2192
 
        msg = "The levels argument must be an integer."
 
2368
        msg = gettext("The levels argument must be an integer.")
2193
2369
        raise errors.BzrCommandError(msg)
2194
2370
 
2195
2371
 
2305
2481
 
2306
2482
    :Other filtering:
2307
2483
 
2308
 
      The --message option can be used for finding revisions that match a
2309
 
      regular expression in a commit message.
 
2484
      The --match option can be used for finding revisions that match a
 
2485
      regular expression in a commit message, committer, author or bug.
 
2486
      Specifying the option several times will match any of the supplied
 
2487
      expressions. --match-author, --match-bugs, --match-committer and
 
2488
      --match-message can be used to only match a specific field.
2310
2489
 
2311
2490
    :Tips & tricks:
2312
2491
 
2372
2551
                   argname='N',
2373
2552
                   type=_parse_levels),
2374
2553
            Option('message',
2375
 
                   short_name='m',
2376
2554
                   help='Show revisions whose message matches this '
2377
2555
                        'regular expression.',
2378
 
                   type=str),
 
2556
                   type=str,
 
2557
                   hidden=True),
2379
2558
            Option('limit',
2380
2559
                   short_name='l',
2381
2560
                   help='Limit the output to the first N revisions.',
2384
2563
            Option('show-diff',
2385
2564
                   short_name='p',
2386
2565
                   help='Show changes made in each revision as a patch.'),
2387
 
            Option('include-merges',
 
2566
            Option('include-merged',
2388
2567
                   help='Show merged revisions like --levels 0 does.'),
 
2568
            Option('include-merges', hidden=True,
 
2569
                   help='Historical alias for --include-merged.'),
 
2570
            Option('omit-merges',
 
2571
                   help='Do not report commits with more than one parent.'),
2389
2572
            Option('exclude-common-ancestry',
2390
2573
                   help='Display only the revisions that are not part'
2391
 
                   ' of both ancestries (require -rX..Y)'
2392
 
                   )
 
2574
                   ' of both ancestries (require -rX..Y).'
 
2575
                   ),
 
2576
            Option('signatures',
 
2577
                   help='Show digital signature validity.'),
 
2578
            ListOption('match',
 
2579
                short_name='m',
 
2580
                help='Show revisions whose properties match this '
 
2581
                'expression.',
 
2582
                type=str),
 
2583
            ListOption('match-message',
 
2584
                   help='Show revisions whose message matches this '
 
2585
                   'expression.',
 
2586
                type=str),
 
2587
            ListOption('match-committer',
 
2588
                   help='Show revisions whose committer matches this '
 
2589
                   'expression.',
 
2590
                type=str),
 
2591
            ListOption('match-author',
 
2592
                   help='Show revisions whose authors match this '
 
2593
                   'expression.',
 
2594
                type=str),
 
2595
            ListOption('match-bugs',
 
2596
                   help='Show revisions whose bugs match this '
 
2597
                   'expression.',
 
2598
                type=str)
2393
2599
            ]
2394
2600
    encoding_type = 'replace'
2395
2601
 
2405
2611
            message=None,
2406
2612
            limit=None,
2407
2613
            show_diff=False,
2408
 
            include_merges=False,
 
2614
            include_merged=None,
2409
2615
            authors=None,
2410
2616
            exclude_common_ancestry=False,
 
2617
            signatures=False,
 
2618
            match=None,
 
2619
            match_message=None,
 
2620
            match_committer=None,
 
2621
            match_author=None,
 
2622
            match_bugs=None,
 
2623
            omit_merges=False,
 
2624
            include_merges=symbol_versioning.DEPRECATED_PARAMETER,
2411
2625
            ):
2412
2626
        from bzrlib.log import (
2413
2627
            Logger,
2415
2629
            _get_info_for_log_files,
2416
2630
            )
2417
2631
        direction = (forward and 'forward') or 'reverse'
 
2632
        if symbol_versioning.deprecated_passed(include_merges):
 
2633
            ui.ui_factory.show_user_warning(
 
2634
                'deprecated_command_option',
 
2635
                deprecated_name='--include-merges',
 
2636
                recommended_name='--include-merged',
 
2637
                deprecated_in_version='2.5',
 
2638
                command=self.invoked_as)
 
2639
            if include_merged is None:
 
2640
                include_merged = include_merges
 
2641
            else:
 
2642
                raise errors.BzrCommandError(gettext(
 
2643
                    '{0} and {1} are mutually exclusive').format(
 
2644
                    '--include-merges', '--include-merged'))
 
2645
        if include_merged is None:
 
2646
            include_merged = False
2418
2647
        if (exclude_common_ancestry
2419
2648
            and (revision is None or len(revision) != 2)):
2420
 
            raise errors.BzrCommandError(
2421
 
                '--exclude-common-ancestry requires -r with two revisions')
2422
 
        if include_merges:
 
2649
            raise errors.BzrCommandError(gettext(
 
2650
                '--exclude-common-ancestry requires -r with two revisions'))
 
2651
        if include_merged:
2423
2652
            if levels is None:
2424
2653
                levels = 0
2425
2654
            else:
2426
 
                raise errors.BzrCommandError(
2427
 
                    '--levels and --include-merges are mutually exclusive')
 
2655
                raise errors.BzrCommandError(gettext(
 
2656
                    '{0} and {1} are mutually exclusive').format(
 
2657
                    '--levels', '--include-merged'))
2428
2658
 
2429
2659
        if change is not None:
2430
2660
            if len(change) > 1:
2431
2661
                raise errors.RangeInChangeOption()
2432
2662
            if revision is not None:
2433
 
                raise errors.BzrCommandError(
2434
 
                    '--revision and --change are mutually exclusive')
 
2663
                raise errors.BzrCommandError(gettext(
 
2664
                    '{0} and {1} are mutually exclusive').format(
 
2665
                    '--revision', '--change'))
2435
2666
            else:
2436
2667
                revision = change
2437
2668
 
2443
2674
                revision, file_list, self.add_cleanup)
2444
2675
            for relpath, file_id, kind in file_info_list:
2445
2676
                if file_id is None:
2446
 
                    raise errors.BzrCommandError(
2447
 
                        "Path unknown at end or start of revision range: %s" %
 
2677
                    raise errors.BzrCommandError(gettext(
 
2678
                        "Path unknown at end or start of revision range: %s") %
2448
2679
                        relpath)
2449
2680
                # If the relpath is the top of the tree, we log everything
2450
2681
                if relpath == '':
2462
2693
                location = revision[0].get_branch()
2463
2694
            else:
2464
2695
                location = '.'
2465
 
            dir, relpath = bzrdir.BzrDir.open_containing(location)
 
2696
            dir, relpath = controldir.ControlDir.open_containing(location)
2466
2697
            b = dir.open_branch()
2467
2698
            self.add_cleanup(b.lock_read().unlock)
2468
2699
            rev1, rev2 = _get_revision_range(revision, b, self.name())
2469
2700
 
 
2701
        if b.get_config().validate_signatures_in_log():
 
2702
            signatures = True
 
2703
 
 
2704
        if signatures:
 
2705
            if not gpg.GPGStrategy.verify_signatures_available():
 
2706
                raise errors.GpgmeNotInstalled(None)
 
2707
 
2470
2708
        # Decide on the type of delta & diff filtering to use
2471
2709
        # TODO: add an --all-files option to make this configurable & consistent
2472
2710
        if not verbose:
2509
2747
        match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2510
2748
            or delta_type or partial_history)
2511
2749
 
 
2750
        match_dict = {}
 
2751
        if match:
 
2752
            match_dict[''] = match
 
2753
        if match_message:
 
2754
            match_dict['message'] = match_message
 
2755
        if match_committer:
 
2756
            match_dict['committer'] = match_committer
 
2757
        if match_author:
 
2758
            match_dict['author'] = match_author
 
2759
        if match_bugs:
 
2760
            match_dict['bugs'] = match_bugs
 
2761
 
2512
2762
        # Build the LogRequest and execute it
2513
2763
        if len(file_ids) == 0:
2514
2764
            file_ids = None
2517
2767
            start_revision=rev1, end_revision=rev2, limit=limit,
2518
2768
            message_search=message, delta_type=delta_type,
2519
2769
            diff_type=diff_type, _match_using_deltas=match_using_deltas,
2520
 
            exclude_common_ancestry=exclude_common_ancestry,
 
2770
            exclude_common_ancestry=exclude_common_ancestry, match=match_dict,
 
2771
            signature=signatures, omit_merges=omit_merges,
2521
2772
            )
2522
2773
        Logger(b, rqst).show(lf)
2523
2774
 
2540
2791
            # b is taken from revision[0].get_branch(), and
2541
2792
            # show_log will use its revision_history. Having
2542
2793
            # different branches will lead to weird behaviors.
2543
 
            raise errors.BzrCommandError(
 
2794
            raise errors.BzrCommandError(gettext(
2544
2795
                "bzr %s doesn't accept two revisions in different"
2545
 
                " branches." % command_name)
 
2796
                " branches.") % command_name)
2546
2797
        if start_spec.spec is None:
2547
2798
            # Avoid loading all the history.
2548
2799
            rev1 = RevisionInfo(branch, None, None)
2556
2807
        else:
2557
2808
            rev2 = end_spec.in_history(branch)
2558
2809
    else:
2559
 
        raise errors.BzrCommandError(
2560
 
            'bzr %s --revision takes one or two values.' % command_name)
 
2810
        raise errors.BzrCommandError(gettext(
 
2811
            'bzr %s --revision takes one or two values.') % command_name)
2561
2812
    return rev1, rev2
2562
2813
 
2563
2814
 
2634
2885
            null=False, kind=None, show_ids=False, path=None, directory=None):
2635
2886
 
2636
2887
        if kind and kind not in ('file', 'directory', 'symlink'):
2637
 
            raise errors.BzrCommandError('invalid kind specified')
 
2888
            raise errors.BzrCommandError(gettext('invalid kind specified'))
2638
2889
 
2639
2890
        if verbose and null:
2640
 
            raise errors.BzrCommandError('Cannot set both --verbose and --null')
 
2891
            raise errors.BzrCommandError(gettext('Cannot set both --verbose and --null'))
2641
2892
        all = not (unknown or versioned or ignored)
2642
2893
 
2643
2894
        selection = {'I':ignored, '?':unknown, 'V':versioned}
2646
2897
            fs_path = '.'
2647
2898
        else:
2648
2899
            if from_root:
2649
 
                raise errors.BzrCommandError('cannot specify both --from-root'
2650
 
                                             ' and PATH')
 
2900
                raise errors.BzrCommandError(gettext('cannot specify both --from-root'
 
2901
                                             ' and PATH'))
2651
2902
            fs_path = path
2652
2903
        tree, branch, relpath = \
2653
2904
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
2669
2920
            if view_files:
2670
2921
                apply_view = True
2671
2922
                view_str = views.view_display_str(view_files)
2672
 
                note("Ignoring files outside view. View is %s" % view_str)
 
2923
                note(gettext("Ignoring files outside view. View is %s") % view_str)
2673
2924
 
2674
2925
        self.add_cleanup(tree.lock_read().unlock)
2675
2926
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
2822
3073
                self.outf.write("%s\n" % pattern)
2823
3074
            return
2824
3075
        if not name_pattern_list:
2825
 
            raise errors.BzrCommandError("ignore requires at least one "
2826
 
                "NAME_PATTERN or --default-rules.")
 
3076
            raise errors.BzrCommandError(gettext("ignore requires at least one "
 
3077
                "NAME_PATTERN or --default-rules."))
2827
3078
        name_pattern_list = [globbing.normalize_pattern(p)
2828
3079
                             for p in name_pattern_list]
2829
3080
        bad_patterns = ''
 
3081
        bad_patterns_count = 0
2830
3082
        for p in name_pattern_list:
2831
3083
            if not globbing.Globster.is_pattern_valid(p):
 
3084
                bad_patterns_count += 1
2832
3085
                bad_patterns += ('\n  %s' % p)
2833
3086
        if bad_patterns:
2834
 
            msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
 
3087
            msg = (ngettext('Invalid ignore pattern found. %s', 
 
3088
                            'Invalid ignore patterns found. %s',
 
3089
                            bad_patterns_count) % bad_patterns)
2835
3090
            ui.ui_factory.show_error(msg)
2836
3091
            raise errors.InvalidPattern('')
2837
3092
        for name_pattern in name_pattern_list:
2838
3093
            if (name_pattern[0] == '/' or
2839
3094
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2840
 
                raise errors.BzrCommandError(
2841
 
                    "NAME_PATTERN should not be an absolute path")
 
3095
                raise errors.BzrCommandError(gettext(
 
3096
                    "NAME_PATTERN should not be an absolute path"))
2842
3097
        tree, relpath = WorkingTree.open_containing(directory)
2843
3098
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2844
3099
        ignored = globbing.Globster(name_pattern_list)
2851
3106
                if ignored.match(filename):
2852
3107
                    matches.append(filename)
2853
3108
        if len(matches) > 0:
2854
 
            self.outf.write("Warning: the following files are version controlled and"
2855
 
                  " match your ignore pattern:\n%s"
 
3109
            self.outf.write(gettext("Warning: the following files are version "
 
3110
                  "controlled and match your ignore pattern:\n%s"
2856
3111
                  "\nThese files will continue to be version controlled"
2857
 
                  " unless you 'bzr remove' them.\n" % ("\n".join(matches),))
 
3112
                  " unless you 'bzr remove' them.\n") % ("\n".join(matches),))
2858
3113
 
2859
3114
 
2860
3115
class cmd_ignored(Command):
2899
3154
        try:
2900
3155
            revno = int(revno)
2901
3156
        except ValueError:
2902
 
            raise errors.BzrCommandError("not a valid revision-number: %r"
 
3157
            raise errors.BzrCommandError(gettext("not a valid revision-number: %r")
2903
3158
                                         % revno)
2904
3159
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2905
3160
        self.outf.write("%s\n" % revid)
2948
3203
        Option('per-file-timestamps',
2949
3204
               help='Set modification time of files to that of the last '
2950
3205
                    'revision in which it was changed.'),
 
3206
        Option('uncommitted',
 
3207
               help='Export the working tree contents rather than that of the '
 
3208
                    'last revision.'),
2951
3209
        ]
2952
3210
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2953
 
        root=None, filters=False, per_file_timestamps=False, directory=u'.'):
 
3211
        root=None, filters=False, per_file_timestamps=False, uncommitted=False,
 
3212
        directory=u'.'):
2954
3213
        from bzrlib.export import export
2955
3214
 
2956
3215
        if branch_or_subdir is None:
2957
 
            tree = WorkingTree.open_containing(directory)[0]
2958
 
            b = tree.branch
2959
 
            subdir = None
 
3216
            branch_or_subdir = directory
 
3217
 
 
3218
        (tree, b, subdir) = controldir.ControlDir.open_containing_tree_or_branch(
 
3219
            branch_or_subdir)
 
3220
        if tree is not None:
 
3221
            self.add_cleanup(tree.lock_read().unlock)
 
3222
 
 
3223
        if uncommitted:
 
3224
            if tree is None:
 
3225
                raise errors.BzrCommandError(
 
3226
                    gettext("--uncommitted requires a working tree"))
 
3227
            export_tree = tree
2960
3228
        else:
2961
 
            b, subdir = Branch.open_containing(branch_or_subdir)
2962
 
            tree = None
2963
 
 
2964
 
        rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
 
3229
            export_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
2965
3230
        try:
2966
 
            export(rev_tree, dest, format, root, subdir, filtered=filters,
 
3231
            export(export_tree, dest, format, root, subdir, filtered=filters,
2967
3232
                   per_file_timestamps=per_file_timestamps)
2968
3233
        except errors.NoSuchExportFormat, e:
2969
 
            raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
 
3234
            raise errors.BzrCommandError(
 
3235
                gettext('Unsupported export format: %s') % e.format)
2970
3236
 
2971
3237
 
2972
3238
class cmd_cat(Command):
2992
3258
    def run(self, filename, revision=None, name_from_revision=False,
2993
3259
            filters=False, directory=None):
2994
3260
        if revision is not None and len(revision) != 1:
2995
 
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2996
 
                                         " one revision specifier")
 
3261
            raise errors.BzrCommandError(gettext("bzr cat --revision takes exactly"
 
3262
                                         " one revision specifier"))
2997
3263
        tree, branch, relpath = \
2998
3264
            _open_directory_or_containing_tree_or_branch(filename, directory)
2999
3265
        self.add_cleanup(branch.lock_read().unlock)
3009
3275
 
3010
3276
        old_file_id = rev_tree.path2id(relpath)
3011
3277
 
 
3278
        # TODO: Split out this code to something that generically finds the
 
3279
        # best id for a path across one or more trees; it's like
 
3280
        # find_ids_across_trees but restricted to find just one. -- mbp
 
3281
        # 20110705.
3012
3282
        if name_from_revision:
3013
3283
            # Try in revision if requested
3014
3284
            if old_file_id is None:
3015
 
                raise errors.BzrCommandError(
3016
 
                    "%r is not present in revision %s" % (
 
3285
                raise errors.BzrCommandError(gettext(
 
3286
                    "{0!r} is not present in revision {1}").format(
3017
3287
                        filename, rev_tree.get_revision_id()))
3018
3288
            else:
3019
 
                content = rev_tree.get_file_text(old_file_id)
 
3289
                actual_file_id = old_file_id
3020
3290
        else:
3021
3291
            cur_file_id = tree.path2id(relpath)
3022
 
            found = False
3023
 
            if cur_file_id is not None:
3024
 
                # Then try with the actual file id
3025
 
                try:
3026
 
                    content = rev_tree.get_file_text(cur_file_id)
3027
 
                    found = True
3028
 
                except errors.NoSuchId:
3029
 
                    # The actual file id didn't exist at that time
3030
 
                    pass
3031
 
            if not found and old_file_id is not None:
3032
 
                # Finally try with the old file id
3033
 
                content = rev_tree.get_file_text(old_file_id)
3034
 
                found = True
3035
 
            if not found:
3036
 
                # Can't be found anywhere
3037
 
                raise errors.BzrCommandError(
3038
 
                    "%r is not present in revision %s" % (
 
3292
            if cur_file_id is not None and rev_tree.has_id(cur_file_id):
 
3293
                actual_file_id = cur_file_id
 
3294
            elif old_file_id is not None:
 
3295
                actual_file_id = old_file_id
 
3296
            else:
 
3297
                raise errors.BzrCommandError(gettext(
 
3298
                    "{0!r} is not present in revision {1}").format(
3039
3299
                        filename, rev_tree.get_revision_id()))
3040
3300
        if filtered:
3041
 
            from bzrlib.filters import (
3042
 
                ContentFilterContext,
3043
 
                filtered_output_bytes,
3044
 
                )
3045
 
            filters = rev_tree._content_filter_stack(relpath)
3046
 
            chunks = content.splitlines(True)
3047
 
            content = filtered_output_bytes(chunks, filters,
3048
 
                ContentFilterContext(relpath, rev_tree))
3049
 
            self.cleanup_now()
3050
 
            self.outf.writelines(content)
 
3301
            from bzrlib.filter_tree import ContentFilterTree
 
3302
            filter_tree = ContentFilterTree(rev_tree,
 
3303
                rev_tree._content_filter_stack)
 
3304
            content = filter_tree.get_file_text(actual_file_id)
3051
3305
        else:
3052
 
            self.cleanup_now()
3053
 
            self.outf.write(content)
 
3306
            content = rev_tree.get_file_text(actual_file_id)
 
3307
        self.cleanup_now()
 
3308
        self.outf.write(content)
3054
3309
 
3055
3310
 
3056
3311
class cmd_local_time_offset(Command):
3163
3418
    aliases = ['ci', 'checkin']
3164
3419
 
3165
3420
    def _iter_bug_fix_urls(self, fixes, branch):
 
3421
        default_bugtracker  = None
3166
3422
        # Configure the properties for bug fixing attributes.
3167
3423
        for fixed_bug in fixes:
3168
3424
            tokens = fixed_bug.split(':')
3169
 
            if len(tokens) != 2:
3170
 
                raise errors.BzrCommandError(
 
3425
            if len(tokens) == 1:
 
3426
                if default_bugtracker is None:
 
3427
                    branch_config = branch.get_config()
 
3428
                    default_bugtracker = branch_config.get_user_option(
 
3429
                        "bugtracker")
 
3430
                if default_bugtracker is None:
 
3431
                    raise errors.BzrCommandError(gettext(
 
3432
                        "No tracker specified for bug %s. Use the form "
 
3433
                        "'tracker:id' or specify a default bug tracker "
 
3434
                        "using the `bugtracker` option.\nSee "
 
3435
                        "\"bzr help bugs\" for more information on this "
 
3436
                        "feature. Commit refused.") % fixed_bug)
 
3437
                tag = default_bugtracker
 
3438
                bug_id = tokens[0]
 
3439
            elif len(tokens) != 2:
 
3440
                raise errors.BzrCommandError(gettext(
3171
3441
                    "Invalid bug %s. Must be in the form of 'tracker:id'. "
3172
3442
                    "See \"bzr help bugs\" for more information on this "
3173
 
                    "feature.\nCommit refused." % fixed_bug)
3174
 
            tag, bug_id = tokens
 
3443
                    "feature.\nCommit refused.") % fixed_bug)
 
3444
            else:
 
3445
                tag, bug_id = tokens
3175
3446
            try:
3176
3447
                yield bugtracker.get_bug_url(tag, branch, bug_id)
3177
3448
            except errors.UnknownBugTrackerAbbreviation:
3178
 
                raise errors.BzrCommandError(
3179
 
                    'Unrecognized bug %s. Commit refused.' % fixed_bug)
 
3449
                raise errors.BzrCommandError(gettext(
 
3450
                    'Unrecognized bug %s. Commit refused.') % fixed_bug)
3180
3451
            except errors.MalformedBugIdentifier, e:
3181
 
                raise errors.BzrCommandError(
3182
 
                    "%s\nCommit refused." % (str(e),))
 
3452
                raise errors.BzrCommandError(gettext(
 
3453
                    "%s\nCommit refused.") % (str(e),))
3183
3454
 
3184
3455
    def run(self, message=None, file=None, verbose=False, selected_list=None,
3185
3456
            unchanged=False, strict=False, local=False, fixes=None,
3193
3464
        from bzrlib.msgeditor import (
3194
3465
            edit_commit_message_encoded,
3195
3466
            generate_commit_message_template,
3196
 
            make_commit_message_template_encoded
 
3467
            make_commit_message_template_encoded,
 
3468
            set_commit_message,
3197
3469
        )
3198
3470
 
3199
3471
        commit_stamp = offset = None
3201
3473
            try:
3202
3474
                commit_stamp, offset = timestamp.parse_patch_date(commit_time)
3203
3475
            except ValueError, e:
3204
 
                raise errors.BzrCommandError(
3205
 
                    "Could not parse --commit-time: " + str(e))
 
3476
                raise errors.BzrCommandError(gettext(
 
3477
                    "Could not parse --commit-time: " + str(e)))
3206
3478
 
3207
3479
        properties = {}
3208
3480
 
3241
3513
                message = message.replace('\r\n', '\n')
3242
3514
                message = message.replace('\r', '\n')
3243
3515
            if file:
3244
 
                raise errors.BzrCommandError(
3245
 
                    "please specify either --message or --file")
 
3516
                raise errors.BzrCommandError(gettext(
 
3517
                    "please specify either --message or --file"))
3246
3518
 
3247
3519
        def get_message(commit_obj):
3248
3520
            """Callback to get commit message"""
3265
3537
                # make_commit_message_template_encoded returns user encoding.
3266
3538
                # We probably want to be using edit_commit_message instead to
3267
3539
                # avoid this.
3268
 
                start_message = generate_commit_message_template(commit_obj)
3269
 
                my_message = edit_commit_message_encoded(text,
3270
 
                    start_message=start_message)
3271
 
                if my_message is None:
3272
 
                    raise errors.BzrCommandError("please specify a commit"
3273
 
                        " message with either --message or --file")
3274
 
            if my_message == "":
3275
 
                raise errors.BzrCommandError("empty commit message specified")
 
3540
                my_message = set_commit_message(commit_obj)
 
3541
                if my_message is None:
 
3542
                    start_message = generate_commit_message_template(commit_obj)
 
3543
                    my_message = edit_commit_message_encoded(text,
 
3544
                        start_message=start_message)
 
3545
                if my_message is None:
 
3546
                    raise errors.BzrCommandError(gettext("please specify a commit"
 
3547
                        " message with either --message or --file"))
 
3548
                if my_message == "":
 
3549
                    raise errors.BzrCommandError(gettext("Empty commit message specified."
 
3550
                            " Please specify a commit message with either"
 
3551
                            " --message or --file or leave a blank message"
 
3552
                            " with --message \"\"."))
3276
3553
            return my_message
3277
3554
 
3278
3555
        # The API permits a commit with a filter of [] to mean 'select nothing'
3289
3566
                        exclude=tree.safe_relpath_files(exclude),
3290
3567
                        lossy=lossy)
3291
3568
        except PointlessCommit:
3292
 
            raise errors.BzrCommandError("No changes to commit."
 
3569
            raise errors.BzrCommandError(gettext("No changes to commit."
3293
3570
                " Please 'bzr add' the files you want to commit, or use"
3294
 
                " --unchanged to force an empty commit.")
 
3571
                " --unchanged to force an empty commit."))
3295
3572
        except ConflictsInTree:
3296
 
            raise errors.BzrCommandError('Conflicts detected in working '
 
3573
            raise errors.BzrCommandError(gettext('Conflicts detected in working '
3297
3574
                'tree.  Use "bzr conflicts" to list, "bzr resolve FILE" to'
3298
 
                ' resolve.')
 
3575
                ' resolve.'))
3299
3576
        except StrictCommitFailed:
3300
 
            raise errors.BzrCommandError("Commit refused because there are"
3301
 
                              " unknown files in the working tree.")
 
3577
            raise errors.BzrCommandError(gettext("Commit refused because there are"
 
3578
                              " unknown files in the working tree."))
3302
3579
        except errors.BoundBranchOutOfDate, e:
3303
 
            e.extra_help = ("\n"
 
3580
            e.extra_help = (gettext("\n"
3304
3581
                'To commit to master branch, run update and then commit.\n'
3305
3582
                'You can also pass --local to commit to continue working '
3306
 
                'disconnected.')
 
3583
                'disconnected.'))
3307
3584
            raise
3308
3585
 
3309
3586
 
3416
3693
        RegistryOption('format',
3417
3694
            help='Upgrade to a specific format.  See "bzr help'
3418
3695
                 ' formats" for details.',
3419
 
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3420
 
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3696
            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
3697
            converter=lambda name: controldir.format_registry.make_bzrdir(name),
3421
3698
            value_switches=True, title='Branch format'),
3422
3699
        Option('clean',
3423
3700
            help='Remove the backup.bzr directory if successful.'),
3464
3741
            if directory is None:
3465
3742
                # use branch if we're inside one; otherwise global config
3466
3743
                try:
3467
 
                    c = Branch.open_containing(u'.')[0].get_config()
 
3744
                    c = Branch.open_containing(u'.')[0].get_config_stack()
3468
3745
                except errors.NotBranchError:
3469
 
                    c = _mod_config.GlobalConfig()
 
3746
                    c = _mod_config.GlobalStack()
3470
3747
            else:
3471
 
                c = Branch.open(directory).get_config()
 
3748
                c = Branch.open(directory).get_config_stack()
 
3749
            identity = c.get('email')
3472
3750
            if email:
3473
 
                self.outf.write(c.user_email() + '\n')
 
3751
                self.outf.write(_mod_config.extract_email_address(identity)
 
3752
                                + '\n')
3474
3753
            else:
3475
 
                self.outf.write(c.username() + '\n')
 
3754
                self.outf.write(identity + '\n')
3476
3755
            return
3477
3756
 
3478
3757
        if email:
3479
 
            raise errors.BzrCommandError("--email can only be used to display existing "
3480
 
                                         "identity")
 
3758
            raise errors.BzrCommandError(gettext("--email can only be used to display existing "
 
3759
                                         "identity"))
3481
3760
 
3482
3761
        # display a warning if an email address isn't included in the given name.
3483
3762
        try:
3489
3768
        # use global config unless --branch given
3490
3769
        if branch:
3491
3770
            if directory is None:
3492
 
                c = Branch.open_containing(u'.')[0].get_config()
 
3771
                c = Branch.open_containing(u'.')[0].get_config_stack()
3493
3772
            else:
3494
 
                c = Branch.open(directory).get_config()
 
3773
                c = Branch.open(directory).get_config_stack()
3495
3774
        else:
3496
 
            c = _mod_config.GlobalConfig()
3497
 
        c.set_user_option('email', name)
 
3775
            c = _mod_config.GlobalStack()
 
3776
        c.set('email', name)
3498
3777
 
3499
3778
 
3500
3779
class cmd_nick(Command):
3562
3841
 
3563
3842
    def remove_alias(self, alias_name):
3564
3843
        if alias_name is None:
3565
 
            raise errors.BzrCommandError(
3566
 
                'bzr alias --remove expects an alias to remove.')
 
3844
            raise errors.BzrCommandError(gettext(
 
3845
                'bzr alias --remove expects an alias to remove.'))
3567
3846
        # If alias is not found, print something like:
3568
3847
        # unalias: foo: not found
3569
3848
        c = _mod_config.GlobalConfig()
3707
3986
                                param_name='starting_with', short_name='s',
3708
3987
                                help=
3709
3988
                                'Load only the tests starting with TESTID.'),
 
3989
                     Option('sync',
 
3990
                            help="By default we disable fsync and fdatasync"
 
3991
                                 " while running the test suite.")
3710
3992
                     ]
3711
3993
    encoding_type = 'replace'
3712
3994
 
3720
4002
            first=False, list_only=False,
3721
4003
            randomize=None, exclude=None, strict=False,
3722
4004
            load_list=None, debugflag=None, starting_with=None, subunit=False,
3723
 
            parallel=None, lsprof_tests=False):
 
4005
            parallel=None, lsprof_tests=False,
 
4006
            sync=False):
 
4007
 
 
4008
        # During selftest, disallow proxying, as it can cause severe
 
4009
        # performance penalties and is only needed for thread
 
4010
        # safety. The selftest command is assumed to not use threads
 
4011
        # too heavily. The call should be as early as possible, as
 
4012
        # error reporting for past duplicate imports won't have useful
 
4013
        # backtraces.
 
4014
        lazy_import.disallow_proxying()
 
4015
 
3724
4016
        from bzrlib import tests
3725
4017
 
3726
4018
        if testspecs_list is not None:
3731
4023
            try:
3732
4024
                from bzrlib.tests import SubUnitBzrRunner
3733
4025
            except ImportError:
3734
 
                raise errors.BzrCommandError("subunit not available. subunit "
3735
 
                    "needs to be installed to use --subunit.")
 
4026
                raise errors.BzrCommandError(gettext("subunit not available. subunit "
 
4027
                    "needs to be installed to use --subunit."))
3736
4028
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3737
4029
            # On Windows, disable automatic conversion of '\n' to '\r\n' in
3738
4030
            # stdout, which would corrupt the subunit stream. 
3747
4039
            self.additional_selftest_args.setdefault(
3748
4040
                'suite_decorators', []).append(parallel)
3749
4041
        if benchmark:
3750
 
            raise errors.BzrCommandError(
 
4042
            raise errors.BzrCommandError(gettext(
3751
4043
                "--benchmark is no longer supported from bzr 2.2; "
3752
 
                "use bzr-usertest instead")
 
4044
                "use bzr-usertest instead"))
3753
4045
        test_suite_factory = None
3754
4046
        if not exclude:
3755
4047
            exclude_pattern = None
3756
4048
        else:
3757
4049
            exclude_pattern = '(' + '|'.join(exclude) + ')'
 
4050
        if not sync:
 
4051
            self._disable_fsync()
3758
4052
        selftest_kwargs = {"verbose": verbose,
3759
4053
                          "pattern": pattern,
3760
4054
                          "stop_on_failure": one,
3782
4076
            cleanup()
3783
4077
        return int(not result)
3784
4078
 
 
4079
    def _disable_fsync(self):
 
4080
        """Change the 'os' functionality to not synchronize."""
 
4081
        self._orig_fsync = getattr(os, 'fsync', None)
 
4082
        if self._orig_fsync is not None:
 
4083
            os.fsync = lambda filedes: None
 
4084
        self._orig_fdatasync = getattr(os, 'fdatasync', None)
 
4085
        if self._orig_fdatasync is not None:
 
4086
            os.fdatasync = lambda filedes: None
 
4087
 
3785
4088
 
3786
4089
class cmd_version(Command):
3787
4090
    __doc__ = """Show version of bzr."""
3807
4110
 
3808
4111
    @display_command
3809
4112
    def run(self):
3810
 
        self.outf.write("It sure does!\n")
 
4113
        self.outf.write(gettext("It sure does!\n"))
3811
4114
 
3812
4115
 
3813
4116
class cmd_find_merge_base(Command):
3831
4134
        graph = branch1.repository.get_graph(branch2.repository)
3832
4135
        base_rev_id = graph.find_unique_lca(last1, last2)
3833
4136
 
3834
 
        self.outf.write('merge base is revision %s\n' % base_rev_id)
 
4137
        self.outf.write(gettext('merge base is revision %s\n') % base_rev_id)
3835
4138
 
3836
4139
 
3837
4140
class cmd_merge(Command):
3870
4173
    Use bzr resolve when you have fixed a problem.  See also bzr conflicts.
3871
4174
 
3872
4175
    If there is no default branch set, the first merge will set it (use
3873
 
    --no-remember to avoid settting it). After that, you can omit the branch
 
4176
    --no-remember to avoid setting it). After that, you can omit the branch
3874
4177
    to use the default.  To change the default, use --remember. The value will
3875
4178
    only be saved if the remote location can be accessed.
3876
4179
 
3962
4265
 
3963
4266
        tree = WorkingTree.open_containing(directory)[0]
3964
4267
        if tree.branch.revno() == 0:
3965
 
            raise errors.BzrCommandError('Merging into empty branches not currently supported, '
3966
 
                                         'https://bugs.launchpad.net/bzr/+bug/308562')
 
4268
            raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
 
4269
                                         'https://bugs.launchpad.net/bzr/+bug/308562'))
3967
4270
 
3968
4271
        try:
3969
4272
            basis_tree = tree.revision_tree(tree.last_revision())
3989
4292
                mergeable = None
3990
4293
            else:
3991
4294
                if uncommitted:
3992
 
                    raise errors.BzrCommandError('Cannot use --uncommitted'
3993
 
                        ' with bundles or merge directives.')
 
4295
                    raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
 
4296
                        ' with bundles or merge directives.'))
3994
4297
 
3995
4298
                if revision is not None:
3996
 
                    raise errors.BzrCommandError(
3997
 
                        'Cannot use -r with merge directives or bundles')
 
4299
                    raise errors.BzrCommandError(gettext(
 
4300
                        'Cannot use -r with merge directives or bundles'))
3998
4301
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
3999
4302
                   mergeable, None)
4000
4303
 
4001
4304
        if merger is None and uncommitted:
4002
4305
            if revision is not None and len(revision) > 0:
4003
 
                raise errors.BzrCommandError('Cannot use --uncommitted and'
4004
 
                    ' --revision at the same time.')
 
4306
                raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
 
4307
                    ' --revision at the same time.'))
4005
4308
            merger = self.get_merger_from_uncommitted(tree, location, None)
4006
4309
            allow_pending = False
4007
4310
 
4020
4323
            if merger.interesting_files:
4021
4324
                if not merger.other_tree.has_filename(
4022
4325
                    merger.interesting_files[0]):
4023
 
                    note("merger: " + str(merger))
 
4326
                    note(gettext("merger: ") + str(merger))
4024
4327
                    raise errors.PathsDoNotExist([location])
4025
 
            note('Nothing to do.')
 
4328
            note(gettext('Nothing to do.'))
4026
4329
            return 0
4027
4330
        if pull and not preview:
4028
4331
            if merger.interesting_files is not None:
4029
 
                raise errors.BzrCommandError('Cannot pull individual files')
 
4332
                raise errors.BzrCommandError(gettext('Cannot pull individual files'))
4030
4333
            if (merger.base_rev_id == tree.last_revision()):
4031
4334
                result = tree.pull(merger.other_branch, False,
4032
4335
                                   merger.other_rev_id)
4033
4336
                result.report(self.outf)
4034
4337
                return 0
4035
4338
        if merger.this_basis is None:
4036
 
            raise errors.BzrCommandError(
 
4339
            raise errors.BzrCommandError(gettext(
4037
4340
                "This branch has no commits."
4038
 
                " (perhaps you would prefer 'bzr pull')")
 
4341
                " (perhaps you would prefer 'bzr pull')"))
4039
4342
        if preview:
4040
4343
            return self._do_preview(merger)
4041
4344
        elif interactive:
4092
4395
    def sanity_check_merger(self, merger):
4093
4396
        if (merger.show_base and
4094
4397
            not merger.merge_type is _mod_merge.Merge3Merger):
4095
 
            raise errors.BzrCommandError("Show-base is not supported for this"
4096
 
                                         " merge type. %s" % merger.merge_type)
 
4398
            raise errors.BzrCommandError(gettext("Show-base is not supported for this"
 
4399
                                         " merge type. %s") % merger.merge_type)
4097
4400
        if merger.reprocess is None:
4098
4401
            if merger.show_base:
4099
4402
                merger.reprocess = False
4101
4404
                # Use reprocess if the merger supports it
4102
4405
                merger.reprocess = merger.merge_type.supports_reprocess
4103
4406
        if merger.reprocess and not merger.merge_type.supports_reprocess:
4104
 
            raise errors.BzrCommandError("Conflict reduction is not supported"
4105
 
                                         " for merge type %s." %
 
4407
            raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
 
4408
                                         " for merge type %s.") %
4106
4409
                                         merger.merge_type)
4107
4410
        if merger.reprocess and merger.show_base:
4108
 
            raise errors.BzrCommandError("Cannot do conflict reduction and"
4109
 
                                         " show base.")
 
4411
            raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
 
4412
                                         " show base."))
4110
4413
 
4111
4414
    def _get_merger_from_branch(self, tree, location, revision, remember,
4112
4415
                                possible_transports, pb):
4216
4519
            stored_location_type = "parent"
4217
4520
        mutter("%s", stored_location)
4218
4521
        if stored_location is None:
4219
 
            raise errors.BzrCommandError("No location specified or remembered")
 
4522
            raise errors.BzrCommandError(gettext("No location specified or remembered"))
4220
4523
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4221
 
        note(u"%s remembered %s location %s", verb_string,
4222
 
                stored_location_type, display_url)
 
4524
        note(gettext("{0} remembered {1} location {2}").format(verb_string,
 
4525
                stored_location_type, display_url))
4223
4526
        return stored_location
4224
4527
 
4225
4528
 
4262
4565
        self.add_cleanup(tree.lock_write().unlock)
4263
4566
        parents = tree.get_parent_ids()
4264
4567
        if len(parents) != 2:
4265
 
            raise errors.BzrCommandError("Sorry, remerge only works after normal"
 
4568
            raise errors.BzrCommandError(gettext("Sorry, remerge only works after normal"
4266
4569
                                         " merges.  Not cherrypicking or"
4267
 
                                         " multi-merges.")
 
4570
                                         " multi-merges."))
4268
4571
        repository = tree.branch.repository
4269
4572
        interesting_ids = None
4270
4573
        new_conflicts = []
4429
4732
 
4430
4733
    @display_command
4431
4734
    def run(self, context=None):
4432
 
        import shellcomplete
 
4735
        from bzrlib import shellcomplete
4433
4736
        shellcomplete.shellcomplete(context)
4434
4737
 
4435
4738
 
4489
4792
            type=_parse_revision_str,
4490
4793
            help='Filter on local branch revisions (inclusive). '
4491
4794
                'See "help revisionspec" for details.'),
4492
 
        Option('include-merges',
 
4795
        Option('include-merged',
4493
4796
               'Show all revisions in addition to the mainline ones.'),
 
4797
        Option('include-merges', hidden=True,
 
4798
               help='Historical alias for --include-merged.'),
4494
4799
        ]
4495
4800
    encoding_type = 'replace'
4496
4801
 
4499
4804
            theirs_only=False,
4500
4805
            log_format=None, long=False, short=False, line=False,
4501
4806
            show_ids=False, verbose=False, this=False, other=False,
4502
 
            include_merges=False, revision=None, my_revision=None,
4503
 
            directory=u'.'):
 
4807
            include_merged=None, revision=None, my_revision=None,
 
4808
            directory=u'.',
 
4809
            include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4504
4810
        from bzrlib.missing import find_unmerged, iter_log_revisions
4505
4811
        def message(s):
4506
4812
            if not is_quiet():
4507
4813
                self.outf.write(s)
4508
4814
 
 
4815
        if symbol_versioning.deprecated_passed(include_merges):
 
4816
            ui.ui_factory.show_user_warning(
 
4817
                'deprecated_command_option',
 
4818
                deprecated_name='--include-merges',
 
4819
                recommended_name='--include-merged',
 
4820
                deprecated_in_version='2.5',
 
4821
                command=self.invoked_as)
 
4822
            if include_merged is None:
 
4823
                include_merged = include_merges
 
4824
            else:
 
4825
                raise errors.BzrCommandError(gettext(
 
4826
                    '{0} and {1} are mutually exclusive').format(
 
4827
                    '--include-merges', '--include-merged'))
 
4828
        if include_merged is None:
 
4829
            include_merged = False
4509
4830
        if this:
4510
4831
            mine_only = this
4511
4832
        if other:
4526
4847
        if other_branch is None:
4527
4848
            other_branch = parent
4528
4849
            if other_branch is None:
4529
 
                raise errors.BzrCommandError("No peer location known"
4530
 
                                             " or specified.")
 
4850
                raise errors.BzrCommandError(gettext("No peer location known"
 
4851
                                             " or specified."))
4531
4852
            display_url = urlutils.unescape_for_display(parent,
4532
4853
                                                        self.outf.encoding)
4533
 
            message("Using saved parent location: "
4534
 
                    + display_url + "\n")
 
4854
            message(gettext("Using saved parent location: {0}\n").format(
 
4855
                    display_url))
4535
4856
 
4536
4857
        remote_branch = Branch.open(other_branch)
4537
4858
        if remote_branch.base == local_branch.base:
4550
4871
        local_extra, remote_extra = find_unmerged(
4551
4872
            local_branch, remote_branch, restrict,
4552
4873
            backward=not reverse,
4553
 
            include_merges=include_merges,
 
4874
            include_merged=include_merged,
4554
4875
            local_revid_range=local_revid_range,
4555
4876
            remote_revid_range=remote_revid_range)
4556
4877
 
4563
4884
 
4564
4885
        status_code = 0
4565
4886
        if local_extra and not theirs_only:
4566
 
            message("You have %d extra revision(s):\n" %
 
4887
            message(ngettext("You have %d extra revision:\n",
 
4888
                             "You have %d extra revisions:\n", 
 
4889
                             len(local_extra)) %
4567
4890
                len(local_extra))
4568
4891
            for revision in iter_log_revisions(local_extra,
4569
4892
                                local_branch.repository,
4577
4900
        if remote_extra and not mine_only:
4578
4901
            if printed_local is True:
4579
4902
                message("\n\n\n")
4580
 
            message("You are missing %d revision(s):\n" %
 
4903
            message(ngettext("You are missing %d revision:\n",
 
4904
                             "You are missing %d revisions:\n",
 
4905
                             len(remote_extra)) %
4581
4906
                len(remote_extra))
4582
4907
            for revision in iter_log_revisions(remote_extra,
4583
4908
                                remote_branch.repository,
4587
4912
 
4588
4913
        if mine_only and not local_extra:
4589
4914
            # We checked local, and found nothing extra
4590
 
            message('This branch is up to date.\n')
 
4915
            message(gettext('This branch has no new revisions.\n'))
4591
4916
        elif theirs_only and not remote_extra:
4592
4917
            # We checked remote, and found nothing extra
4593
 
            message('Other branch is up to date.\n')
 
4918
            message(gettext('Other branch has no new revisions.\n'))
4594
4919
        elif not (mine_only or theirs_only or local_extra or
4595
4920
                  remote_extra):
4596
4921
            # We checked both branches, and neither one had extra
4597
4922
            # revisions
4598
 
            message("Branches are up to date.\n")
 
4923
            message(gettext("Branches are up to date.\n"))
4599
4924
        self.cleanup_now()
4600
4925
        if not status_code and parent is None and other_branch is not None:
4601
4926
            self.add_cleanup(local_branch.lock_write().unlock)
4631
4956
        ]
4632
4957
 
4633
4958
    def run(self, branch_or_repo='.', clean_obsolete_packs=False):
4634
 
        dir = bzrdir.BzrDir.open_containing(branch_or_repo)[0]
 
4959
        dir = controldir.ControlDir.open_containing(branch_or_repo)[0]
4635
4960
        try:
4636
4961
            branch = dir.open_branch()
4637
4962
            repository = branch.repository
4762
5087
 
4763
5088
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
4764
5089
        if revision_id_list is not None and revision is not None:
4765
 
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
 
5090
            raise errors.BzrCommandError(gettext('You can only supply one of revision_id or --revision'))
4766
5091
        if revision_id_list is None and revision is None:
4767
 
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
 
5092
            raise errors.BzrCommandError(gettext('You must supply either --revision or a revision_id'))
4768
5093
        b = WorkingTree.open_containing(directory)[0].branch
4769
5094
        self.add_cleanup(b.lock_write().unlock)
4770
5095
        return self._run(b, revision_id_list, revision)
4771
5096
 
4772
5097
    def _run(self, b, revision_id_list, revision):
4773
5098
        import bzrlib.gpg as gpg
4774
 
        gpg_strategy = gpg.GPGStrategy(b.get_config())
 
5099
        gpg_strategy = gpg.GPGStrategy(b.get_config_stack())
4775
5100
        if revision_id_list is not None:
4776
5101
            b.repository.start_write_group()
4777
5102
            try:
4802
5127
                if to_revid is None:
4803
5128
                    to_revno = b.revno()
4804
5129
                if from_revno is None or to_revno is None:
4805
 
                    raise errors.BzrCommandError('Cannot sign a range of non-revision-history revisions')
 
5130
                    raise errors.BzrCommandError(gettext('Cannot sign a range of non-revision-history revisions'))
4806
5131
                b.repository.start_write_group()
4807
5132
                try:
4808
5133
                    for revno in range(from_revno, to_revno + 1):
4814
5139
                else:
4815
5140
                    b.repository.commit_write_group()
4816
5141
            else:
4817
 
                raise errors.BzrCommandError('Please supply either one revision, or a range.')
 
5142
                raise errors.BzrCommandError(gettext('Please supply either one revision, or a range.'))
4818
5143
 
4819
5144
 
4820
5145
class cmd_bind(Command):
4839
5164
            try:
4840
5165
                location = b.get_old_bound_location()
4841
5166
            except errors.UpgradeRequired:
4842
 
                raise errors.BzrCommandError('No location supplied.  '
4843
 
                    'This format does not remember old locations.')
 
5167
                raise errors.BzrCommandError(gettext('No location supplied.  '
 
5168
                    'This format does not remember old locations.'))
4844
5169
            else:
4845
5170
                if location is None:
4846
5171
                    if b.get_bound_location() is not None:
4847
 
                        raise errors.BzrCommandError('Branch is already bound')
 
5172
                        raise errors.BzrCommandError(gettext('Branch is already bound'))
4848
5173
                    else:
4849
 
                        raise errors.BzrCommandError('No location supplied '
4850
 
                            'and no previous location known')
 
5174
                        raise errors.BzrCommandError(gettext('No location supplied '
 
5175
                            'and no previous location known'))
4851
5176
        b_other = Branch.open(location)
4852
5177
        try:
4853
5178
            b.bind(b_other)
4854
5179
        except errors.DivergedBranches:
4855
 
            raise errors.BzrCommandError('These branches have diverged.'
4856
 
                                         ' Try merging, and then bind again.')
 
5180
            raise errors.BzrCommandError(gettext('These branches have diverged.'
 
5181
                                         ' Try merging, and then bind again.'))
4857
5182
        if b.get_config().has_explicit_nickname():
4858
5183
            b.nick = b_other.nick
4859
5184
 
4872
5197
    def run(self, directory=u'.'):
4873
5198
        b, relpath = Branch.open_containing(directory)
4874
5199
        if not b.unbind():
4875
 
            raise errors.BzrCommandError('Local branch is not bound')
 
5200
            raise errors.BzrCommandError(gettext('Local branch is not bound'))
4876
5201
 
4877
5202
 
4878
5203
class cmd_uncommit(Command):
4899
5224
    takes_options = ['verbose', 'revision',
4900
5225
                    Option('dry-run', help='Don\'t actually make changes.'),
4901
5226
                    Option('force', help='Say yes to all questions.'),
 
5227
                    Option('keep-tags',
 
5228
                           help='Keep tags that point to removed revisions.'),
4902
5229
                    Option('local',
4903
5230
                           help="Only remove the commits from the local branch"
4904
5231
                                " when in a checkout."
4908
5235
    aliases = []
4909
5236
    encoding_type = 'replace'
4910
5237
 
4911
 
    def run(self, location=None,
4912
 
            dry_run=False, verbose=False,
4913
 
            revision=None, force=False, local=False):
 
5238
    def run(self, location=None, dry_run=False, verbose=False,
 
5239
            revision=None, force=False, local=False, keep_tags=False):
4914
5240
        if location is None:
4915
5241
            location = u'.'
4916
 
        control, relpath = bzrdir.BzrDir.open_containing(location)
 
5242
        control, relpath = controldir.ControlDir.open_containing(location)
4917
5243
        try:
4918
5244
            tree = control.open_workingtree()
4919
5245
            b = tree.branch
4925
5251
            self.add_cleanup(tree.lock_write().unlock)
4926
5252
        else:
4927
5253
            self.add_cleanup(b.lock_write().unlock)
4928
 
        return self._run(b, tree, dry_run, verbose, revision, force, local=local)
 
5254
        return self._run(b, tree, dry_run, verbose, revision, force,
 
5255
                         local, keep_tags)
4929
5256
 
4930
 
    def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
 
5257
    def _run(self, b, tree, dry_run, verbose, revision, force, local,
 
5258
             keep_tags):
4931
5259
        from bzrlib.log import log_formatter, show_log
4932
5260
        from bzrlib.uncommit import uncommit
4933
5261
 
4948
5276
                rev_id = b.get_rev_id(revno)
4949
5277
 
4950
5278
        if rev_id is None or _mod_revision.is_null(rev_id):
4951
 
            self.outf.write('No revisions to uncommit.\n')
 
5279
            self.outf.write(gettext('No revisions to uncommit.\n'))
4952
5280
            return 1
4953
5281
 
4954
5282
        lf = log_formatter('short',
4963
5291
                 end_revision=last_revno)
4964
5292
 
4965
5293
        if dry_run:
4966
 
            self.outf.write('Dry-run, pretending to remove'
4967
 
                            ' the above revisions.\n')
 
5294
            self.outf.write(gettext('Dry-run, pretending to remove'
 
5295
                            ' the above revisions.\n'))
4968
5296
        else:
4969
 
            self.outf.write('The above revision(s) will be removed.\n')
 
5297
            self.outf.write(gettext('The above revision(s) will be removed.\n'))
4970
5298
 
4971
5299
        if not force:
4972
5300
            if not ui.ui_factory.confirm_action(
4973
 
                    u'Uncommit these revisions',
 
5301
                    gettext(u'Uncommit these revisions'),
4974
5302
                    'bzrlib.builtins.uncommit',
4975
5303
                    {}):
4976
 
                self.outf.write('Canceled\n')
 
5304
                self.outf.write(gettext('Canceled\n'))
4977
5305
                return 0
4978
5306
 
4979
5307
        mutter('Uncommitting from {%s} to {%s}',
4980
5308
               last_rev_id, rev_id)
4981
5309
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
4982
 
                 revno=revno, local=local)
4983
 
        self.outf.write('You can restore the old tip by running:\n'
4984
 
             '  bzr pull . -r revid:%s\n' % last_rev_id)
 
5310
                 revno=revno, local=local, keep_tags=keep_tags)
 
5311
        self.outf.write(gettext('You can restore the old tip by running:\n'
 
5312
             '  bzr pull . -r revid:%s\n') % last_rev_id)
4985
5313
 
4986
5314
 
4987
5315
class cmd_break_lock(Command):
5021
5349
            conf = _mod_config.LockableConfig(file_name=location)
5022
5350
            conf.break_lock()
5023
5351
        else:
5024
 
            control, relpath = bzrdir.BzrDir.open_containing(location)
 
5352
            control, relpath = controldir.ControlDir.open_containing(location)
5025
5353
            try:
5026
5354
                control.break_lock()
5027
5355
            except NotImplementedError:
5071
5399
                    'option leads to global uncontrolled write access to your '
5072
5400
                    'file system.'
5073
5401
                ),
 
5402
        Option('client-timeout', type=float,
 
5403
               help='Override the default idle client timeout (5min).'),
5074
5404
        ]
5075
5405
 
5076
5406
    def get_host_and_port(self, port):
5093
5423
        return host, port
5094
5424
 
5095
5425
    def run(self, port=None, inet=False, directory=None, allow_writes=False,
5096
 
            protocol=None):
 
5426
            protocol=None, client_timeout=None):
5097
5427
        from bzrlib import transport
5098
5428
        if directory is None:
5099
5429
            directory = os.getcwd()
5100
5430
        if protocol is None:
5101
5431
            protocol = transport.transport_server_registry.get()
5102
5432
        host, port = self.get_host_and_port(port)
5103
 
        url = urlutils.local_path_to_url(directory)
 
5433
        url = transport.location_to_url(directory)
5104
5434
        if not allow_writes:
5105
5435
            url = 'readonly+' + url
5106
 
        t = transport.get_transport(url)
5107
 
        protocol(t, host, port, inet)
 
5436
        t = transport.get_transport_from_url(url)
 
5437
        try:
 
5438
            protocol(t, host, port, inet, client_timeout)
 
5439
        except TypeError, e:
 
5440
            # We use symbol_versioning.deprecated_in just so that people
 
5441
            # grepping can find it here.
 
5442
            # symbol_versioning.deprecated_in((2, 5, 0))
 
5443
            symbol_versioning.warn(
 
5444
                'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
 
5445
                'Most likely it needs to be updated to support a'
 
5446
                ' "timeout" parameter (added in bzr 2.5.0)'
 
5447
                % (e, protocol.__module__, protocol),
 
5448
                DeprecationWarning)
 
5449
            protocol(t, host, port, inet)
5108
5450
 
5109
5451
 
5110
5452
class cmd_join(Command):
5133
5475
        containing_tree = WorkingTree.open_containing(parent_dir)[0]
5134
5476
        repo = containing_tree.branch.repository
5135
5477
        if not repo.supports_rich_root():
5136
 
            raise errors.BzrCommandError(
 
5478
            raise errors.BzrCommandError(gettext(
5137
5479
                "Can't join trees because %s doesn't support rich root data.\n"
5138
 
                "You can use bzr upgrade on the repository."
 
5480
                "You can use bzr upgrade on the repository.")
5139
5481
                % (repo,))
5140
5482
        if reference:
5141
5483
            try:
5143
5485
            except errors.BadReferenceTarget, e:
5144
5486
                # XXX: Would be better to just raise a nicely printable
5145
5487
                # exception from the real origin.  Also below.  mbp 20070306
5146
 
                raise errors.BzrCommandError("Cannot join %s.  %s" %
5147
 
                                             (tree, e.reason))
 
5488
                raise errors.BzrCommandError(
 
5489
                       gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5148
5490
        else:
5149
5491
            try:
5150
5492
                containing_tree.subsume(sub_tree)
5151
5493
            except errors.BadSubsumeSource, e:
5152
 
                raise errors.BzrCommandError("Cannot join %s.  %s" %
5153
 
                                             (tree, e.reason))
 
5494
                raise errors.BzrCommandError(
 
5495
                       gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5154
5496
 
5155
5497
 
5156
5498
class cmd_split(Command):
5240
5582
        if submit_branch is None:
5241
5583
            submit_branch = branch.get_parent()
5242
5584
        if submit_branch is None:
5243
 
            raise errors.BzrCommandError('No submit branch specified or known')
 
5585
            raise errors.BzrCommandError(gettext('No submit branch specified or known'))
5244
5586
 
5245
5587
        stored_public_branch = branch.get_public_branch()
5246
5588
        if public_branch is None:
5248
5590
        elif stored_public_branch is None:
5249
5591
            branch.set_public_branch(public_branch)
5250
5592
        if not include_bundle and public_branch is None:
5251
 
            raise errors.BzrCommandError('No public branch specified or'
5252
 
                                         ' known')
 
5593
            raise errors.BzrCommandError(gettext('No public branch specified or'
 
5594
                                         ' known'))
5253
5595
        base_revision_id = None
5254
5596
        if revision is not None:
5255
5597
            if len(revision) > 2:
5256
 
                raise errors.BzrCommandError('bzr merge-directive takes '
5257
 
                    'at most two one revision identifiers')
 
5598
                raise errors.BzrCommandError(gettext('bzr merge-directive takes '
 
5599
                    'at most two one revision identifiers'))
5258
5600
            revision_id = revision[-1].as_revision_id(branch)
5259
5601
            if len(revision) == 2:
5260
5602
                base_revision_id = revision[0].as_revision_id(branch)
5262
5604
            revision_id = branch.last_revision()
5263
5605
        revision_id = ensure_null(revision_id)
5264
5606
        if revision_id == NULL_REVISION:
5265
 
            raise errors.BzrCommandError('No revisions to bundle.')
 
5607
            raise errors.BzrCommandError(gettext('No revisions to bundle.'))
5266
5608
        directive = merge_directive.MergeDirective2.from_objects(
5267
5609
            branch.repository, revision_id, time.time(),
5268
5610
            osutils.local_time_offset(), submit_branch,
5276
5618
                self.outf.writelines(directive.to_lines())
5277
5619
        else:
5278
5620
            message = directive.to_email(mail_to, branch, sign)
5279
 
            s = SMTPConnection(branch.get_config())
 
5621
            s = SMTPConnection(branch.get_config_stack())
5280
5622
            s.send_email(message)
5281
5623
 
5282
5624
 
5314
5656
 
5315
5657
    Both the submit branch and the public branch follow the usual behavior with
5316
5658
    respect to --remember: If there is no default location set, the first send
5317
 
    will set it (use --no-remember to avoid settting it). After that, you can
 
5659
    will set it (use --no-remember to avoid setting it). After that, you can
5318
5660
    omit the location to use the default.  To change the default, use
5319
5661
    --remember. The value will only be saved if the location can be accessed.
5320
5662
 
5522
5864
        self.add_cleanup(branch.lock_write().unlock)
5523
5865
        if delete:
5524
5866
            if tag_name is None:
5525
 
                raise errors.BzrCommandError("No tag specified to delete.")
 
5867
                raise errors.BzrCommandError(gettext("No tag specified to delete."))
5526
5868
            branch.tags.delete_tag(tag_name)
5527
 
            note('Deleted tag %s.' % tag_name)
 
5869
            note(gettext('Deleted tag %s.') % tag_name)
5528
5870
        else:
5529
5871
            if revision:
5530
5872
                if len(revision) != 1:
5531
 
                    raise errors.BzrCommandError(
 
5873
                    raise errors.BzrCommandError(gettext(
5532
5874
                        "Tags can only be placed on a single revision, "
5533
 
                        "not on a range")
 
5875
                        "not on a range"))
5534
5876
                revision_id = revision[0].as_revision_id(branch)
5535
5877
            else:
5536
5878
                revision_id = branch.last_revision()
5537
5879
            if tag_name is None:
5538
5880
                tag_name = branch.automatic_tag_name(revision_id)
5539
5881
                if tag_name is None:
5540
 
                    raise errors.BzrCommandError(
5541
 
                        "Please specify a tag name.")
5542
 
            if (not force) and branch.tags.has_tag(tag_name):
 
5882
                    raise errors.BzrCommandError(gettext(
 
5883
                        "Please specify a tag name."))
 
5884
            try:
 
5885
                existing_target = branch.tags.lookup_tag(tag_name)
 
5886
            except errors.NoSuchTag:
 
5887
                existing_target = None
 
5888
            if not force and existing_target not in (None, revision_id):
5543
5889
                raise errors.TagAlreadyExists(tag_name)
5544
 
            branch.tags.set_tag(tag_name, revision_id)
5545
 
            note('Created tag %s.' % tag_name)
 
5890
            if existing_target == revision_id:
 
5891
                note(gettext('Tag %s already exists for that revision.') % tag_name)
 
5892
            else:
 
5893
                branch.tags.set_tag(tag_name, revision_id)
 
5894
                if existing_target is None:
 
5895
                    note(gettext('Created tag %s.') % tag_name)
 
5896
                else:
 
5897
                    note(gettext('Updated tag %s.') % tag_name)
5546
5898
 
5547
5899
 
5548
5900
class cmd_tags(Command):
5574
5926
 
5575
5927
        self.add_cleanup(branch.lock_read().unlock)
5576
5928
        if revision:
5577
 
            graph = branch.repository.get_graph()
5578
 
            rev1, rev2 = _get_revision_range(revision, branch, self.name())
5579
 
            revid1, revid2 = rev1.rev_id, rev2.rev_id
5580
 
            # only show revisions between revid1 and revid2 (inclusive)
5581
 
            tags = [(tag, revid) for tag, revid in tags if
5582
 
                graph.is_between(revid, revid1, revid2)]
 
5929
            # Restrict to the specified range
 
5930
            tags = self._tags_for_range(branch, revision)
5583
5931
        if sort is None:
5584
5932
            sort = tag_sort_methods.get()
5585
5933
        sort(branch, tags)
5590
5938
                    revno = branch.revision_id_to_dotted_revno(revid)
5591
5939
                    if isinstance(revno, tuple):
5592
5940
                        revno = '.'.join(map(str, revno))
5593
 
                except (errors.NoSuchRevision, errors.GhostRevisionsHaveNoRevno):
 
5941
                except (errors.NoSuchRevision,
 
5942
                        errors.GhostRevisionsHaveNoRevno,
 
5943
                        errors.UnsupportedOperation):
5594
5944
                    # Bad tag data/merges can lead to tagged revisions
5595
5945
                    # which are not in this branch. Fail gracefully ...
5596
5946
                    revno = '?'
5599
5949
        for tag, revspec in tags:
5600
5950
            self.outf.write('%-20s %s\n' % (tag, revspec))
5601
5951
 
 
5952
    def _tags_for_range(self, branch, revision):
 
5953
        range_valid = True
 
5954
        rev1, rev2 = _get_revision_range(revision, branch, self.name())
 
5955
        revid1, revid2 = rev1.rev_id, rev2.rev_id
 
5956
        # _get_revision_range will always set revid2 if it's not specified.
 
5957
        # If revid1 is None, it means we want to start from the branch
 
5958
        # origin which is always a valid ancestor. If revid1 == revid2, the
 
5959
        # ancestry check is useless.
 
5960
        if revid1 and revid1 != revid2:
 
5961
            # FIXME: We really want to use the same graph than
 
5962
            # branch.iter_merge_sorted_revisions below, but this is not
 
5963
            # easily available -- vila 2011-09-23
 
5964
            if branch.repository.get_graph().is_ancestor(revid2, revid1):
 
5965
                # We don't want to output anything in this case...
 
5966
                return []
 
5967
        # only show revisions between revid1 and revid2 (inclusive)
 
5968
        tagged_revids = branch.tags.get_reverse_tag_dict()
 
5969
        found = []
 
5970
        for r in branch.iter_merge_sorted_revisions(
 
5971
            start_revision_id=revid2, stop_revision_id=revid1,
 
5972
            stop_rule='include'):
 
5973
            revid_tags = tagged_revids.get(r[0], None)
 
5974
            if revid_tags:
 
5975
                found.extend([(tag, r[0]) for tag in revid_tags])
 
5976
        return found
 
5977
 
5602
5978
 
5603
5979
class cmd_reconfigure(Command):
5604
5980
    __doc__ = """Reconfigure the type of a bzr directory.
5618
5994
    takes_args = ['location?']
5619
5995
    takes_options = [
5620
5996
        RegistryOption.from_kwargs(
5621
 
            'target_type',
5622
 
            title='Target type',
5623
 
            help='The type to reconfigure the directory to.',
 
5997
            'tree_type',
 
5998
            title='Tree type',
 
5999
            help='The relation between branch and tree.',
5624
6000
            value_switches=True, enum_switch=False,
5625
6001
            branch='Reconfigure to be an unbound branch with no working tree.',
5626
6002
            tree='Reconfigure to be an unbound branch with a working tree.',
5627
6003
            checkout='Reconfigure to be a bound branch with a working tree.',
5628
6004
            lightweight_checkout='Reconfigure to be a lightweight'
5629
6005
                ' checkout (with no local history).',
 
6006
            ),
 
6007
        RegistryOption.from_kwargs(
 
6008
            'repository_type',
 
6009
            title='Repository type',
 
6010
            help='Location fo the repository.',
 
6011
            value_switches=True, enum_switch=False,
5630
6012
            standalone='Reconfigure to be a standalone branch '
5631
6013
                '(i.e. stop using shared repository).',
5632
6014
            use_shared='Reconfigure to use a shared repository.',
 
6015
            ),
 
6016
        RegistryOption.from_kwargs(
 
6017
            'repository_trees',
 
6018
            title='Trees in Repository',
 
6019
            help='Whether new branches in the repository have trees.',
 
6020
            value_switches=True, enum_switch=False,
5633
6021
            with_trees='Reconfigure repository to create '
5634
6022
                'working trees on branches by default.',
5635
6023
            with_no_trees='Reconfigure repository to not create '
5649
6037
            ),
5650
6038
        ]
5651
6039
 
5652
 
    def run(self, location=None, target_type=None, bind_to=None, force=False,
5653
 
            stacked_on=None,
5654
 
            unstacked=None):
5655
 
        directory = bzrdir.BzrDir.open(location)
 
6040
    def run(self, location=None, bind_to=None, force=False,
 
6041
            tree_type=None, repository_type=None, repository_trees=None,
 
6042
            stacked_on=None, unstacked=None):
 
6043
        directory = controldir.ControlDir.open(location)
5656
6044
        if stacked_on and unstacked:
5657
 
            raise errors.BzrCommandError("Can't use both --stacked-on and --unstacked")
 
6045
            raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5658
6046
        elif stacked_on is not None:
5659
6047
            reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5660
6048
        elif unstacked:
5662
6050
        # At the moment you can use --stacked-on and a different
5663
6051
        # reconfiguration shape at the same time; there seems no good reason
5664
6052
        # to ban it.
5665
 
        if target_type is None:
 
6053
        if (tree_type is None and
 
6054
            repository_type is None and
 
6055
            repository_trees is None):
5666
6056
            if stacked_on or unstacked:
5667
6057
                return
5668
6058
            else:
5669
 
                raise errors.BzrCommandError('No target configuration '
5670
 
                    'specified')
5671
 
        elif target_type == 'branch':
 
6059
                raise errors.BzrCommandError(gettext('No target configuration '
 
6060
                    'specified'))
 
6061
        reconfiguration = None
 
6062
        if tree_type == 'branch':
5672
6063
            reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5673
 
        elif target_type == 'tree':
 
6064
        elif tree_type == 'tree':
5674
6065
            reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5675
 
        elif target_type == 'checkout':
 
6066
        elif tree_type == 'checkout':
5676
6067
            reconfiguration = reconfigure.Reconfigure.to_checkout(
5677
6068
                directory, bind_to)
5678
 
        elif target_type == 'lightweight-checkout':
 
6069
        elif tree_type == 'lightweight-checkout':
5679
6070
            reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5680
6071
                directory, bind_to)
5681
 
        elif target_type == 'use-shared':
 
6072
        if reconfiguration:
 
6073
            reconfiguration.apply(force)
 
6074
            reconfiguration = None
 
6075
        if repository_type == 'use-shared':
5682
6076
            reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5683
 
        elif target_type == 'standalone':
 
6077
        elif repository_type == 'standalone':
5684
6078
            reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5685
 
        elif target_type == 'with-trees':
 
6079
        if reconfiguration:
 
6080
            reconfiguration.apply(force)
 
6081
            reconfiguration = None
 
6082
        if repository_trees == 'with-trees':
5686
6083
            reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5687
6084
                directory, True)
5688
 
        elif target_type == 'with-no-trees':
 
6085
        elif repository_trees == 'with-no-trees':
5689
6086
            reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5690
6087
                directory, False)
5691
 
        reconfiguration.apply(force)
 
6088
        if reconfiguration:
 
6089
            reconfiguration.apply(force)
 
6090
            reconfiguration = None
5692
6091
 
5693
6092
 
5694
6093
class cmd_switch(Command):
5729
6128
        from bzrlib import switch
5730
6129
        tree_location = directory
5731
6130
        revision = _get_one_revision('switch', revision)
5732
 
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
 
6131
        control_dir = controldir.ControlDir.open_containing(tree_location)[0]
5733
6132
        if to_location is None:
5734
6133
            if revision is None:
5735
 
                raise errors.BzrCommandError('You must supply either a'
5736
 
                                             ' revision or a location')
 
6134
                raise errors.BzrCommandError(gettext('You must supply either a'
 
6135
                                             ' revision or a location'))
5737
6136
            to_location = tree_location
5738
6137
        try:
5739
6138
            branch = control_dir.open_branch()
5743
6142
            had_explicit_nick = False
5744
6143
        if create_branch:
5745
6144
            if branch is None:
5746
 
                raise errors.BzrCommandError('cannot create branch without'
5747
 
                                             ' source branch')
 
6145
                raise errors.BzrCommandError(gettext('cannot create branch without'
 
6146
                                             ' source branch'))
5748
6147
            to_location = directory_service.directories.dereference(
5749
6148
                              to_location)
5750
6149
            if '/' not in to_location and '\\' not in to_location:
5751
6150
                # This path is meant to be relative to the existing branch
5752
6151
                this_url = self._get_branch_location(control_dir)
5753
 
                to_location = urlutils.join(this_url, '..', to_location)
 
6152
                # Perhaps the target control dir supports colocated branches?
 
6153
                try:
 
6154
                    root = controldir.ControlDir.open(this_url,
 
6155
                        possible_transports=[control_dir.user_transport])
 
6156
                except errors.NotBranchError:
 
6157
                    colocated = False
 
6158
                else:
 
6159
                    colocated = root._format.colocated_branches
 
6160
                if colocated:
 
6161
                    to_location = urlutils.join_segment_parameters(this_url,
 
6162
                        {"branch": urlutils.escape(to_location)})
 
6163
                else:
 
6164
                    to_location = urlutils.join(
 
6165
                        this_url, '..', urlutils.escape(to_location))
5754
6166
            to_branch = branch.bzrdir.sprout(to_location,
5755
6167
                                 possible_transports=[branch.bzrdir.root_transport],
5756
6168
                                 source_branch=branch).open_branch()
5757
6169
        else:
 
6170
            # Perhaps it's a colocated branch?
5758
6171
            try:
5759
 
                to_branch = Branch.open(to_location)
5760
 
            except errors.NotBranchError:
5761
 
                this_url = self._get_branch_location(control_dir)
5762
 
                to_branch = Branch.open(
5763
 
                    urlutils.join(this_url, '..', to_location))
 
6172
                to_branch = control_dir.open_branch(to_location)
 
6173
            except (errors.NotBranchError, errors.NoColocatedBranchSupport):
 
6174
                try:
 
6175
                    to_branch = Branch.open(to_location)
 
6176
                except errors.NotBranchError:
 
6177
                    this_url = self._get_branch_location(control_dir)
 
6178
                    to_branch = Branch.open(
 
6179
                        urlutils.join(
 
6180
                            this_url, '..', urlutils.escape(to_location)))
5764
6181
        if revision is not None:
5765
6182
            revision = revision.as_revision_id(to_branch)
5766
6183
        switch.switch(control_dir, to_branch, force, revision_id=revision)
5767
6184
        if had_explicit_nick:
5768
6185
            branch = control_dir.open_branch() #get the new branch!
5769
6186
            branch.nick = to_branch.nick
5770
 
        note('Switched to branch: %s',
 
6187
        note(gettext('Switched to branch: %s'),
5771
6188
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5772
6189
 
5773
6190
    def _get_branch_location(self, control_dir):
5882
6299
            name = current_view
5883
6300
        if delete:
5884
6301
            if file_list:
5885
 
                raise errors.BzrCommandError(
5886
 
                    "Both --delete and a file list specified")
 
6302
                raise errors.BzrCommandError(gettext(
 
6303
                    "Both --delete and a file list specified"))
5887
6304
            elif switch:
5888
 
                raise errors.BzrCommandError(
5889
 
                    "Both --delete and --switch specified")
 
6305
                raise errors.BzrCommandError(gettext(
 
6306
                    "Both --delete and --switch specified"))
5890
6307
            elif all:
5891
6308
                tree.views.set_view_info(None, {})
5892
 
                self.outf.write("Deleted all views.\n")
 
6309
                self.outf.write(gettext("Deleted all views.\n"))
5893
6310
            elif name is None:
5894
 
                raise errors.BzrCommandError("No current view to delete")
 
6311
                raise errors.BzrCommandError(gettext("No current view to delete"))
5895
6312
            else:
5896
6313
                tree.views.delete_view(name)
5897
 
                self.outf.write("Deleted '%s' view.\n" % name)
 
6314
                self.outf.write(gettext("Deleted '%s' view.\n") % name)
5898
6315
        elif switch:
5899
6316
            if file_list:
5900
 
                raise errors.BzrCommandError(
5901
 
                    "Both --switch and a file list specified")
 
6317
                raise errors.BzrCommandError(gettext(
 
6318
                    "Both --switch and a file list specified"))
5902
6319
            elif all:
5903
 
                raise errors.BzrCommandError(
5904
 
                    "Both --switch and --all specified")
 
6320
                raise errors.BzrCommandError(gettext(
 
6321
                    "Both --switch and --all specified"))
5905
6322
            elif switch == 'off':
5906
6323
                if current_view is None:
5907
 
                    raise errors.BzrCommandError("No current view to disable")
 
6324
                    raise errors.BzrCommandError(gettext("No current view to disable"))
5908
6325
                tree.views.set_view_info(None, view_dict)
5909
 
                self.outf.write("Disabled '%s' view.\n" % (current_view))
 
6326
                self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
5910
6327
            else:
5911
6328
                tree.views.set_view_info(switch, view_dict)
5912
6329
                view_str = views.view_display_str(tree.views.lookup_view())
5913
 
                self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
 
6330
                self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
5914
6331
        elif all:
5915
6332
            if view_dict:
5916
 
                self.outf.write('Views defined:\n')
 
6333
                self.outf.write(gettext('Views defined:\n'))
5917
6334
                for view in sorted(view_dict):
5918
6335
                    if view == current_view:
5919
6336
                        active = "=>"
5922
6339
                    view_str = views.view_display_str(view_dict[view])
5923
6340
                    self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5924
6341
            else:
5925
 
                self.outf.write('No views defined.\n')
 
6342
                self.outf.write(gettext('No views defined.\n'))
5926
6343
        elif file_list:
5927
6344
            if name is None:
5928
6345
                # No name given and no current view set
5929
6346
                name = 'my'
5930
6347
            elif name == 'off':
5931
 
                raise errors.BzrCommandError(
5932
 
                    "Cannot change the 'off' pseudo view")
 
6348
                raise errors.BzrCommandError(gettext(
 
6349
                    "Cannot change the 'off' pseudo view"))
5933
6350
            tree.views.set_view(name, sorted(file_list))
5934
6351
            view_str = views.view_display_str(tree.views.lookup_view())
5935
 
            self.outf.write("Using '%s' view: %s\n" % (name, view_str))
 
6352
            self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
5936
6353
        else:
5937
6354
            # list the files
5938
6355
            if name is None:
5939
6356
                # No name given and no current view set
5940
 
                self.outf.write('No current view.\n')
 
6357
                self.outf.write(gettext('No current view.\n'))
5941
6358
            else:
5942
6359
                view_str = views.view_display_str(tree.views.lookup_view(name))
5943
 
                self.outf.write("'%s' view is: %s\n" % (name, view_str))
 
6360
                self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
5944
6361
 
5945
6362
 
5946
6363
class cmd_hooks(Command):
5960
6377
                        self.outf.write("    %s\n" %
5961
6378
                                        (some_hooks.get_hook_name(hook),))
5962
6379
                else:
5963
 
                    self.outf.write("    <no hooks installed>\n")
 
6380
                    self.outf.write(gettext("    <no hooks installed>\n"))
5964
6381
 
5965
6382
 
5966
6383
class cmd_remove_branch(Command):
6067
6484
        manager = tree.get_shelf_manager()
6068
6485
        shelves = manager.active_shelves()
6069
6486
        if len(shelves) == 0:
6070
 
            note('No shelved changes.')
 
6487
            note(gettext('No shelved changes.'))
6071
6488
            return 0
6072
6489
        for shelf_id in reversed(shelves):
6073
6490
            message = manager.get_metadata(shelf_id).get('message')
6162
6579
        if path is not None:
6163
6580
            branchdir = path
6164
6581
        tree, branch, relpath =(
6165
 
            bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
 
6582
            controldir.ControlDir.open_containing_tree_or_branch(branchdir))
6166
6583
        if path is not None:
6167
6584
            path = relpath
6168
6585
        if tree is None:
6196
6613
    __doc__ = """Export command helps and error messages in po format."""
6197
6614
 
6198
6615
    hidden = True
 
6616
    takes_options = [Option('plugin', 
 
6617
                            help='Export help text from named command '\
 
6618
                                 '(defaults to all built in commands).',
 
6619
                            type=str),
 
6620
                     Option('include-duplicates',
 
6621
                            help='Output multiple copies of the same msgid '
 
6622
                                 'string if it appears more than once.'),
 
6623
                            ]
6199
6624
 
6200
 
    def run(self):
 
6625
    def run(self, plugin=None, include_duplicates=False):
6201
6626
        from bzrlib.export_pot import export_pot
6202
 
        export_pot(self.outf)
 
6627
        export_pot(self.outf, plugin, include_duplicates)
6203
6628
 
6204
6629
 
6205
6630
def _register_lazy_builtins():
6212
6637
        ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6213
6638
        ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6214
6639
        ('cmd_conflicts', [], 'bzrlib.conflicts'),
6215
 
        ('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
 
6640
        ('cmd_sign_my_commits', [], 'bzrlib.commit_signature_commands'),
 
6641
        ('cmd_verify_signatures', [],
 
6642
                                        'bzrlib.commit_signature_commands'),
6216
6643
        ('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6217
6644
        ]:
6218
6645
        builtin_command_registry.register_lazy(name, aliases, module_name)