/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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