/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to breezy/builtins.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""builtin brz commands"""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
import errno
22
20
import os
23
21
import sys
86
84
    RevisionSpec,
87
85
    RevisionInfo,
88
86
    )
89
 
from .sixish import (
90
 
    PY3,
91
 
    text_type,
92
 
    viewitems,
93
 
    viewvalues,
94
 
)
95
87
from .trace import mutter, note, warning, is_quiet, get_verbosity_level
96
88
 
97
89
 
221
213
    if ref_branch is None or ref_branch.name:
222
214
        if ref_branch is not None:
223
215
            control_dir = ref_branch.controldir
224
 
        for name, branch in viewitems(control_dir.get_branches()):
 
216
        for name, branch in control_dir.get_branches().items():
225
217
            yield name, branch
226
218
    else:
227
219
        repo = ref_branch.controldir.find_repository()
268
260
    if revisions is None:
269
261
        return None
270
262
    if len(revisions) != 1:
271
 
        raise errors.BzrCommandError(gettext(
 
263
        raise errors.CommandError(gettext(
272
264
            'brz %s --revision takes exactly one revision identifier') % (
273
265
                command_name,))
274
266
    return revisions[0]
404
396
        from .status import show_tree_status
405
397
 
406
398
        if revision and len(revision) > 2:
407
 
            raise errors.BzrCommandError(
 
399
            raise errors.CommandError(
408
400
                gettext('brz status --revision takes exactly'
409
401
                        ' one or two revision specifiers'))
410
402
 
449
441
    @display_command
450
442
    def run(self, revision_id=None, revision=None, directory=u'.'):
451
443
        if revision_id is not None and revision is not None:
452
 
            raise errors.BzrCommandError(gettext('You can only supply one of'
 
444
            raise errors.CommandError(gettext('You can only supply one of'
453
445
                                                 ' revision_id or --revision'))
454
446
        if revision_id is None and revision is None:
455
 
            raise errors.BzrCommandError(
 
447
            raise errors.CommandError(
456
448
                gettext('You must supply either --revision or a revision_id'))
457
449
 
458
450
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
459
451
 
460
452
        revisions = getattr(b.repository, "revisions", None)
461
453
        if revisions is None:
462
 
            raise errors.BzrCommandError(
 
454
            raise errors.CommandError(
463
455
                gettext('Repository %r does not support '
464
456
                        'access to raw revision texts') % b.repository)
465
457
 
473
465
                    msg = gettext(
474
466
                        "The repository {0} contains no revision {1}.").format(
475
467
                            b.repository.base, revision_id.decode('utf-8'))
476
 
                    raise errors.BzrCommandError(msg)
 
468
                    raise errors.CommandError(msg)
477
469
            elif revision is not None:
478
470
                for rev in revision:
479
471
                    if rev is None:
480
 
                        raise errors.BzrCommandError(
 
472
                        raise errors.CommandError(
481
473
                            gettext('You cannot specify a NULL revision.'))
482
474
                    rev_id = rev.as_revision_id(b)
483
475
                    self.print_revision(revisions, rev_id)
509
501
            try:
510
502
                working = d.open_workingtree()
511
503
            except errors.NoWorkingTree:
512
 
                raise errors.BzrCommandError(
 
504
                raise errors.CommandError(
513
505
                    gettext("No working tree to remove"))
514
506
            except errors.NotLocalUrl:
515
 
                raise errors.BzrCommandError(
 
507
                raise errors.CommandError(
516
508
                    gettext("You cannot remove the working tree"
517
509
                            " of a remote path"))
518
510
            if not force:
522
514
                    raise errors.ShelvedChanges(working)
523
515
 
524
516
            if working.user_url != working.branch.user_url:
525
 
                raise errors.BzrCommandError(
 
517
                raise errors.CommandError(
526
518
                    gettext("You cannot remove the working tree"
527
519
                            " from a lightweight checkout"))
528
520
 
563
555
                pass  # There seems to be a real error here, so we'll reset
564
556
            else:
565
557
                # Refuse
566
 
                raise errors.BzrCommandError(gettext(
 
558
                raise errors.CommandError(gettext(
567
559
                    'The tree does not appear to be corrupt. You probably'
568
560
                    ' want "brz revert" instead. Use "--force" if you are'
569
561
                    ' sure you want to reset the working tree.'))
579
571
                                '-r -1 to set the state to the last commit')
580
572
            else:
581
573
                extra = ''
582
 
            raise errors.BzrCommandError(
 
574
            raise errors.CommandError(
583
575
                gettext('failed to reset the tree state{0}').format(extra))
584
576
 
585
577
 
599
591
    @display_command
600
592
    def run(self, tree=False, location=u'.', revision=None):
601
593
        if revision is not None and tree:
602
 
            raise errors.BzrCommandError(
 
594
            raise errors.CommandError(
603
595
                gettext("--tree and --revision can not be used together"))
604
596
 
605
597
        if tree:
615
607
            self.enter_context(b.lock_read())
616
608
            if revision:
617
609
                if len(revision) != 1:
618
 
                    raise errors.BzrCommandError(gettext(
 
610
                    raise errors.CommandError(gettext(
619
611
                        "Revision numbers only make sense for single "
620
612
                        "revisions, not ranges"))
621
613
                revid = revision[0].as_revision_id(b)
741
733
                    "anything."),
742
734
        'verbose',
743
735
        Option('file-ids-from',
744
 
               type=text_type,
 
736
               type=str,
745
737
               help='Lookup file ids from this tree.'),
746
738
        ]
747
739
    encoding_type = 'replace'
871
863
        Option('kind',
872
864
               help='List entries of a particular kind: file, directory, '
873
865
                    'symlink.',
874
 
               type=text_type),
 
866
               type=str),
875
867
        ]
876
868
    takes_args = ['file*']
877
869
 
879
871
    def run(self, revision=None, show_ids=False, kind=None, include_root=False,
880
872
            file_list=None):
881
873
        if kind and kind not in ['file', 'directory', 'symlink']:
882
 
            raise errors.BzrCommandError(
 
874
            raise errors.CommandError(
883
875
                gettext('invalid kind %r specified') % (kind,))
884
876
 
885
877
        revision = _get_one_revision('inventory', revision)
942
934
        if names_list is None:
943
935
            names_list = []
944
936
        if len(names_list) < 2:
945
 
            raise errors.BzrCommandError(gettext("missing file argument"))
 
937
            raise errors.CommandError(gettext("missing file argument"))
946
938
        tree, rel_names = WorkingTree.open_containing_paths(
947
939
            names_list, canonicalize=False)
948
940
        for file_name in rel_names[0:-1]:
949
941
            if file_name == '':
950
 
                raise errors.BzrCommandError(
 
942
                raise errors.CommandError(
951
943
                    gettext("can not copy root of branch"))
952
944
        self.enter_context(tree.lock_tree_write())
953
945
        into_existing = osutils.isdir(names_list[-1])
955
947
            try:
956
948
                (src, dst) = rel_names
957
949
            except IndexError:
958
 
                raise errors.BzrCommandError(
 
950
                raise errors.CommandError(
959
951
                    gettext('to copy multiple files the'
960
952
                            ' destination must be a versioned'
961
953
                            ' directory'))
969
961
            try:
970
962
                src_kind = tree.stored_kind(src)
971
963
            except errors.NoSuchFile:
972
 
                raise errors.BzrCommandError(
 
964
                raise errors.CommandError(
973
965
                    gettext('Could not copy %s => %s: %s is not versioned.')
974
966
                    % (src, dst, src))
975
967
            if src_kind is None:
976
 
                raise errors.BzrCommandError(
 
968
                raise errors.CommandError(
977
969
                    gettext('Could not copy %s => %s . %s is not versioned\\.'
978
970
                            % (src, dst, src)))
979
971
            if src_kind == 'directory':
980
 
                raise errors.BzrCommandError(
 
972
                raise errors.CommandError(
981
973
                    gettext('Could not copy %s => %s . %s is a directory.'
982
974
                            % (src, dst, src)))
983
975
            dst_parent = osutils.split(dst)[0]
985
977
                try:
986
978
                    dst_parent_kind = tree.stored_kind(dst_parent)
987
979
                except errors.NoSuchFile:
988
 
                    raise errors.BzrCommandError(
 
980
                    raise errors.CommandError(
989
981
                        gettext('Could not copy %s => %s: %s is not versioned.')
990
982
                        % (src, dst, dst_parent))
991
983
                if dst_parent_kind != 'directory':
992
 
                    raise errors.BzrCommandError(
 
984
                    raise errors.CommandError(
993
985
                        gettext('Could not copy to %s: %s is not a directory.')
994
986
                        % (dst_parent, dst_parent))
995
987
 
1031
1023
        if auto:
1032
1024
            return self.run_auto(names_list, after, dry_run)
1033
1025
        elif dry_run:
1034
 
            raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
 
1026
            raise errors.CommandError(gettext('--dry-run requires --auto.'))
1035
1027
        if names_list is None:
1036
1028
            names_list = []
1037
1029
        if len(names_list) < 2:
1038
 
            raise errors.BzrCommandError(gettext("missing file argument"))
 
1030
            raise errors.CommandError(gettext("missing file argument"))
1039
1031
        tree, rel_names = WorkingTree.open_containing_paths(
1040
1032
            names_list, canonicalize=False)
1041
1033
        for file_name in rel_names[0:-1]:
1042
1034
            if file_name == '':
1043
 
                raise errors.BzrCommandError(
 
1035
                raise errors.CommandError(
1044
1036
                    gettext("can not move root of branch"))
1045
1037
        self.enter_context(tree.lock_tree_write())
1046
1038
        self._run(tree, names_list, rel_names, after)
1047
1039
 
1048
1040
    def run_auto(self, names_list, after, dry_run):
1049
1041
        if names_list is not None and len(names_list) > 1:
1050
 
            raise errors.BzrCommandError(
 
1042
            raise errors.CommandError(
1051
1043
                gettext('Only one path may be specified to --auto.'))
1052
1044
        if after:
1053
 
            raise errors.BzrCommandError(
 
1045
            raise errors.CommandError(
1054
1046
                gettext('--after cannot be specified with --auto.'))
1055
1047
        work_tree, file_list = WorkingTree.open_containing_paths(
1056
1048
            names_list, default_directory='.')
1087
1079
                    self.outf.write("%s => %s\n" % (src, dest))
1088
1080
        else:
1089
1081
            if len(names_list) != 2:
1090
 
                raise errors.BzrCommandError(gettext('to mv multiple files the'
 
1082
                raise errors.CommandError(gettext('to mv multiple files the'
1091
1083
                                                     ' destination must be a versioned'
1092
1084
                                                     ' directory'))
1093
1085
 
1230
1222
        stored_loc = branch_to.get_parent()
1231
1223
        if location is None:
1232
1224
            if stored_loc is None:
1233
 
                raise errors.BzrCommandError(gettext("No pull location known or"
 
1225
                raise errors.CommandError(gettext("No pull location known or"
1234
1226
                                                     " specified."))
1235
1227
            else:
1236
1228
                display_url = urlutils.unescape_for_display(stored_loc,
1243
1235
        revision = _get_one_revision('pull', revision)
1244
1236
        if mergeable is not None:
1245
1237
            if revision is not None:
1246
 
                raise errors.BzrCommandError(gettext(
 
1238
                raise errors.CommandError(gettext(
1247
1239
                    'Cannot use -r with merge directives or bundles'))
1248
1240
            mergeable.install_revisions(branch_to.repository)
1249
1241
            base_revision_id, revision_id, verified = \
1336
1328
                            help='Create a stacked branch that refers to another branch '
1337
1329
                            'for the commit history. Only the work not present in the '
1338
1330
                            'referenced branch is included in the branch created.',
1339
 
                            type=text_type),
 
1331
                            type=str),
1340
1332
                     Option('strict',
1341
1333
                            help='Refuse to push if there are uncommitted changes in'
1342
1334
                            ' the working tree, --no-strict disables the check.'),
1398
1390
                    # error by the feedback given to them. RBC 20080227.
1399
1391
                    stacked_on = parent_url
1400
1392
            if not stacked_on:
1401
 
                raise errors.BzrCommandError(gettext(
 
1393
                raise errors.CommandError(gettext(
1402
1394
                    "Could not determine branch to refer to."))
1403
1395
 
1404
1396
        # Get the destination location
1407
1399
            if stored_loc is None:
1408
1400
                parent_loc = br_from.get_parent()
1409
1401
                if parent_loc:
1410
 
                    raise errors.BzrCommandError(gettext(
 
1402
                    raise errors.CommandError(gettext(
1411
1403
                        "No push location known or specified. To push to the "
1412
1404
                        "parent branch (at %s), use 'brz push :parent'." %
1413
1405
                        urlutils.unescape_for_display(parent_loc,
1414
1406
                                                      self.outf.encoding)))
1415
1407
                else:
1416
 
                    raise errors.BzrCommandError(gettext(
 
1408
                    raise errors.CommandError(gettext(
1417
1409
                        "No push location known or specified."))
1418
1410
            else:
1419
1411
                display_url = urlutils.unescape_for_display(stored_loc,
1448
1440
    takes_options = ['revision',
1449
1441
                     Option(
1450
1442
                         'hardlink', help='Hard-link working tree files where possible.'),
1451
 
                     Option('files-from', type=text_type,
 
1443
                     Option('files-from', type=str,
1452
1444
                            help="Get file contents from this tree."),
1453
1445
                     Option('no-tree',
1454
1446
                            help="Create a branch without a working-tree."),
1512
1504
                    to_transport)
1513
1505
            except errors.NotBranchError:
1514
1506
                if not use_existing_dir:
1515
 
                    raise errors.BzrCommandError(gettext('Target directory "%s" '
 
1507
                    raise errors.CommandError(gettext('Target directory "%s" '
1516
1508
                                                         'already exists.') % to_location)
1517
1509
                else:
1518
1510
                    to_dir = None
1524
1516
                else:
1525
1517
                    raise errors.AlreadyBranchError(to_location)
1526
1518
        except errors.NoSuchFile:
1527
 
            raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
 
1519
            raise errors.CommandError(gettext('Parent of "%s" does not exist.')
1528
1520
                                         % to_location)
1529
1521
        else:
1530
1522
            to_dir = None
1545
1537
                to_transport.delete_tree('.')
1546
1538
                msg = gettext("The branch {0} has no revision {1}.").format(
1547
1539
                    from_location, revision)
1548
 
                raise errors.BzrCommandError(msg)
 
1540
                raise errors.CommandError(msg)
1549
1541
        else:
1550
1542
            try:
1551
1543
                to_repo = to_dir.open_repository()
1601
1593
        if recursive:
1602
1594
            t = transport.get_transport(location, purpose='read')
1603
1595
            if not t.listable():
1604
 
                raise errors.BzrCommandError(
 
1596
                raise errors.CommandError(
1605
1597
                    "Can't scan this type of location.")
1606
1598
            for b in controldir.ControlDir.find_branches(t):
1607
1599
                self.outf.write("%s\n" % urlutils.unescape_for_display(
1622
1614
                names[name] = active
1623
1615
            # Only mention the current branch explicitly if it's not
1624
1616
            # one of the colocated branches
1625
 
            if not any(viewvalues(names)) and active_branch is not None:
 
1617
            if not any(names.values()) and active_branch is not None:
1626
1618
                self.outf.write("* %s\n" % gettext("(default)"))
1627
1619
            for name in sorted(names):
1628
1620
                active = names[name]
1630
1622
                    prefix = "*"
1631
1623
                else:
1632
1624
                    prefix = " "
1633
 
                self.outf.write("%s %s\n" % (
1634
 
                    prefix, (name if PY3 else name.encode(self.outf.encoding))))
 
1625
                self.outf.write("%s %s\n" % (prefix, name))
1635
1626
 
1636
1627
 
1637
1628
class cmd_checkout(Command):
1665
1656
                                 "common operations like diff and status without "
1666
1657
                                 "such access, and also support local commits."
1667
1658
                            ),
1668
 
                     Option('files-from', type=text_type,
 
1659
                     Option('files-from', type=str,
1669
1660
                            help="Get file contents from this tree."),
1670
1661
                     Option('hardlink',
1671
1662
                            help='Hard-link working tree files where possible.'
1807
1798
 
1808
1799
    def run(self, dir=None, revision=None, show_base=None):
1809
1800
        if revision is not None and len(revision) != 1:
1810
 
            raise errors.BzrCommandError(gettext(
 
1801
            raise errors.CommandError(gettext(
1811
1802
                "brz update --revision takes exactly one revision"))
1812
1803
        if dir is None:
1813
1804
            tree = WorkingTree.open_containing('.')[0]
1815
1806
            tree, relpath = WorkingTree.open_containing(dir)
1816
1807
            if relpath:
1817
1808
                # See bug 557886.
1818
 
                raise errors.BzrCommandError(gettext(
 
1809
                raise errors.CommandError(gettext(
1819
1810
                    "brz update can only update a whole tree, "
1820
1811
                    "not a file or subdirectory"))
1821
1812
        branch = tree.branch
1861
1852
                old_tip=old_tip,
1862
1853
                show_base=show_base)
1863
1854
        except errors.NoSuchRevision as e:
1864
 
            raise errors.BzrCommandError(gettext(
 
1855
            raise errors.CommandError(gettext(
1865
1856
                "branch has no revision %s\n"
1866
1857
                "brz update --revision only works"
1867
1858
                " for a revision in the branch history")
1963
1954
                                      specific_files=file_list).added
1964
1955
            file_list = sorted([f.path[1] for f in added], reverse=True)
1965
1956
            if len(file_list) == 0:
1966
 
                raise errors.BzrCommandError(gettext('No matching files.'))
 
1957
                raise errors.CommandError(gettext('No matching files.'))
1967
1958
        elif file_list is None:
1968
1959
            # missing files show up in iter_changes(basis) as
1969
1960
            # versioned-with-no-kind.
2125
2116
            to_transport.ensure_base()
2126
2117
        except errors.NoSuchFile:
2127
2118
            if not create_prefix:
2128
 
                raise errors.BzrCommandError(gettext("Parent directory of %s"
 
2119
                raise errors.CommandError(gettext("Parent directory of %s"
2129
2120
                                                     " does not exist."
2130
2121
                                                     "\nYou may supply --create-prefix to create all"
2131
2122
                                                     " leading parent directories.")
2160
2151
            try:
2161
2152
                branch.set_append_revisions_only(True)
2162
2153
            except errors.UpgradeRequired:
2163
 
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
 
2154
                raise errors.CommandError(gettext('This branch format cannot be set'
2164
2155
                                                     ' to append-revisions-only.  Try --default.'))
2165
2156
        if not is_quiet():
2166
2157
            from .info import describe_layout, describe_format
2341
2332
    _see_also = ['status']
2342
2333
    takes_args = ['file*']
2343
2334
    takes_options = [
2344
 
        Option('diff-options', type=text_type,
 
2335
        Option('diff-options', type=str,
2345
2336
               help='Pass these options to the external diff program.'),
2346
 
        Option('prefix', type=text_type,
 
2337
        Option('prefix', type=str,
2347
2338
               short_name='p',
2348
2339
               help='Set prefixes added to old and new filenames, as '
2349
2340
                    'two values separated by a colon. (eg "old/:new/").'),
2350
2341
        Option('old',
2351
2342
               help='Branch/tree to compare from.',
2352
 
               type=text_type,
 
2343
               type=str,
2353
2344
               ),
2354
2345
        Option('new',
2355
2346
               help='Branch/tree to compare to.',
2356
 
               type=text_type,
 
2347
               type=str,
2357
2348
               ),
2358
2349
        'revision',
2359
2350
        'change',
2360
2351
        Option('using',
2361
2352
               help='Use this command to compare files.',
2362
 
               type=text_type,
 
2353
               type=str,
2363
2354
               ),
2364
2355
        RegistryOption('format',
2365
2356
                       short_name='F',
2404
2395
        elif u':' in prefix:
2405
2396
            old_label, new_label = prefix.split(u":")
2406
2397
        else:
2407
 
            raise errors.BzrCommandError(gettext(
 
2398
            raise errors.CommandError(gettext(
2408
2399
                '--prefix expects two values separated by a colon'
2409
2400
                ' (eg "old/:new/")'))
2410
2401
 
2411
2402
        if revision and len(revision) > 2:
2412
 
            raise errors.BzrCommandError(gettext('brz diff --revision takes exactly'
 
2403
            raise errors.CommandError(gettext('brz diff --revision takes exactly'
2413
2404
                                                 ' one or two revision specifiers'))
2414
2405
 
2415
2406
        if using is not None and format is not None:
2416
 
            raise errors.BzrCommandError(gettext(
 
2407
            raise errors.CommandError(gettext(
2417
2408
                '{0} and {1} are mutually exclusive').format(
2418
2409
                '--using', '--format'))
2419
2410
 
2538
2529
        return int(limitstring)
2539
2530
    except ValueError:
2540
2531
        msg = gettext("The limit argument must be an integer.")
2541
 
        raise errors.BzrCommandError(msg)
 
2532
        raise errors.CommandError(msg)
2542
2533
 
2543
2534
 
2544
2535
def _parse_levels(s):
2546
2537
        return int(s)
2547
2538
    except ValueError:
2548
2539
        msg = gettext("The levels argument must be an integer.")
2549
 
        raise errors.BzrCommandError(msg)
 
2540
        raise errors.CommandError(msg)
2550
2541
 
2551
2542
 
2552
2543
class cmd_log(Command):
2734
2725
        Option('message',
2735
2726
               help='Show revisions whose message matches this '
2736
2727
               'regular expression.',
2737
 
               type=text_type,
 
2728
               type=str,
2738
2729
               hidden=True),
2739
2730
        Option('limit',
2740
2731
               short_name='l',
2760
2751
                   short_name='m',
2761
2752
                   help='Show revisions whose properties match this '
2762
2753
                   'expression.',
2763
 
                   type=text_type),
 
2754
                   type=str),
2764
2755
        ListOption('match-message',
2765
2756
                   help='Show revisions whose message matches this '
2766
2757
                   'expression.',
2767
 
                   type=text_type),
 
2758
                   type=str),
2768
2759
        ListOption('match-committer',
2769
2760
                   help='Show revisions whose committer matches this '
2770
2761
                   'expression.',
2771
 
                   type=text_type),
 
2762
                   type=str),
2772
2763
        ListOption('match-author',
2773
2764
                   help='Show revisions whose authors match this '
2774
2765
                   'expression.',
2775
 
                   type=text_type),
 
2766
                   type=str),
2776
2767
        ListOption('match-bugs',
2777
2768
                   help='Show revisions whose bugs match this '
2778
2769
                   'expression.',
2779
 
                   type=text_type)
 
2770
                   type=str)
2780
2771
        ]
2781
2772
    encoding_type = 'replace'
2782
2773
 
2813
2804
            include_merged = False
2814
2805
        if (exclude_common_ancestry
2815
2806
                and (revision is None or len(revision) != 2)):
2816
 
            raise errors.BzrCommandError(gettext(
 
2807
            raise errors.CommandError(gettext(
2817
2808
                '--exclude-common-ancestry requires -r with two revisions'))
2818
2809
        if include_merged:
2819
2810
            if levels is None:
2820
2811
                levels = 0
2821
2812
            else:
2822
 
                raise errors.BzrCommandError(gettext(
 
2813
                raise errors.CommandError(gettext(
2823
2814
                    '{0} and {1} are mutually exclusive').format(
2824
2815
                    '--levels', '--include-merged'))
2825
2816
 
2827
2818
            if len(change) > 1:
2828
2819
                raise errors.RangeInChangeOption()
2829
2820
            if revision is not None:
2830
 
                raise errors.BzrCommandError(gettext(
 
2821
                raise errors.CommandError(gettext(
2831
2822
                    '{0} and {1} are mutually exclusive').format(
2832
2823
                    '--revision', '--change'))
2833
2824
            else:
2834
2825
                revision = change
2835
2826
 
2836
 
        file_ids = []
 
2827
        files = []
2837
2828
        filter_by_dir = False
2838
2829
        if file_list:
2839
2830
            # find the file ids to log and check for directory filtering
2840
2831
            b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2841
2832
                revision, file_list, self._exit_stack)
2842
 
            for relpath, file_id, kind in file_info_list:
2843
 
                if file_id is None:
2844
 
                    raise errors.BzrCommandError(gettext(
 
2833
            for relpath, kind in file_info_list:
 
2834
                if not kind:
 
2835
                    raise errors.CommandError(gettext(
2845
2836
                        "Path unknown at end or start of revision range: %s") %
2846
2837
                        relpath)
2847
2838
                # If the relpath is the top of the tree, we log everything
2848
2839
                if relpath == '':
2849
 
                    file_ids = []
 
2840
                    files = []
2850
2841
                    break
2851
2842
                else:
2852
 
                    file_ids.append(file_id)
 
2843
                    files.append(relpath)
2853
2844
                filter_by_dir = filter_by_dir or (
2854
2845
                    kind in ['directory', 'tree-reference'])
2855
2846
        else:
2880
2871
            delta_type = 'full'
2881
2872
        if not show_diff:
2882
2873
            diff_type = None
2883
 
        elif file_ids:
 
2874
        elif files:
2884
2875
            diff_type = 'partial'
2885
2876
        else:
2886
2877
            diff_type = 'full'
2912
2903
        # original algorithm - per-file-graph - for the "single
2913
2904
        # file that isn't a directory without showing a delta" case.
2914
2905
        partial_history = revision and b.repository._format.supports_chks
2915
 
        match_using_deltas = (len(file_ids) != 1 or filter_by_dir
 
2906
        match_using_deltas = (len(files) != 1 or filter_by_dir
2916
2907
                              or delta_type or partial_history)
2917
2908
 
2918
2909
        match_dict = {}
2928
2919
            match_dict['bugs'] = match_bugs
2929
2920
 
2930
2921
        # Build the LogRequest and execute it
2931
 
        if len(file_ids) == 0:
2932
 
            file_ids = None
 
2922
        if len(files) == 0:
 
2923
            files = None
2933
2924
        rqst = make_log_request_dict(
2934
 
            direction=direction, specific_fileids=file_ids,
 
2925
            direction=direction, specific_files=files,
2935
2926
            start_revision=rev1, end_revision=rev2, limit=limit,
2936
2927
            message_search=message, delta_type=delta_type,
2937
2928
            diff_type=diff_type, _match_using_deltas=match_using_deltas,
2959
2950
            # b is taken from revision[0].get_branch(), and
2960
2951
            # show_log will use its revision_history. Having
2961
2952
            # different branches will lead to weird behaviors.
2962
 
            raise errors.BzrCommandError(gettext(
 
2953
            raise errors.CommandError(gettext(
2963
2954
                "brz %s doesn't accept two revisions in different"
2964
2955
                " branches.") % command_name)
2965
2956
        if start_spec.spec is None:
2975
2966
        else:
2976
2967
            rev2 = end_spec.in_history(branch)
2977
2968
    else:
2978
 
        raise errors.BzrCommandError(gettext(
 
2969
        raise errors.CommandError(gettext(
2979
2970
            'brz %s --revision takes one or two values.') % command_name)
2980
2971
    return rev1, rev2
2981
2972
 
3042
3033
        Option('kind', short_name='k',
3043
3034
               help=('List entries of a particular kind: file, '
3044
3035
                     'directory, symlink, tree-reference.'),
3045
 
               type=text_type),
 
3036
               type=str),
3046
3037
        'null',
3047
3038
        'show-ids',
3048
3039
        'directory',
3055
3046
            null=False, kind=None, show_ids=False, path=None, directory=None):
3056
3047
 
3057
3048
        if kind and kind not in ('file', 'directory', 'symlink', 'tree-reference'):
3058
 
            raise errors.BzrCommandError(gettext('invalid kind specified'))
 
3049
            raise errors.CommandError(gettext('invalid kind specified'))
3059
3050
 
3060
3051
        if verbose and null:
3061
 
            raise errors.BzrCommandError(
 
3052
            raise errors.CommandError(
3062
3053
                gettext('Cannot set both --verbose and --null'))
3063
3054
        all = not (unknown or versioned or ignored)
3064
3055
 
3068
3059
            fs_path = '.'
3069
3060
        else:
3070
3061
            if from_root:
3071
 
                raise errors.BzrCommandError(gettext('cannot specify both --from-root'
 
3062
                raise errors.CommandError(gettext('cannot specify both --from-root'
3072
3063
                                                     ' and PATH'))
3073
3064
            fs_path = path
3074
3065
        tree, branch, relpath = \
3245
3236
                self.outf.write("%s\n" % pattern)
3246
3237
            return
3247
3238
        if not name_pattern_list:
3248
 
            raise errors.BzrCommandError(gettext("ignore requires at least one "
 
3239
            raise errors.CommandError(gettext("ignore requires at least one "
3249
3240
                                                 "NAME_PATTERN or --default-rules."))
3250
3241
        name_pattern_list = [globbing.normalize_pattern(p)
3251
3242
                             for p in name_pattern_list]
3264
3255
        for name_pattern in name_pattern_list:
3265
3256
            if (name_pattern[0] == '/' or
3266
3257
                    (len(name_pattern) > 1 and name_pattern[1] == ':')):
3267
 
                raise errors.BzrCommandError(gettext(
 
3258
                raise errors.CommandError(gettext(
3268
3259
                    "NAME_PATTERN should not be an absolute path"))
3269
3260
        tree, relpath = WorkingTree.open_containing(directory)
3270
3261
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
3325
3316
        try:
3326
3317
            revno = int(revno)
3327
3318
        except ValueError:
3328
 
            raise errors.BzrCommandError(gettext("not a valid revision-number: %r")
 
3319
            raise errors.CommandError(gettext("not a valid revision-number: %r")
3329
3320
                                         % revno)
3330
3321
        revid = WorkingTree.open_containing(
3331
3322
            directory)[0].branch.get_rev_id(revno)
3366
3357
    takes_options = ['directory',
3367
3358
                     Option('format',
3368
3359
                            help="Type of file to export to.",
3369
 
                            type=text_type),
 
3360
                            type=str),
3370
3361
                     'revision',
3371
3362
                     Option('filters', help='Apply content filters to export the '
3372
3363
                            'convenient form.'),
3373
3364
                     Option('root',
3374
 
                            type=text_type,
 
3365
                            type=str,
3375
3366
                            help="Name of the root directory inside the exported file."),
3376
3367
                     Option('per-file-timestamps',
3377
3368
                            help='Set modification time of files to that of the last '
3396
3387
 
3397
3388
        if uncommitted:
3398
3389
            if tree is None:
3399
 
                raise errors.BzrCommandError(
 
3390
                raise errors.CommandError(
3400
3391
                    gettext("--uncommitted requires a working tree"))
3401
3392
            export_tree = tree
3402
3393
        else:
3424
3415
            export(export_tree, dest, format, root, subdir,
3425
3416
                   per_file_timestamps=per_file_timestamps)
3426
3417
        except errors.NoSuchExportFormat as e:
3427
 
            raise errors.BzrCommandError(
 
3418
            raise errors.CommandError(
3428
3419
                gettext('Unsupported export format: %s') % e.format)
3429
3420
 
3430
3421
 
3452
3443
    def run(self, filename, revision=None, name_from_revision=False,
3453
3444
            filters=False, directory=None):
3454
3445
        if revision is not None and len(revision) != 1:
3455
 
            raise errors.BzrCommandError(gettext("brz cat --revision takes exactly"
 
3446
            raise errors.CommandError(gettext("brz cat --revision takes exactly"
3456
3447
                                                 " one revision specifier"))
3457
3448
        tree, branch, relpath = \
3458
3449
            _open_directory_or_containing_tree_or_branch(filename, directory)
3471
3462
        if name_from_revision:
3472
3463
            # Try in revision if requested
3473
3464
            if not rev_tree.is_versioned(relpath):
3474
 
                raise errors.BzrCommandError(gettext(
 
3465
                raise errors.CommandError(gettext(
3475
3466
                    "{0!r} is not present in revision {1}").format(
3476
3467
                        filename, rev_tree.get_revision_id()))
3477
3468
            rev_tree_path = relpath
3485
3476
            if rev_tree_path is None:
3486
3477
                # Path didn't exist in working tree
3487
3478
                if not rev_tree.is_versioned(relpath):
3488
 
                    raise errors.BzrCommandError(gettext(
 
3479
                    raise errors.CommandError(gettext(
3489
3480
                        "{0!r} is not present in revision {1}").format(
3490
3481
                            filename, rev_tree.get_revision_id()))
3491
3482
                else:
3573
3564
    takes_args = ['selected*']
3574
3565
    takes_options = [
3575
3566
        ListOption(
3576
 
            'exclude', type=text_type, short_name='x',
 
3567
            'exclude', type=str, short_name='x',
3577
3568
            help="Do not consider changes made to a given path."),
3578
 
        Option('message', type=text_type,
 
3569
        Option('message', type=str,
3579
3570
               short_name='m',
3580
3571
               help="Description of the new revision."),
3581
3572
        'verbose',
3582
3573
        Option('unchanged',
3583
3574
               help='Commit even if nothing has changed.'),
3584
 
        Option('file', type=text_type,
 
3575
        Option('file', type=str,
3585
3576
               short_name='F',
3586
3577
               argname='msgfile',
3587
3578
               help='Take commit message from this file.'),
3588
3579
        Option('strict',
3589
3580
               help="Refuse to commit if there are unknown "
3590
3581
               "files in the working tree."),
3591
 
        Option('commit-time', type=text_type,
 
3582
        Option('commit-time', type=str,
3592
3583
               help="Manually set a commit time using commit date "
3593
3584
               "format, e.g. '2009-10-10 08:00:00 +0100'."),
3594
3585
        ListOption(
3595
 
            'bugs', type=text_type,
 
3586
            'bugs', type=str,
3596
3587
            help="Link to a related bug. (see \"brz help bugs\")."),
3597
3588
        ListOption(
3598
 
            'fixes', type=text_type,
 
3589
            'fixes', type=str,
3599
3590
            help="Mark a bug as being fixed by this revision "
3600
3591
                 "(see \"brz help bugs\")."),
3601
3592
        ListOption(
3602
 
            'author', type=text_type,
 
3593
            'author', type=str,
3603
3594
            help="Set the author's name, if it's different "
3604
3595
                 "from the committer."),
3605
3596
        Option('local',
3628
3619
                    default_bugtracker = branch_config.get(
3629
3620
                        "bugtracker")
3630
3621
                if default_bugtracker is None:
3631
 
                    raise errors.BzrCommandError(gettext(
 
3622
                    raise errors.CommandError(gettext(
3632
3623
                        "No tracker specified for bug %s. Use the form "
3633
3624
                        "'tracker:id' or specify a default bug tracker "
3634
3625
                        "using the `bugtracker` option.\nSee "
3637
3628
                tag = default_bugtracker
3638
3629
                bug_id = tokens[0]
3639
3630
            elif len(tokens) != 2:
3640
 
                raise errors.BzrCommandError(gettext(
 
3631
                raise errors.CommandError(gettext(
3641
3632
                    "Invalid bug %s. Must be in the form of 'tracker:id'. "
3642
3633
                    "See \"brz help bugs\" for more information on this "
3643
3634
                    "feature.\nCommit refused.") % bug)
3646
3637
            try:
3647
3638
                yield bugtracker.get_bug_url(tag, branch, bug_id), status
3648
3639
            except bugtracker.UnknownBugTrackerAbbreviation:
3649
 
                raise errors.BzrCommandError(gettext(
 
3640
                raise errors.CommandError(gettext(
3650
3641
                    'Unrecognized bug %s. Commit refused.') % bug)
3651
3642
            except bugtracker.MalformedBugIdentifier as e:
3652
 
                raise errors.BzrCommandError(gettext(
 
3643
                raise errors.CommandError(gettext(
3653
3644
                    u"%s\nCommit refused.") % (e,))
3654
3645
 
3655
3646
    def run(self, message=None, file=None, verbose=False, selected_list=None,
3676
3667
            try:
3677
3668
                commit_stamp, offset = timestamp.parse_patch_date(commit_time)
3678
3669
            except ValueError as e:
3679
 
                raise errors.BzrCommandError(gettext(
 
3670
                raise errors.CommandError(gettext(
3680
3671
                    "Could not parse --commit-time: " + str(e)))
3681
3672
 
3682
3673
        properties = {}
3720
3711
                message = message.replace('\r\n', '\n')
3721
3712
                message = message.replace('\r', '\n')
3722
3713
            if file:
3723
 
                raise errors.BzrCommandError(gettext(
 
3714
                raise errors.CommandError(gettext(
3724
3715
                    "please specify either --message or --file"))
3725
3716
 
3726
3717
        def get_message(commit_obj):
3751
3742
                    my_message = edit_commit_message_encoded(text,
3752
3743
                                                             start_message=start_message)
3753
3744
                if my_message is None:
3754
 
                    raise errors.BzrCommandError(gettext("please specify a commit"
 
3745
                    raise errors.CommandError(gettext("please specify a commit"
3755
3746
                                                         " message with either --message or --file"))
3756
3747
                if my_message == "":
3757
 
                    raise errors.BzrCommandError(gettext("Empty commit message specified."
 
3748
                    raise errors.CommandError(gettext("Empty commit message specified."
3758
3749
                                                         " Please specify a commit message with either"
3759
3750
                                                         " --message or --file or leave a blank message"
3760
3751
                                                         " with --message \"\"."))
3774
3765
                        exclude=tree.safe_relpath_files(exclude),
3775
3766
                        lossy=lossy)
3776
3767
        except PointlessCommit:
3777
 
            raise errors.BzrCommandError(gettext("No changes to commit."
 
3768
            raise errors.CommandError(gettext("No changes to commit."
3778
3769
                                                 " Please 'brz add' the files you want to commit, or use"
3779
3770
                                                 " --unchanged to force an empty commit."))
3780
3771
        except ConflictsInTree:
3781
 
            raise errors.BzrCommandError(gettext('Conflicts detected in working '
 
3772
            raise errors.CommandError(gettext('Conflicts detected in working '
3782
3773
                                                 'tree.  Use "brz conflicts" to list, "brz resolve FILE" to'
3783
3774
                                                 ' resolve.'))
3784
3775
        except StrictCommitFailed:
3785
 
            raise errors.BzrCommandError(gettext("Commit refused because there are"
 
3776
            raise errors.CommandError(gettext("Commit refused because there are"
3786
3777
                                                 " unknown files in the working tree."))
3787
3778
        except errors.BoundBranchOutOfDate as e:
3788
3779
            e.extra_help = (gettext("\n"
3964
3955
            return
3965
3956
 
3966
3957
        if email:
3967
 
            raise errors.BzrCommandError(gettext("--email can only be used to display existing "
 
3958
            raise errors.CommandError(gettext("--email can only be used to display existing "
3968
3959
                                                 "identity"))
3969
3960
 
3970
3961
        # display a warning if an email address isn't included in the given name.
4054
4045
 
4055
4046
    def remove_alias(self, alias_name):
4056
4047
        if alias_name is None:
4057
 
            raise errors.BzrCommandError(gettext(
 
4048
            raise errors.CommandError(gettext(
4058
4049
                'brz alias --remove expects an alias to remove.'))
4059
4050
        # If alias is not found, print something like:
4060
4051
        # unalias: foo: not found
4065
4056
    def print_aliases(self):
4066
4057
        """Print out the defined aliases in a similar format to bash."""
4067
4058
        aliases = _mod_config.GlobalConfig().get_aliases()
4068
 
        for key, value in sorted(viewitems(aliases)):
 
4059
        for key, value in sorted(aliases.items()):
4069
4060
            self.outf.write('brz alias %s="%s"\n' % (key, value))
4070
4061
 
4071
4062
    @display_command
4149
4140
            return test_server.FakeNFSServer
4150
4141
        msg = "No known transport type %s. Supported types are: sftp\n" %\
4151
4142
            (typestring)
4152
 
        raise errors.BzrCommandError(msg)
 
4143
        raise errors.CommandError(msg)
4153
4144
 
4154
4145
    hidden = True
4155
4146
    takes_args = ['testspecs*']
4182
4173
                                        'breezy.tests', 'parallel_registry'),
4183
4174
                                    value_switches=False,
4184
4175
                                    ),
4185
 
                     Option('randomize', type=text_type, argname="SEED",
 
4176
                     Option('randomize', type=str, argname="SEED",
4186
4177
                            help='Randomize the order of tests using the given'
4187
4178
                                 ' seed or "now" for the current time.'),
4188
 
                     ListOption('exclude', type=text_type, argname="PATTERN",
 
4179
                     ListOption('exclude', type=str, argname="PATTERN",
4189
4180
                                short_name='x',
4190
4181
                                help='Exclude tests that match this regular'
4191
4182
                                ' expression.'),
4195
4186
                            help='Output test progress via subunit v2.'),
4196
4187
                     Option('strict', help='Fail on missing dependencies or '
4197
4188
                            'known failures.'),
4198
 
                     Option('load-list', type=text_type, argname='TESTLISTFILE',
 
4189
                     Option('load-list', type=str, argname='TESTLISTFILE',
4199
4190
                            help='Load a test id list from a text file.'),
4200
 
                     ListOption('debugflag', type=text_type, short_name='E',
 
4191
                     ListOption('debugflag', type=str, short_name='E',
4201
4192
                                help='Turn on a selftest debug flag.'),
4202
 
                     ListOption('starting-with', type=text_type, argname='TESTID',
 
4193
                     ListOption('starting-with', type=str, argname='TESTID',
4203
4194
                                param_name='starting_with', short_name='s',
4204
4195
                                help='Load only the tests starting with TESTID.'),
4205
4196
                     Option('sync',
4233
4224
 
4234
4225
        try:
4235
4226
            from . import tests
4236
 
        except ImportError:
4237
 
            raise errors.BzrCommandError("tests not available. Install the "
 
4227
        except ImportError as e:
 
4228
            raise errors.CommandError("tests not available. Install the "
4238
4229
                                         "breezy tests to run the breezy testsuite.")
4239
4230
 
4240
4231
        if testspecs_list is not None:
4245
4236
            try:
4246
4237
                from .tests import SubUnitBzrRunnerv1
4247
4238
            except ImportError:
4248
 
                raise errors.BzrCommandError(gettext(
 
4239
                raise errors.CommandError(gettext(
4249
4240
                    "subunit not available. subunit needs to be installed "
4250
4241
                    "to use --subunit."))
4251
4242
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv1
4262
4253
            try:
4263
4254
                from .tests import SubUnitBzrRunnerv2
4264
4255
            except ImportError:
4265
 
                raise errors.BzrCommandError(gettext(
 
4256
                raise errors.CommandError(gettext(
4266
4257
                    "subunit not available. subunit "
4267
4258
                    "needs to be installed to use --subunit2."))
4268
4259
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv2
4271
4262
            self.additional_selftest_args.setdefault(
4272
4263
                'suite_decorators', []).append(parallel)
4273
4264
        if benchmark:
4274
 
            raise errors.BzrCommandError(gettext(
 
4265
            raise errors.CommandError(gettext(
4275
4266
                "--benchmark is no longer supported from brz 2.2; "
4276
4267
                "use bzr-usertest instead"))
4277
4268
        test_suite_factory = None
4499
4490
 
4500
4491
        tree = WorkingTree.open_containing(directory)[0]
4501
4492
        if tree.branch.last_revision() == _mod_revision.NULL_REVISION:
4502
 
            raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
 
4493
            raise errors.CommandError(gettext('Merging into empty branches not currently supported, '
4503
4494
                                                 'https://bugs.launchpad.net/bzr/+bug/308562'))
4504
4495
 
4505
4496
        # die as quickly as possible if there are uncommitted changes
4521
4512
                mergeable = None
4522
4513
            else:
4523
4514
                if uncommitted:
4524
 
                    raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
 
4515
                    raise errors.CommandError(gettext('Cannot use --uncommitted'
4525
4516
                                                         ' with bundles or merge directives.'))
4526
4517
 
4527
4518
                if revision is not None:
4528
 
                    raise errors.BzrCommandError(gettext(
 
4519
                    raise errors.CommandError(gettext(
4529
4520
                        'Cannot use -r with merge directives or bundles'))
4530
4521
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
4531
4522
                                                                    mergeable)
4532
4523
 
4533
4524
        if merger is None and uncommitted:
4534
4525
            if revision is not None and len(revision) > 0:
4535
 
                raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
 
4526
                raise errors.CommandError(gettext('Cannot use --uncommitted and'
4536
4527
                                                     ' --revision at the same time.'))
4537
4528
            merger = self.get_merger_from_uncommitted(tree, location, None)
4538
4529
            allow_pending = False
4558
4549
            return 0
4559
4550
        if pull and not preview:
4560
4551
            if merger.interesting_files is not None:
4561
 
                raise errors.BzrCommandError(
 
4552
                raise errors.CommandError(
4562
4553
                    gettext('Cannot pull individual files'))
4563
4554
            if (merger.base_rev_id == tree.last_revision()):
4564
4555
                result = tree.pull(merger.other_branch, False,
4566
4557
                result.report(self.outf)
4567
4558
                return 0
4568
4559
        if merger.this_basis is None:
4569
 
            raise errors.BzrCommandError(gettext(
 
4560
            raise errors.CommandError(gettext(
4570
4561
                "This branch has no commits."
4571
4562
                " (perhaps you would prefer 'brz pull')"))
4572
4563
        if preview:
4625
4616
    def sanity_check_merger(self, merger):
4626
4617
        if (merger.show_base and
4627
4618
                merger.merge_type is not _mod_merge.Merge3Merger):
4628
 
            raise errors.BzrCommandError(gettext("Show-base is not supported for this"
 
4619
            raise errors.CommandError(gettext("Show-base is not supported for this"
4629
4620
                                                 " merge type. %s") % merger.merge_type)
4630
4621
        if merger.reprocess is None:
4631
4622
            if merger.show_base:
4634
4625
                # Use reprocess if the merger supports it
4635
4626
                merger.reprocess = merger.merge_type.supports_reprocess
4636
4627
        if merger.reprocess and not merger.merge_type.supports_reprocess:
4637
 
            raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
 
4628
            raise errors.CommandError(gettext("Conflict reduction is not supported"
4638
4629
                                                 " for merge type %s.") %
4639
4630
                                         merger.merge_type)
4640
4631
        if merger.reprocess and merger.show_base:
4641
 
            raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
 
4632
            raise errors.CommandError(gettext("Cannot do conflict reduction and"
4642
4633
                                                 " show base."))
4643
4634
 
4644
4635
        if (merger.merge_type.requires_file_merge_plan and
4646
4637
             not getattr(merger.other_tree, 'plan_file_merge', None) or
4647
4638
             (merger.base_tree is not None and
4648
4639
                 not getattr(merger.base_tree, 'plan_file_merge', None)))):
4649
 
            raise errors.BzrCommandError(
 
4640
            raise errors.CommandError(
4650
4641
                gettext('Plan file merge unsupported: '
4651
4642
                        'Merge type incompatible with tree formats.'))
4652
4643
 
4757
4748
            stored_location_type = "parent"
4758
4749
        mutter("%s", stored_location)
4759
4750
        if stored_location is None:
4760
 
            raise errors.BzrCommandError(
 
4751
            raise errors.CommandError(
4761
4752
                gettext("No location specified or remembered"))
4762
4753
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4763
4754
        note(gettext("{0} remembered {1} location {2}").format(verb_string,
4804
4795
        self.enter_context(tree.lock_write())
4805
4796
        parents = tree.get_parent_ids()
4806
4797
        if len(parents) != 2:
4807
 
            raise errors.BzrCommandError(
 
4798
            raise errors.CommandError(
4808
4799
                gettext("Sorry, remerge only works after normal"
4809
4800
                        " merges.  Not cherrypicking or multi-merges."))
4810
4801
        interesting_files = None
5079
5070
        if other_branch is None:
5080
5071
            other_branch = parent
5081
5072
            if other_branch is None:
5082
 
                raise errors.BzrCommandError(gettext("No peer location known"
 
5073
                raise errors.CommandError(gettext("No peer location known"
5083
5074
                                                     " or specified."))
5084
5075
            display_url = urlutils.unescape_for_display(parent,
5085
5076
                                                        self.outf.encoding)
5327
5318
 
5328
5319
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
5329
5320
        if revision_id_list is not None and revision is not None:
5330
 
            raise errors.BzrCommandError(
 
5321
            raise errors.CommandError(
5331
5322
                gettext('You can only supply one of revision_id or --revision'))
5332
5323
        if revision_id_list is None and revision is None:
5333
 
            raise errors.BzrCommandError(
 
5324
            raise errors.CommandError(
5334
5325
                gettext('You must supply either --revision or a revision_id'))
5335
5326
        b = WorkingTree.open_containing(directory)[0].branch
5336
5327
        self.enter_context(b.lock_write())
5358
5349
                if to_revid is None:
5359
5350
                    to_revno = b.revno()
5360
5351
                if from_revno is None or to_revno is None:
5361
 
                    raise errors.BzrCommandError(
 
5352
                    raise errors.CommandError(
5362
5353
                        gettext('Cannot sign a range of non-revision-history revisions'))
5363
5354
                with WriteGroup(b.repository):
5364
5355
                    for revno in range(from_revno, to_revno + 1):
5365
5356
                        b.repository.sign_revision(b.get_rev_id(revno),
5366
5357
                                                   gpg_strategy)
5367
5358
            else:
5368
 
                raise errors.BzrCommandError(
 
5359
                raise errors.CommandError(
5369
5360
                    gettext('Please supply either one revision, or a range.'))
5370
5361
 
5371
5362
 
5391
5382
            try:
5392
5383
                location = b.get_old_bound_location()
5393
5384
            except errors.UpgradeRequired:
5394
 
                raise errors.BzrCommandError(
 
5385
                raise errors.CommandError(
5395
5386
                    gettext('No location supplied.  '
5396
5387
                            'This format does not remember old locations.'))
5397
5388
            else:
5398
5389
                if location is None:
5399
5390
                    if b.get_bound_location() is not None:
5400
 
                        raise errors.BzrCommandError(
 
5391
                        raise errors.CommandError(
5401
5392
                            gettext('Branch is already bound'))
5402
5393
                    else:
5403
 
                        raise errors.BzrCommandError(
 
5394
                        raise errors.CommandError(
5404
5395
                            gettext('No location supplied'
5405
5396
                                    ' and no previous location known'))
5406
5397
        b_other = Branch.open(location)
5407
5398
        try:
5408
5399
            b.bind(b_other)
5409
5400
        except errors.DivergedBranches:
5410
 
            raise errors.BzrCommandError(
 
5401
            raise errors.CommandError(
5411
5402
                gettext('These branches have diverged.'
5412
5403
                        ' Try merging, and then bind again.'))
5413
5404
        if b.get_config().has_explicit_nickname():
5428
5419
    def run(self, directory=u'.'):
5429
5420
        b, relpath = Branch.open_containing(directory)
5430
5421
        if not b.unbind():
5431
 
            raise errors.BzrCommandError(gettext('Local branch is not bound'))
 
5422
            raise errors.CommandError(gettext('Local branch is not bound'))
5432
5423
 
5433
5424
 
5434
5425
class cmd_uncommit(Command):
5625
5616
                       value_switches=True),
5626
5617
        Option('listen',
5627
5618
               help='Listen for connections on nominated address.',
5628
 
               type=text_type),
 
5619
               type=str),
5629
5620
        Option('port',
5630
5621
               help='Listen for connections on nominated port.  Passing 0 as '
5631
5622
                    'the port number will result in a dynamically allocated '
5687
5678
        containing_tree = WorkingTree.open_containing(parent_dir)[0]
5688
5679
        repo = containing_tree.branch.repository
5689
5680
        if not repo.supports_rich_root():
5690
 
            raise errors.BzrCommandError(gettext(
 
5681
            raise errors.CommandError(gettext(
5691
5682
                "Can't join trees because %s doesn't support rich root data.\n"
5692
5683
                "You can use brz upgrade on the repository.")
5693
5684
                % (repo,))
5697
5688
            except BadReferenceTarget as e:
5698
5689
                # XXX: Would be better to just raise a nicely printable
5699
5690
                # exception from the real origin.  Also below.  mbp 20070306
5700
 
                raise errors.BzrCommandError(
 
5691
                raise errors.CommandError(
5701
5692
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5702
5693
        else:
5703
5694
            try:
5704
5695
                containing_tree.subsume(sub_tree)
5705
5696
            except errors.BadSubsumeSource as e:
5706
 
                raise errors.BzrCommandError(
 
5697
                raise errors.CommandError(
5707
5698
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5708
5699
 
5709
5700
 
5767
5758
            diff='Normal unified diff.',
5768
5759
            plain='No patch, just directive.'),
5769
5760
        Option('sign', help='GPG-sign the directive.'), 'revision',
5770
 
        Option('mail-to', type=text_type,
 
5761
        Option('mail-to', type=str,
5771
5762
               help='Instead of printing the directive, email to this '
5772
5763
               'address.'),
5773
 
        Option('message', type=text_type, short_name='m',
 
5764
        Option('message', type=str, short_name='m',
5774
5765
               help='Message to use when committing this merge.')
5775
5766
        ]
5776
5767
 
5795
5786
        if submit_branch is None:
5796
5787
            submit_branch = branch.get_parent()
5797
5788
        if submit_branch is None:
5798
 
            raise errors.BzrCommandError(
 
5789
            raise errors.CommandError(
5799
5790
                gettext('No submit branch specified or known'))
5800
5791
 
5801
5792
        stored_public_branch = branch.get_public_branch()
5805
5796
            # FIXME: Should be done only if we succeed ? -- vila 2012-01-03
5806
5797
            branch.set_public_branch(public_branch)
5807
5798
        if not include_bundle and public_branch is None:
5808
 
            raise errors.BzrCommandError(
 
5799
            raise errors.CommandError(
5809
5800
                gettext('No public branch specified or known'))
5810
5801
        base_revision_id = None
5811
5802
        if revision is not None:
5812
5803
            if len(revision) > 2:
5813
 
                raise errors.BzrCommandError(
 
5804
                raise errors.CommandError(
5814
5805
                    gettext('brz merge-directive takes '
5815
5806
                            'at most two one revision identifiers'))
5816
5807
            revision_id = revision[-1].as_revision_id(branch)
5820
5811
            revision_id = branch.last_revision()
5821
5812
        revision_id = ensure_null(revision_id)
5822
5813
        if revision_id == NULL_REVISION:
5823
 
            raise errors.BzrCommandError(gettext('No revisions to bundle.'))
 
5814
            raise errors.CommandError(gettext('No revisions to bundle.'))
5824
5815
        directive = merge_directive.MergeDirective2.from_objects(
5825
5816
            branch.repository, revision_id, time.time(),
5826
5817
            osutils.local_time_offset(), submit_branch,
5924
5915
               help='Branch to generate the submission from, '
5925
5916
               'rather than the one containing the working directory.',
5926
5917
               short_name='f',
5927
 
               type=text_type),
 
5918
               type=str),
5928
5919
        Option('output', short_name='o',
5929
5920
               help='Write merge directive to this file or directory; '
5930
5921
                    'use - for stdout.',
5931
 
               type=text_type),
 
5922
               type=str),
5932
5923
        Option('strict',
5933
5924
               help='Refuse to send if there are uncommitted changes in'
5934
5925
               ' the working tree, --no-strict disables the check.'),
5935
5926
        Option('mail-to', help='Mail the request to this address.',
5936
 
               type=text_type),
 
5927
               type=str),
5937
5928
        'revision',
5938
5929
        'message',
5939
 
        Option('body', help='Body for the email.', type=text_type),
 
5930
        Option('body', help='Body for the email.', type=str),
5940
5931
        RegistryOption('format',
5941
5932
                       help='Use the specified output format.',
5942
5933
                       lazy_registry=('breezy.send', 'format_registry')),
5992
5983
               help='Branch to generate the submission from, '
5993
5984
               'rather than the one containing the working directory.',
5994
5985
               short_name='f',
5995
 
               type=text_type),
 
5986
               type=str),
5996
5987
        Option('output', short_name='o', help='Write directive to this file.',
5997
 
               type=text_type),
 
5988
               type=str),
5998
5989
        Option('strict',
5999
5990
               help='Refuse to bundle revisions if there are uncommitted'
6000
5991
               ' changes in the working tree, --no-strict disables the check.'),
6067
6058
        self.enter_context(branch.lock_write())
6068
6059
        if delete:
6069
6060
            if tag_name is None:
6070
 
                raise errors.BzrCommandError(
 
6061
                raise errors.CommandError(
6071
6062
                    gettext("No tag specified to delete."))
6072
6063
            branch.tags.delete_tag(tag_name)
6073
6064
            note(gettext('Deleted tag %s.') % tag_name)
6074
6065
        else:
6075
6066
            if revision:
6076
6067
                if len(revision) != 1:
6077
 
                    raise errors.BzrCommandError(gettext(
 
6068
                    raise errors.CommandError(gettext(
6078
6069
                        "Tags can only be placed on a single revision, "
6079
6070
                        "not on a range"))
6080
6071
                revision_id = revision[0].as_revision_id(branch)
6083
6074
            if tag_name is None:
6084
6075
                tag_name = branch.automatic_tag_name(revision_id)
6085
6076
                if tag_name is None:
6086
 
                    raise errors.BzrCommandError(gettext(
 
6077
                    raise errors.CommandError(gettext(
6087
6078
                        "Please specify a tag name."))
6088
6079
            try:
6089
6080
                existing_target = branch.tags.lookup_tag(tag_name)
6124
6115
        from .tag import tag_sort_methods
6125
6116
        branch, relpath = Branch.open_containing(directory)
6126
6117
 
6127
 
        tags = list(viewitems(branch.tags.get_tag_dict()))
 
6118
        tags = list(branch.tags.get_tag_dict().items())
6128
6119
        if not tags:
6129
6120
            return
6130
6121
 
6228
6219
            with_no_trees='Reconfigure repository to not create '
6229
6220
            'working trees on branches by default.'
6230
6221
            ),
6231
 
        Option('bind-to', help='Branch to bind checkout to.', type=text_type),
 
6222
        Option('bind-to', help='Branch to bind checkout to.', type=str),
6232
6223
        Option('force',
6233
6224
               help='Perform reconfiguration even if local changes'
6234
6225
               ' will be lost.'),
6235
6226
        Option('stacked-on',
6236
6227
               help='Reconfigure a branch to be stacked on another branch.',
6237
 
               type=text_type,
 
6228
               type=str,
6238
6229
               ),
6239
6230
        Option('unstacked',
6240
6231
               help='Reconfigure a branch to be unstacked.  This '
6247
6238
            stacked_on=None, unstacked=None):
6248
6239
        directory = controldir.ControlDir.open(location)
6249
6240
        if stacked_on and unstacked:
6250
 
            raise errors.BzrCommandError(
 
6241
            raise errors.CommandError(
6251
6242
                gettext("Can't use both --stacked-on and --unstacked"))
6252
6243
        elif stacked_on is not None:
6253
6244
            reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
6262
6253
            if stacked_on or unstacked:
6263
6254
                return
6264
6255
            else:
6265
 
                raise errors.BzrCommandError(gettext('No target configuration '
 
6256
                raise errors.CommandError(gettext('No target configuration '
6266
6257
                                                     'specified'))
6267
6258
        reconfiguration = None
6268
6259
        if tree_type == 'branch':
6341
6332
        possible_transports = [control_dir.root_transport]
6342
6333
        if to_location is None:
6343
6334
            if revision is None:
6344
 
                raise errors.BzrCommandError(gettext('You must supply either a'
 
6335
                raise errors.CommandError(gettext('You must supply either a'
6345
6336
                                                     ' revision or a location'))
6346
6337
            to_location = tree_location
6347
6338
        try:
6355
6346
            possible_transports.append(branch.user_transport)
6356
6347
        if create_branch:
6357
6348
            if branch is None:
6358
 
                raise errors.BzrCommandError(
 
6349
                raise errors.CommandError(
6359
6350
                    gettext('cannot create branch without source branch'))
6360
6351
            to_location = lookup_new_sibling_branch(
6361
6352
                control_dir, to_location,
6383
6374
                          store_uncommitted=store,
6384
6375
                          possible_transports=possible_transports)
6385
6376
        except controldir.BranchReferenceLoop:
6386
 
            raise errors.BzrCommandError(
 
6377
            raise errors.CommandError(
6387
6378
                gettext('switching would create a branch reference loop. '
6388
6379
                        'Use the "bzr up" command to switch to a '
6389
6380
                        'different revision.'))
6474
6465
               ),
6475
6466
        Option('name',
6476
6467
               help='Name of the view to define, list or delete.',
6477
 
               type=text_type,
 
6468
               type=str,
6478
6469
               ),
6479
6470
        Option('switch',
6480
6471
               help='Name of the view to switch to.',
6481
 
               type=text_type,
 
6472
               type=str,
6482
6473
               ),
6483
6474
        ]
6484
6475
 
6495
6486
            name = current_view
6496
6487
        if delete:
6497
6488
            if file_list:
6498
 
                raise errors.BzrCommandError(gettext(
 
6489
                raise errors.CommandError(gettext(
6499
6490
                    "Both --delete and a file list specified"))
6500
6491
            elif switch:
6501
 
                raise errors.BzrCommandError(gettext(
 
6492
                raise errors.CommandError(gettext(
6502
6493
                    "Both --delete and --switch specified"))
6503
6494
            elif all:
6504
6495
                tree.views.set_view_info(None, {})
6505
6496
                self.outf.write(gettext("Deleted all views.\n"))
6506
6497
            elif name is None:
6507
 
                raise errors.BzrCommandError(
 
6498
                raise errors.CommandError(
6508
6499
                    gettext("No current view to delete"))
6509
6500
            else:
6510
6501
                tree.views.delete_view(name)
6511
6502
                self.outf.write(gettext("Deleted '%s' view.\n") % name)
6512
6503
        elif switch:
6513
6504
            if file_list:
6514
 
                raise errors.BzrCommandError(gettext(
 
6505
                raise errors.CommandError(gettext(
6515
6506
                    "Both --switch and a file list specified"))
6516
6507
            elif all:
6517
 
                raise errors.BzrCommandError(gettext(
 
6508
                raise errors.CommandError(gettext(
6518
6509
                    "Both --switch and --all specified"))
6519
6510
            elif switch == 'off':
6520
6511
                if current_view is None:
6521
 
                    raise errors.BzrCommandError(
 
6512
                    raise errors.CommandError(
6522
6513
                        gettext("No current view to disable"))
6523
6514
                tree.views.set_view_info(None, view_dict)
6524
6515
                self.outf.write(gettext("Disabled '%s' view.\n") %
6545
6536
                # No name given and no current view set
6546
6537
                name = 'my'
6547
6538
            elif name == 'off':
6548
 
                raise errors.BzrCommandError(gettext(
 
6539
                raise errors.CommandError(gettext(
6549
6540
                    "Cannot change the 'off' pseudo view"))
6550
6541
            tree.views.set_view(name, sorted(file_list))
6551
6542
            view_str = views.view_display_str(tree.views.lookup_view())
6612
6603
                active_branch = None
6613
6604
            if (active_branch is not None and
6614
6605
                    br.control_url == active_branch.control_url):
6615
 
                raise errors.BzrCommandError(
 
6606
                raise errors.CommandError(
6616
6607
                    gettext("Branch is active. Use --force to remove it."))
6617
6608
        br.controldir.destroy_branch(br.name)
6618
6609
 
6827
6818
    takes_options = [Option('plugin',
6828
6819
                            help='Export help text from named command '
6829
6820
                                 '(defaults to all built in commands).',
6830
 
                            type=text_type),
 
6821
                            type=str),
6831
6822
                     Option('include-duplicates',
6832
6823
                            help='Output multiple copies of the same msgid '
6833
6824
                                 'string if it appears more than once.'),
6933
6924
    takes_options = [
6934
6925
        'verbose',
6935
6926
        'revision',
6936
 
        Option('color', type=text_type, argname='when',
 
6927
        Option('color', type=str, argname='when',
6937
6928
               help='Show match in color. WHEN is never, always or auto.'),
6938
6929
        Option('diff', short_name='p',
6939
6930
               help='Grep for pattern in changeset for each revision.'),
6940
 
        ListOption('exclude', type=text_type, argname='glob', short_name='X',
 
6931
        ListOption('exclude', type=str, argname='glob', short_name='X',
6941
6932
                   help="Skip files whose base name matches GLOB."),
6942
 
        ListOption('include', type=text_type, argname='glob', short_name='I',
 
6933
        ListOption('include', type=str, argname='glob', short_name='I',
6943
6934
                   help="Search only files whose base name matches GLOB."),
6944
6935
        Option('files-with-matches', short_name='l',
6945
6936
               help='Print only the name of each input file in '
6981
6972
            path_list = ['.']
6982
6973
        else:
6983
6974
            if from_root:
6984
 
                raise errors.BzrCommandError(
 
6975
                raise errors.CommandError(
6985
6976
                    'cannot specify both --from-root and PATH.')
6986
6977
 
6987
6978
        if files_with_matches and files_without_match:
6988
 
            raise errors.BzrCommandError(
 
6979
            raise errors.CommandError(
6989
6980
                'cannot specify both '
6990
6981
                '-l/--files-with-matches and -L/--files-without-matches.')
6991
6982
 
6998
6989
            color = 'never'
6999
6990
 
7000
6991
        if color not in ['always', 'never', 'auto']:
7001
 
            raise errors.BzrCommandError('Valid values for --color are '
 
6992
            raise errors.CommandError('Valid values for --color are '
7002
6993
                                         '"always", "never" or "auto".')
7003
6994
 
7004
6995
        if levels is None: