/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: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
446
446
    def run(self, revision_id=None, revision=None, directory=u'.'):
447
447
        if revision_id is not None and revision is not None:
448
448
            raise errors.BzrCommandError(gettext('You can only supply one of'
449
 
                                         ' revision_id or --revision'))
 
449
                                                 ' revision_id or --revision'))
450
450
        if revision_id is None and revision is None:
451
451
            raise errors.BzrCommandError(gettext('You must supply either'
452
 
                                         ' --revision or a revision_id'))
 
452
                                                 ' --revision or a revision_id'))
453
453
 
454
454
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
455
455
 
930
930
            names_list = []
931
931
        if len(names_list) < 2:
932
932
            raise errors.BzrCommandError(gettext("missing file argument"))
933
 
        tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
 
933
        tree, rel_names = WorkingTree.open_containing_paths(
 
934
            names_list, canonicalize=False)
934
935
        for file_name in rel_names[0:-1]:
935
936
            if file_name == '':
936
 
                raise errors.BzrCommandError(gettext("can not copy root of branch"))
 
937
                raise errors.BzrCommandError(
 
938
                    gettext("can not copy root of branch"))
937
939
        self.add_cleanup(tree.lock_tree_write().unlock)
938
940
        into_existing = osutils.isdir(names_list[-1])
939
941
        if not into_existing:
953
955
                src_kind = tree.stored_kind(src)
954
956
            except errors.NoSuchFile:
955
957
                raise errors.BzrCommandError(
956
 
                        gettext('Could not copy %s => %s: %s is not versioned.')
957
 
                        % (src, dst, src))
 
958
                    gettext('Could not copy %s => %s: %s is not versioned.')
 
959
                    % (src, dst, src))
958
960
            if src_kind is None:
959
961
                raise errors.BzrCommandError(
960
962
                    gettext('Could not copy %s => %s . %s is not versioned\\.'
961
 
                        % (src, dst, src)))
 
963
                            % (src, dst, src)))
962
964
            if src_kind == 'directory':
963
965
                raise errors.BzrCommandError(
964
966
                    gettext('Could not copy %s => %s . %s is a directory.'
965
 
                        % (src, dst, src)))
 
967
                            % (src, dst, src)))
966
968
            dst_parent = osutils.split(dst)[0]
967
969
            if dst_parent != '':
968
970
                try:
969
971
                    dst_parent_kind = tree.stored_kind(dst_parent)
970
972
                except errors.NoSuchFile:
971
973
                    raise errors.BzrCommandError(
972
 
                            gettext('Could not copy %s => %s: %s is not versioned.')
973
 
                            % (src, dst, dst_parent))
 
974
                        gettext('Could not copy %s => %s: %s is not versioned.')
 
975
                        % (src, dst, dst_parent))
974
976
                if dst_parent_kind != 'directory':
975
977
                    raise errors.BzrCommandError(
976
 
                            gettext('Could not copy to %s: %s is not a directory.')
977
 
                            % (dst_parent, dst_parent))
 
978
                        gettext('Could not copy to %s: %s is not a directory.')
 
979
                        % (dst_parent, dst_parent))
978
980
 
979
981
            tree.copy_one(src, dst)
980
982
 
1002
1004
 
1003
1005
    takes_args = ['names*']
1004
1006
    takes_options = [Option("after", help="Move only the brz identifier"
1005
 
        " of the file, because the file has already been moved."),
1006
 
        Option('auto', help='Automatically guess renames.'),
1007
 
        Option('dry-run', help='Avoid making changes when guessing renames.'),
1008
 
        ]
 
1007
                            " of the file, because the file has already been moved."),
 
1008
                     Option('auto', help='Automatically guess renames.'),
 
1009
                     Option(
 
1010
                         'dry-run', help='Avoid making changes when guessing renames.'),
 
1011
                     ]
1009
1012
    aliases = ['move', 'rename']
1010
1013
    encoding_type = 'replace'
1011
1014
 
1018
1021
            names_list = []
1019
1022
        if len(names_list) < 2:
1020
1023
            raise errors.BzrCommandError(gettext("missing file argument"))
1021
 
        tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
 
1024
        tree, rel_names = WorkingTree.open_containing_paths(
 
1025
            names_list, canonicalize=False)
1022
1026
        for file_name in rel_names[0:-1]:
1023
1027
            if file_name == '':
1024
 
                raise errors.BzrCommandError(gettext("can not move root of branch"))
 
1028
                raise errors.BzrCommandError(
 
1029
                    gettext("can not move root of branch"))
1025
1030
        self.add_cleanup(tree.lock_tree_write().unlock)
1026
1031
        self._run(tree, names_list, rel_names, after)
1027
1032
 
1028
1033
    def run_auto(self, names_list, after, dry_run):
1029
1034
        if names_list is not None and len(names_list) > 1:
1030
1035
            raise errors.BzrCommandError(gettext('Only one path may be specified to'
1031
 
                                         ' --auto.'))
 
1036
                                                 ' --auto.'))
1032
1037
        if after:
1033
1038
            raise errors.BzrCommandError(gettext('--after cannot be specified with'
1034
 
                                         ' --auto.'))
 
1039
                                                 ' --auto.'))
1035
1040
        work_tree, file_list = WorkingTree.open_containing_paths(
1036
1041
            names_list, default_directory='.')
1037
1042
        self.add_cleanup(work_tree.lock_tree_write().unlock)
1038
1043
        rename_map.RenameMap.guess_renames(
1039
 
                work_tree.basis_tree(), work_tree, dry_run)
 
1044
            work_tree.basis_tree(), work_tree, dry_run)
1040
1045
 
1041
1046
    def _run(self, tree, names_list, rel_names, after):
1042
1047
        into_existing = osutils.isdir(names_list[-1])
1047
1052
            #    a directory, but now doesn't exist in the working tree
1048
1053
            #    and the target is an existing directory, just rename it)
1049
1054
            if (not tree.case_sensitive
1050
 
                and rel_names[0].lower() == rel_names[1].lower()):
 
1055
                    and rel_names[0].lower() == rel_names[1].lower()):
1051
1056
                into_existing = False
1052
1057
            else:
1053
1058
                # 'fix' the case of a potential 'from'
1054
1059
                from_path = tree.get_canonical_path(rel_names[0])
1055
1060
                if (not osutils.lexists(names_list[0]) and
1056
1061
                    tree.is_versioned(from_path) and
1057
 
                    tree.stored_kind(from_path) == "directory"):
 
1062
                        tree.stored_kind(from_path) == "directory"):
1058
1063
                    into_existing = False
1059
1064
        # move/rename
1060
1065
        if into_existing:
1068
1073
        else:
1069
1074
            if len(names_list) != 2:
1070
1075
                raise errors.BzrCommandError(gettext('to mv multiple files the'
1071
 
                                             ' destination must be a versioned'
1072
 
                                             ' directory'))
 
1076
                                                     ' destination must be a versioned'
 
1077
                                                     ' directory'))
1073
1078
 
1074
1079
            # for cicp file-systems: the src references an existing inventory
1075
1080
            # item:
1096
1101
                if after:
1097
1102
                    # If 'after' is specified, the tail must refer to a file on disk.
1098
1103
                    if dest_parent:
1099
 
                        dest_parent_fq = osutils.pathjoin(tree.basedir, dest_parent)
 
1104
                        dest_parent_fq = osutils.pathjoin(
 
1105
                            tree.basedir, dest_parent)
1100
1106
                    else:
1101
1107
                        # pathjoin with an empty tail adds a slash, which breaks
1102
1108
                        # relpath :(
1103
1109
                        dest_parent_fq = tree.basedir
1104
1110
 
1105
1111
                    dest_tail = osutils.canonical_relpath(
1106
 
                                    dest_parent_fq,
1107
 
                                    osutils.pathjoin(dest_parent_fq, spec_tail))
 
1112
                        dest_parent_fq,
 
1113
                        osutils.pathjoin(dest_parent_fq, spec_tail))
1108
1114
                else:
1109
1115
                    # not 'after', so case as specified is used
1110
1116
                    dest_tail = spec_tail
1150
1156
 
1151
1157
    _see_also = ['push', 'update', 'status-flags', 'send']
1152
1158
    takes_options = ['remember', 'overwrite', 'revision',
1153
 
        custom_help('verbose',
1154
 
            help='Show logs of pulled revisions.'),
1155
 
        custom_help('directory',
1156
 
            help='Branch to pull into, '
1157
 
                 'rather than the one containing the working directory.'),
1158
 
        Option('local',
1159
 
            help="Perform a local pull in a bound "
1160
 
                 "branch.  Local pulls are not applied to "
1161
 
                 "the master branch."
1162
 
            ),
1163
 
        Option('show-base',
1164
 
            help="Show base revision text in conflicts."),
1165
 
        Option('overwrite-tags',
1166
 
            help="Overwrite tags only."),
1167
 
        ]
 
1159
                     custom_help('verbose',
 
1160
                                 help='Show logs of pulled revisions.'),
 
1161
                     custom_help('directory',
 
1162
                                 help='Branch to pull into, '
 
1163
                                 'rather than the one containing the working directory.'),
 
1164
                     Option('local',
 
1165
                            help="Perform a local pull in a bound "
 
1166
                            "branch.  Local pulls are not applied to "
 
1167
                            "the master branch."
 
1168
                            ),
 
1169
                     Option('show-base',
 
1170
                            help="Show base revision text in conflicts."),
 
1171
                     Option('overwrite-tags',
 
1172
                            help="Overwrite tags only."),
 
1173
                     ]
1168
1174
    takes_args = ['location?']
1169
1175
    encoding_type = 'replace'
1170
1176
 
1202
1208
        if location is not None:
1203
1209
            try:
1204
1210
                mergeable = bundle.read_mergeable_from_url(location,
1205
 
                    possible_transports=possible_transports)
 
1211
                                                           possible_transports=possible_transports)
1206
1212
            except errors.NotABundle:
1207
1213
                mergeable = None
1208
1214
 
1210
1216
        if location is None:
1211
1217
            if stored_loc is None:
1212
1218
                raise errors.BzrCommandError(gettext("No pull location known or"
1213
 
                                             " specified."))
 
1219
                                                     " specified."))
1214
1220
            else:
1215
1221
                display_url = urlutils.unescape_for_display(stored_loc,
1216
 
                        self.outf.encoding)
 
1222
                                                            self.outf.encoding)
1217
1223
                if not is_quiet():
1218
 
                    self.outf.write(gettext("Using saved parent location: %s\n") % display_url)
 
1224
                    self.outf.write(
 
1225
                        gettext("Using saved parent location: %s\n") % display_url)
1219
1226
                location = stored_loc
1220
1227
 
1221
1228
        revision = _get_one_revision('pull', revision)
1229
1236
            branch_from = branch_to
1230
1237
        else:
1231
1238
            branch_from = Branch.open(location,
1232
 
                possible_transports=possible_transports)
 
1239
                                      possible_transports=possible_transports)
1233
1240
            self.add_cleanup(branch_from.lock_read().unlock)
1234
1241
            # Remembers if asked explicitly or no previous location is set
1235
1242
            if (remember
1236
 
                or (remember is None and branch_to.get_parent() is None)):
 
1243
                    or (remember is None and branch_to.get_parent() is None)):
1237
1244
                # FIXME: This shouldn't be done before the pull
1238
1245
                # succeeds... -- vila 2012-01-02
1239
1246
                branch_to.set_parent(branch_from.base)
1296
1303
 
1297
1304
    _see_also = ['pull', 'update', 'working-trees']
1298
1305
    takes_options = ['remember', 'overwrite', 'verbose', 'revision',
1299
 
        Option('create-prefix',
1300
 
               help='Create the path leading up to the branch '
1301
 
                    'if it does not already exist.'),
1302
 
        custom_help('directory',
1303
 
            help='Branch to push from, '
1304
 
                 'rather than the one containing the working directory.'),
1305
 
        Option('use-existing-dir',
1306
 
               help='By default push will fail if the target'
1307
 
                    ' directory exists, but does not already'
1308
 
                    ' have a control directory.  This flag will'
1309
 
                    ' allow push to proceed.'),
1310
 
        Option('stacked',
1311
 
            help='Create a stacked branch that references the public location '
1312
 
                'of the parent branch.'),
1313
 
        Option('stacked-on',
1314
 
            help='Create a stacked branch that refers to another branch '
1315
 
                'for the commit history. Only the work not present in the '
1316
 
                'referenced branch is included in the branch created.',
1317
 
            type=text_type),
1318
 
        Option('strict',
1319
 
               help='Refuse to push if there are uncommitted changes in'
1320
 
               ' the working tree, --no-strict disables the check.'),
1321
 
        Option('no-tree',
1322
 
               help="Don't populate the working tree, even for protocols"
1323
 
               " that support it."),
1324
 
        Option('overwrite-tags',
1325
 
              help="Overwrite tags only."),
1326
 
        Option('lossy', help="Allow lossy push, i.e. dropping metadata "
1327
 
                             "that can't be represented in the target.")
1328
 
        ]
 
1306
                     Option('create-prefix',
 
1307
                            help='Create the path leading up to the branch '
 
1308
                            'if it does not already exist.'),
 
1309
                     custom_help('directory',
 
1310
                                 help='Branch to push from, '
 
1311
                                 'rather than the one containing the working directory.'),
 
1312
                     Option('use-existing-dir',
 
1313
                            help='By default push will fail if the target'
 
1314
                            ' directory exists, but does not already'
 
1315
                            ' have a control directory.  This flag will'
 
1316
                            ' allow push to proceed.'),
 
1317
                     Option('stacked',
 
1318
                            help='Create a stacked branch that references the public location '
 
1319
                            'of the parent branch.'),
 
1320
                     Option('stacked-on',
 
1321
                            help='Create a stacked branch that refers to another branch '
 
1322
                            'for the commit history. Only the work not present in the '
 
1323
                            'referenced branch is included in the branch created.',
 
1324
                            type=text_type),
 
1325
                     Option('strict',
 
1326
                            help='Refuse to push if there are uncommitted changes in'
 
1327
                            ' the working tree, --no-strict disables the check.'),
 
1328
                     Option('no-tree',
 
1329
                            help="Don't populate the working tree, even for protocols"
 
1330
                            " that support it."),
 
1331
                     Option('overwrite-tags',
 
1332
                            help="Overwrite tags only."),
 
1333
                     Option('lossy', help="Allow lossy push, i.e. dropping metadata "
 
1334
                            "that can't be represented in the target.")
 
1335
                     ]
1329
1336
    takes_args = ['location?']
1330
1337
    encoding_type = 'replace'
1331
1338
 
1332
1339
    def run(self, location=None, remember=None, overwrite=False,
1333
 
        create_prefix=False, verbose=False, revision=None,
1334
 
        use_existing_dir=False, directory=None, stacked_on=None,
1335
 
        stacked=False, strict=None, no_tree=False,
1336
 
        overwrite_tags=False, lossy=False):
 
1340
            create_prefix=False, verbose=False, revision=None,
 
1341
            use_existing_dir=False, directory=None, stacked_on=None,
 
1342
            stacked=False, strict=None, no_tree=False,
 
1343
            overwrite_tags=False, lossy=False):
1337
1344
        from .push import _show_push_branch
1338
1345
 
1339
1346
        if overwrite:
1387
1394
                        "No push location known or specified. To push to the "
1388
1395
                        "parent branch (at %s), use 'brz push :parent'." %
1389
1396
                        urlutils.unescape_for_display(parent_loc,
1390
 
                            self.outf.encoding)))
 
1397
                                                      self.outf.encoding)))
1391
1398
                else:
1392
1399
                    raise errors.BzrCommandError(gettext(
1393
1400
                        "No push location known or specified."))
1394
1401
            else:
1395
1402
                display_url = urlutils.unescape_for_display(stored_loc,
1396
 
                        self.outf.encoding)
 
1403
                                                            self.outf.encoding)
1397
1404
                note(gettext("Using saved push location: %s") % display_url)
1398
1405
                location = stored_loc
1399
1406
 
1400
1407
        _show_push_branch(br_from, revision_id, location, self.outf,
1401
 
            verbose=verbose, overwrite=overwrite, remember=remember,
1402
 
            stacked_on=stacked_on, create_prefix=create_prefix,
1403
 
            use_existing_dir=use_existing_dir, no_tree=no_tree,
1404
 
            lossy=lossy)
 
1408
                          verbose=verbose, overwrite=overwrite, remember=remember,
 
1409
                          stacked_on=stacked_on, create_prefix=create_prefix,
 
1410
                          use_existing_dir=use_existing_dir, no_tree=no_tree,
 
1411
                          lossy=lossy)
1405
1412
 
1406
1413
 
1407
1414
class cmd_branch(Command):
1421
1428
    _see_also = ['checkout']
1422
1429
    takes_args = ['from_location', 'to_location?']
1423
1430
    takes_options = ['revision',
1424
 
        Option('hardlink', help='Hard-link working tree files where possible.'),
1425
 
        Option('files-from', type=text_type,
1426
 
               help="Get file contents from this tree."),
1427
 
        Option('no-tree',
1428
 
            help="Create a branch without a working-tree."),
1429
 
        Option('switch',
1430
 
            help="Switch the checkout in the current directory "
1431
 
                 "to the new branch."),
1432
 
        Option('stacked',
1433
 
            help='Create a stacked branch referring to the source branch. '
1434
 
                'The new branch will depend on the availability of the source '
1435
 
                'branch for all operations.'),
1436
 
        Option('standalone',
1437
 
               help='Do not use a shared repository, even if available.'),
1438
 
        Option('use-existing-dir',
1439
 
               help='By default branch will fail if the target'
1440
 
                    ' directory exists, but does not already'
1441
 
                    ' have a control directory.  This flag will'
1442
 
                    ' allow branch to proceed.'),
1443
 
        Option('bind',
1444
 
            help="Bind new branch to from location."),
1445
 
        ]
 
1431
                     Option(
 
1432
                         'hardlink', help='Hard-link working tree files where possible.'),
 
1433
                     Option('files-from', type=text_type,
 
1434
                            help="Get file contents from this tree."),
 
1435
                     Option('no-tree',
 
1436
                            help="Create a branch without a working-tree."),
 
1437
                     Option('switch',
 
1438
                            help="Switch the checkout in the current directory "
 
1439
                            "to the new branch."),
 
1440
                     Option('stacked',
 
1441
                            help='Create a stacked branch referring to the source branch. '
 
1442
                            'The new branch will depend on the availability of the source '
 
1443
                            'branch for all operations.'),
 
1444
                     Option('standalone',
 
1445
                            help='Do not use a shared repository, even if available.'),
 
1446
                     Option('use-existing-dir',
 
1447
                            help='By default branch will fail if the target'
 
1448
                            ' directory exists, but does not already'
 
1449
                            ' have a control directory.  This flag will'
 
1450
                            ' allow branch to proceed.'),
 
1451
                     Option('bind',
 
1452
                            help="Bind new branch to from location."),
 
1453
                     ]
1446
1454
 
1447
1455
    def run(self, from_location, to_location=None, revision=None,
1448
1456
            hardlink=False, stacked=False, standalone=False, no_tree=False,
1479
1487
            except errors.NotBranchError:
1480
1488
                if not use_existing_dir:
1481
1489
                    raise errors.BzrCommandError(gettext('Target directory "%s" '
1482
 
                        'already exists.') % to_location)
 
1490
                                                         'already exists.') % to_location)
1483
1491
                else:
1484
1492
                    to_dir = None
1485
1493
            else:
1525
1533
        # We therefore need a try/except here and not just 'if stacked:'
1526
1534
        try:
1527
1535
            note(gettext('Created new stacked branch referring to %s.') %
1528
 
                branch.get_stacked_on_url())
 
1536
                 branch.get_stacked_on_url())
1529
1537
        except (errors.NotStacked, _mod_branch.UnstackableBranchFormat,
1530
 
            errors.UnstackableRepositoryFormat) as e:
1531
 
            note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
 
1538
                errors.UnstackableRepositoryFormat) as e:
 
1539
            note(ngettext('Branched %d revision.',
 
1540
                          'Branched %d revisions.', branch.revno()) % branch.revno())
1532
1541
        if bind:
1533
1542
            # Bind to the parent
1534
1543
            parent_branch = Branch.open(from_location)
1539
1548
            wt, _ = WorkingTree.open_containing('.')
1540
1549
            _mod_switch.switch(wt.controldir, branch)
1541
1550
            note(gettext('Switched to branch: %s'),
1542
 
                urlutils.unescape_for_display(branch.base, 'utf-8'))
 
1551
                 urlutils.unescape_for_display(branch.base, 'utf-8'))
1543
1552
 
1544
1553
 
1545
1554
class cmd_branches(Command):
1551
1560
 
1552
1561
    takes_args = ['location?']
1553
1562
    takes_options = [
1554
 
                  Option('recursive', short_name='R',
1555
 
                         help='Recursively scan for branches rather than '
1556
 
                              'just looking in the specified location.')]
 
1563
        Option('recursive', short_name='R',
 
1564
               help='Recursively scan for branches rather than '
 
1565
               'just looking in the specified location.')]
1557
1566
 
1558
1567
    def run(self, location=".", recursive=False):
1559
1568
        if recursive:
1774
1783
        if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1775
1784
            revno = branch.revision_id_to_dotted_revno(revision_id)
1776
1785
            note(gettext("Tree is up to date at revision {0} of branch {1}"
1777
 
                        ).format('.'.join(map(str, revno)), branch_location))
 
1786
                         ).format('.'.join(map(str, revno)), branch_location))
1778
1787
            return 0
1779
1788
        view_info = _get_view_info_for_change_reporter(tree)
1780
1789
        change_reporter = delta._ChangeReporter(
1789
1798
                show_base=show_base)
1790
1799
        except errors.NoSuchRevision as e:
1791
1800
            raise errors.BzrCommandError(gettext(
1792
 
                                  "branch has no revision %s\n"
1793
 
                                  "brz update --revision only works"
1794
 
                                  " for a revision in the branch history")
1795
 
                                  % (e.revision))
 
1801
                "branch has no revision %s\n"
 
1802
                "brz update --revision only works"
 
1803
                " for a revision in the branch history")
 
1804
                % (e.revision))
1796
1805
        revno = tree.branch.revision_id_to_dotted_revno(
1797
1806
            _mod_revision.ensure_null(tree.last_revision()))
1798
1807
        note(gettext('Updated to revision {0} of branch {1}').format(
1800
1809
        parent_ids = tree.get_parent_ids()
1801
1810
        if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1802
1811
            note(gettext('Your local commits will now show as pending merges with '
1803
 
                 "'brz status', and can be committed with 'brz commit'."))
 
1812
                         "'brz status', and can be committed with 'brz commit'."))
1804
1813
        if conflicts != 0:
1805
1814
            return 1
1806
1815
        else:
1862
1871
    """
1863
1872
    takes_args = ['file*']
1864
1873
    takes_options = ['verbose',
1865
 
        Option('new', help='Only remove files that have never been committed.'),
1866
 
        RegistryOption.from_kwargs('file-deletion-strategy',
1867
 
            'The file deletion mode to be used.',
1868
 
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1869
 
            safe='Backup changed files (default).',
1870
 
            keep='Delete from brz but leave the working copy.',
1871
 
            no_backup='Don\'t backup changed files.'),
1872
 
        ]
 
1874
                     Option(
 
1875
                         'new', help='Only remove files that have never been committed.'),
 
1876
                     RegistryOption.from_kwargs('file-deletion-strategy',
 
1877
                                                'The file deletion mode to be used.',
 
1878
                                                title='Deletion Strategy', value_switches=True, enum_switch=False,
 
1879
                                                safe='Backup changed files (default).',
 
1880
                                                keep='Delete from brz but leave the working copy.',
 
1881
                                                no_backup='Don\'t backup changed files.'),
 
1882
                     ]
1873
1883
    aliases = ['rm', 'del']
1874
1884
    encoding_type = 'replace'
1875
1885
 
1876
1886
    def run(self, file_list, verbose=False, new=False,
1877
 
        file_deletion_strategy='safe'):
 
1887
            file_deletion_strategy='safe'):
1878
1888
 
1879
1889
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1880
1890
 
1886
1896
        # some such?
1887
1897
        if new:
1888
1898
            added = tree.changes_from(tree.basis_tree(),
1889
 
                specific_files=file_list).added
 
1899
                                      specific_files=file_list).added
1890
1900
            file_list = sorted([f[0] for f in added], reverse=True)
1891
1901
            if len(file_list) == 0:
1892
1902
                raise errors.BzrCommandError(gettext('No matching files.'))
1901
1911
            file_list = sorted(missing, reverse=True)
1902
1912
            file_deletion_strategy = 'keep'
1903
1913
        tree.remove(file_list, verbose=verbose, to_file=self.outf,
1904
 
            keep_files=file_deletion_strategy=='keep',
1905
 
            force=(file_deletion_strategy=='no-backup'))
 
1914
                    keep_files=file_deletion_strategy == 'keep',
 
1915
                    force=(file_deletion_strategy == 'no-backup'))
1906
1916
 
1907
1917
 
1908
1918
class cmd_file_id(Command):
1997
2007
        self.add_cleanup(branch.lock_read().unlock)
1998
2008
        graph = branch.repository.get_graph()
1999
2009
        history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
2000
 
            [_mod_revision.NULL_REVISION]))
 
2010
                                                    [_mod_revision.NULL_REVISION]))
2001
2011
        for revid in reversed(history):
2002
2012
            self.outf.write(revid)
2003
2013
            self.outf.write('\n')
2025
2035
        self.add_cleanup(b.repository.lock_read().unlock)
2026
2036
        graph = b.repository.get_graph()
2027
2037
        revisions = [revid for revid, parents in
2028
 
            graph.iter_ancestry([last_revision])]
 
2038
                     graph.iter_ancestry([last_revision])]
2029
2039
        for revision_id in reversed(revisions):
2030
2040
            if _mod_revision.is_null(revision_id):
2031
2041
                continue
2061
2071
        Option('create-prefix',
2062
2072
               help='Create the path leading up to the branch '
2063
2073
                    'if it does not already exist.'),
2064
 
         RegistryOption('format',
2065
 
                help='Specify a format for this branch. '
2066
 
                'See "help formats" for a full list.',
2067
 
                lazy_registry=('breezy.controldir', 'format_registry'),
2068
 
                converter=lambda name: controldir.format_registry.make_controldir(name),
2069
 
                value_switches=True,
2070
 
                title="Branch format",
2071
 
                ),
2072
 
         Option('append-revisions-only',
2073
 
                help='Never change revnos or the existing log.'
2074
 
                '  Append revisions to it only.'),
2075
 
         Option('no-tree',
2076
 
                'Create a branch without a working tree.')
2077
 
         ]
 
2074
        RegistryOption('format',
 
2075
                       help='Specify a format for this branch. '
 
2076
                       'See "help formats" for a full list.',
 
2077
                       lazy_registry=('breezy.controldir', 'format_registry'),
 
2078
                       converter=lambda name: controldir.format_registry.make_controldir(
 
2079
                            name),
 
2080
                       value_switches=True,
 
2081
                       title="Branch format",
 
2082
                       ),
 
2083
        Option('append-revisions-only',
 
2084
               help='Never change revnos or the existing log.'
 
2085
               '  Append revisions to it only.'),
 
2086
        Option('no-tree',
 
2087
               'Create a branch without a working tree.')
 
2088
        ]
 
2089
 
2078
2090
    def run(self, location=None, format=None, append_revisions_only=False,
2079
2091
            create_prefix=False, no_tree=False):
2080
2092
        if format is None:
2094
2106
        except errors.NoSuchFile:
2095
2107
            if not create_prefix:
2096
2108
                raise errors.BzrCommandError(gettext("Parent directory of %s"
2097
 
                    " does not exist."
2098
 
                    "\nYou may supply --create-prefix to create all"
2099
 
                    " leading parent directories.")
2100
 
                    % location)
 
2109
                                                     " does not exist."
 
2110
                                                     "\nYou may supply --create-prefix to create all"
 
2111
                                                     " leading parent directories.")
 
2112
                                             % location)
2101
2113
            to_transport.create_prefix()
2102
2114
 
2103
2115
        try:
2104
 
            a_controldir = controldir.ControlDir.open_from_transport(to_transport)
 
2116
            a_controldir = controldir.ControlDir.open_from_transport(
 
2117
                to_transport)
2105
2118
        except errors.NotBranchError:
2106
2119
            # really a NotBzrDir error...
2107
2120
            create_branch = controldir.ControlDir.create_branch_convenience
2117
2130
            from .transport.local import LocalTransport
2118
2131
            if a_controldir.has_branch():
2119
2132
                if (isinstance(to_transport, LocalTransport)
2120
 
                    and not a_controldir.has_workingtree()):
2121
 
                        raise errors.BranchExistsWithoutWorkingTree(location)
 
2133
                        and not a_controldir.has_workingtree()):
 
2134
                    raise errors.BranchExistsWithoutWorkingTree(location)
2122
2135
                raise errors.AlreadyBranchError(location)
2123
2136
            branch = a_controldir.create_branch()
2124
2137
            if not no_tree and not a_controldir.has_workingtree():
2128
2141
                branch.set_append_revisions_only(True)
2129
2142
            except errors.UpgradeRequired:
2130
2143
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
2131
 
                    ' to append-revisions-only.  Try --default.'))
 
2144
                                                     ' to append-revisions-only.  Try --default.'))
2132
2145
        if not is_quiet():
2133
2146
            from .info import describe_layout, describe_format
2134
2147
            try:
2139
2152
            layout = describe_layout(repository, branch, tree).lower()
2140
2153
            format = describe_format(a_controldir, repository, branch, tree)
2141
2154
            self.outf.write(gettext("Created a {0} (format: {1})\n").format(
2142
 
                  layout, format))
 
2155
                layout, format))
2143
2156
            if repository.is_shared():
2144
 
                #XXX: maybe this can be refactored into transport.path_or_url()
 
2157
                # XXX: maybe this can be refactored into transport.path_or_url()
2145
2158
                url = repository.controldir.root_transport.external_url()
2146
2159
                try:
2147
2160
                    url = urlutils.local_path_from_url(url)
2181
2194
    _see_also = ['init', 'branch', 'checkout', 'repositories']
2182
2195
    takes_args = ["location"]
2183
2196
    takes_options = [RegistryOption('format',
2184
 
                            help='Specify a format for this repository. See'
2185
 
                                 ' "brz help formats" for details.',
2186
 
                            lazy_registry=('breezy.controldir', 'format_registry'),
2187
 
                            converter=lambda name: controldir.format_registry.make_controldir(name),
2188
 
                            value_switches=True, title='Repository format'),
 
2197
                                    help='Specify a format for this repository. See'
 
2198
                                    ' "brz help formats" for details.',
 
2199
                                    lazy_registry=(
 
2200
                                        'breezy.controldir', 'format_registry'),
 
2201
                                    converter=lambda name: controldir.format_registry.make_controldir(
 
2202
                                        name),
 
2203
                                    value_switches=True, title='Repository format'),
2189
2204
                     Option('no-trees',
2190
 
                             help='Branches in the repository will default to'
2191
 
                                  ' not having a working tree.'),
2192
 
                    ]
 
2205
                            help='Branches in the repository will default to'
 
2206
                            ' not having a working tree.'),
 
2207
                     ]
2193
2208
    aliases = ["init-repo"]
2194
2209
 
2195
2210
    def run(self, location, format=None, no_trees=False):
2208
2223
 
2209
2224
        (repo, newdir, require_stacking, repository_policy) = (
2210
2225
            format.initialize_on_transport_ex(to_transport,
2211
 
            create_prefix=True, make_working_trees=not no_trees,
2212
 
            shared_repo=True, force_new_repo=True,
2213
 
            use_existing_dir=True,
2214
 
            repo_format_name=repo_format_name))
 
2226
                                              create_prefix=True, make_working_trees=not no_trees,
 
2227
                                              shared_repo=True, force_new_repo=True,
 
2228
                                              use_existing_dir=True,
 
2229
                                              repo_format_name=repo_format_name))
2215
2230
        if not is_quiet():
2216
2231
            from .info import show_bzrdir_info
2217
2232
            show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
2313
2328
               help='Set prefixes added to old and new filenames, as '
2314
2329
                    'two values separated by a colon. (eg "old/:new/").'),
2315
2330
        Option('old',
2316
 
            help='Branch/tree to compare from.',
2317
 
            type=text_type,
2318
 
            ),
 
2331
               help='Branch/tree to compare from.',
 
2332
               type=text_type,
 
2333
               ),
2319
2334
        Option('new',
2320
 
            help='Branch/tree to compare to.',
2321
 
            type=text_type,
2322
 
            ),
 
2335
               help='Branch/tree to compare to.',
 
2336
               type=text_type,
 
2337
               ),
2323
2338
        'revision',
2324
2339
        'change',
2325
2340
        Option('using',
2326
 
            help='Use this command to compare files.',
2327
 
            type=text_type,
2328
 
            ),
 
2341
               help='Use this command to compare files.',
 
2342
               type=text_type,
 
2343
               ),
2329
2344
        RegistryOption('format',
2330
 
            short_name='F',
2331
 
            help='Diff format to use.',
2332
 
            lazy_registry=('breezy.diff', 'format_registry'),
2333
 
            title='Diff format'),
 
2345
                       short_name='F',
 
2346
                       help='Diff format to use.',
 
2347
                       lazy_registry=('breezy.diff', 'format_registry'),
 
2348
                       title='Diff format'),
2334
2349
        Option('context',
2335
 
            help='How many lines of context to show.',
2336
 
            type=int,
2337
 
            ),
 
2350
               help='How many lines of context to show.',
 
2351
               type=int,
 
2352
               ),
2338
2353
        ]
2339
2354
    aliases = ['di', 'dif']
2340
2355
    encoding_type = 'exact'
2344
2359
            prefix=None, old=None, new=None, using=None, format=None,
2345
2360
            context=None):
2346
2361
        from .diff import (get_trees_and_branches_to_diff_locked,
2347
 
            show_diff_trees)
 
2362
                           show_diff_trees)
2348
2363
 
2349
2364
        if prefix == u'0':
2350
2365
            # diff -p0 format
2362
2377
 
2363
2378
        if revision and len(revision) > 2:
2364
2379
            raise errors.BzrCommandError(gettext('brz diff --revision takes exactly'
2365
 
                                         ' one or two revision specifiers'))
 
2380
                                                 ' one or two revision specifiers'))
2366
2381
 
2367
2382
        if using is not None and format is not None:
2368
2383
            raise errors.BzrCommandError(gettext(
2649
2664
    takes_args = ['file*']
2650
2665
    _see_also = ['log-formats', 'revisionspec']
2651
2666
    takes_options = [
2652
 
            Option('forward',
2653
 
                   help='Show from oldest to newest.'),
2654
 
            'timezone',
2655
 
            custom_help('verbose',
2656
 
                   help='Show files changed in each revision.'),
2657
 
            'show-ids',
2658
 
            'revision',
2659
 
            Option('change',
2660
 
                   type=breezy.option._parse_revision_str,
2661
 
                   short_name='c',
2662
 
                   help='Show just the specified revision.'
2663
 
                   ' See also "help revisionspec".'),
2664
 
            'log-format',
2665
 
            RegistryOption('authors',
2666
 
                'What names to list as authors - first, all or committer.',
2667
 
                title='Authors',
2668
 
                lazy_registry=('breezy.log', 'author_list_registry'),
2669
 
            ),
2670
 
            Option('levels',
2671
 
                   short_name='n',
2672
 
                   help='Number of levels to display - 0 for all, 1 for flat.',
2673
 
                   argname='N',
2674
 
                   type=_parse_levels),
2675
 
            Option('message',
2676
 
                   help='Show revisions whose message matches this '
2677
 
                        'regular expression.',
2678
 
                   type=text_type,
2679
 
                   hidden=True),
2680
 
            Option('limit',
2681
 
                   short_name='l',
2682
 
                   help='Limit the output to the first N revisions.',
2683
 
                   argname='N',
2684
 
                   type=_parse_limit),
2685
 
            Option('show-diff',
2686
 
                   short_name='p',
2687
 
                   help='Show changes made in each revision as a patch.'),
2688
 
            Option('include-merged',
2689
 
                   help='Show merged revisions like --levels 0 does.'),
2690
 
            Option('include-merges', hidden=True,
2691
 
                   help='Historical alias for --include-merged.'),
2692
 
            Option('omit-merges',
2693
 
                   help='Do not report commits with more than one parent.'),
2694
 
            Option('exclude-common-ancestry',
2695
 
                   help='Display only the revisions that are not part'
2696
 
                   ' of both ancestries (require -rX..Y).'
2697
 
                   ),
2698
 
            Option('signatures',
2699
 
                   help='Show digital signature validity.'),
2700
 
            ListOption('match',
2701
 
                short_name='m',
2702
 
                help='Show revisions whose properties match this '
2703
 
                'expression.',
2704
 
                type=text_type),
2705
 
            ListOption('match-message',
2706
 
                   help='Show revisions whose message matches this '
2707
 
                   'expression.',
2708
 
                type=text_type),
2709
 
            ListOption('match-committer',
 
2667
        Option('forward',
 
2668
               help='Show from oldest to newest.'),
 
2669
        'timezone',
 
2670
        custom_help('verbose',
 
2671
                    help='Show files changed in each revision.'),
 
2672
        'show-ids',
 
2673
        'revision',
 
2674
        Option('change',
 
2675
               type=breezy.option._parse_revision_str,
 
2676
               short_name='c',
 
2677
               help='Show just the specified revision.'
 
2678
               ' See also "help revisionspec".'),
 
2679
        'log-format',
 
2680
        RegistryOption('authors',
 
2681
                       'What names to list as authors - first, all or committer.',
 
2682
                       title='Authors',
 
2683
                       lazy_registry=(
 
2684
                           'breezy.log', 'author_list_registry'),
 
2685
                       ),
 
2686
        Option('levels',
 
2687
               short_name='n',
 
2688
               help='Number of levels to display - 0 for all, 1 for flat.',
 
2689
               argname='N',
 
2690
               type=_parse_levels),
 
2691
        Option('message',
 
2692
               help='Show revisions whose message matches this '
 
2693
               'regular expression.',
 
2694
               type=text_type,
 
2695
               hidden=True),
 
2696
        Option('limit',
 
2697
               short_name='l',
 
2698
               help='Limit the output to the first N revisions.',
 
2699
               argname='N',
 
2700
               type=_parse_limit),
 
2701
        Option('show-diff',
 
2702
               short_name='p',
 
2703
               help='Show changes made in each revision as a patch.'),
 
2704
        Option('include-merged',
 
2705
               help='Show merged revisions like --levels 0 does.'),
 
2706
        Option('include-merges', hidden=True,
 
2707
               help='Historical alias for --include-merged.'),
 
2708
        Option('omit-merges',
 
2709
               help='Do not report commits with more than one parent.'),
 
2710
        Option('exclude-common-ancestry',
 
2711
               help='Display only the revisions that are not part'
 
2712
               ' of both ancestries (require -rX..Y).'
 
2713
               ),
 
2714
        Option('signatures',
 
2715
               help='Show digital signature validity.'),
 
2716
        ListOption('match',
 
2717
                   short_name='m',
 
2718
                   help='Show revisions whose properties match this '
 
2719
                   'expression.',
 
2720
                   type=text_type),
 
2721
        ListOption('match-message',
 
2722
                   help='Show revisions whose message matches this '
 
2723
                   'expression.',
 
2724
                   type=text_type),
 
2725
        ListOption('match-committer',
2710
2726
                   help='Show revisions whose committer matches this '
2711
2727
                   'expression.',
2712
 
                type=text_type),
2713
 
            ListOption('match-author',
 
2728
                   type=text_type),
 
2729
        ListOption('match-author',
2714
2730
                   help='Show revisions whose authors match this '
2715
2731
                   'expression.',
2716
 
                type=text_type),
2717
 
            ListOption('match-bugs',
 
2732
                   type=text_type),
 
2733
        ListOption('match-bugs',
2718
2734
                   help='Show revisions whose bugs match this '
2719
2735
                   'expression.',
2720
 
                type=text_type)
2721
 
            ]
 
2736
                   type=text_type)
 
2737
        ]
2722
2738
    encoding_type = 'replace'
2723
2739
 
2724
2740
    @display_command
2753
2769
        if include_merged is None:
2754
2770
            include_merged = False
2755
2771
        if (exclude_common_ancestry
2756
 
            and (revision is None or len(revision) != 2)):
 
2772
                and (revision is None or len(revision) != 2)):
2757
2773
            raise errors.BzrCommandError(gettext(
2758
2774
                '--exclude-common-ancestry requires -r with two revisions'))
2759
2775
        if include_merged:
2830
2846
        if log_format is None:
2831
2847
            log_format = log.log_formatter_registry.get_default(b)
2832
2848
        # Make a non-encoding output to include the diffs - bug 328007
2833
 
        unencoded_output = ui.ui_factory.make_output_stream(encoding_type='exact')
 
2849
        unencoded_output = ui.ui_factory.make_output_stream(
 
2850
            encoding_type='exact')
2834
2851
        lf = log_format(show_ids=show_ids, to_file=self.outf,
2835
2852
                        to_exact_file=unencoded_output,
2836
2853
                        show_timezone=timezone,
2853
2870
        # file that isn't a directory without showing a delta" case.
2854
2871
        partial_history = revision and b.repository._format.supports_chks
2855
2872
        match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2856
 
            or delta_type or partial_history)
 
2873
                              or delta_type or partial_history)
2857
2874
 
2858
2875
        match_dict = {}
2859
2876
        if match:
2955
2972
        tree, relpath = WorkingTree.open_containing(filename)
2956
2973
        with tree.lock_read():
2957
2974
            touching_revs = log.find_touching_revisions(
2958
 
                    tree.branch.repository, tree.branch.last_revision(), tree, relpath)
 
2975
                tree.branch.repository, tree.branch.last_revision(), tree, relpath)
2959
2976
            for revno, revision_id, what in reversed(list(touching_revs)):
2960
2977
                self.outf.write("%6d %s\n" % (revno, what))
2961
2978
 
2967
2984
    _see_also = ['status', 'cat']
2968
2985
    takes_args = ['path?']
2969
2986
    takes_options = [
2970
 
            'verbose',
2971
 
            'revision',
2972
 
            Option('recursive', short_name='R',
2973
 
                   help='Recurse into subdirectories.'),
2974
 
            Option('from-root',
2975
 
                   help='Print paths relative to the root of the branch.'),
2976
 
            Option('unknown', short_name='u',
2977
 
                help='Print unknown files.'),
2978
 
            Option('versioned', help='Print versioned files.',
2979
 
                   short_name='V'),
2980
 
            Option('ignored', short_name='i',
2981
 
                help='Print ignored files.'),
2982
 
            Option('kind', short_name='k',
2983
 
                   help=('List entries of a particular kind: file, '
2984
 
                         'directory, symlink, tree-reference.'),
2985
 
                   type=text_type),
2986
 
            'null',
2987
 
            'show-ids',
2988
 
            'directory',
2989
 
            ]
 
2987
        'verbose',
 
2988
        'revision',
 
2989
        Option('recursive', short_name='R',
 
2990
               help='Recurse into subdirectories.'),
 
2991
        Option('from-root',
 
2992
               help='Print paths relative to the root of the branch.'),
 
2993
        Option('unknown', short_name='u',
 
2994
               help='Print unknown files.'),
 
2995
        Option('versioned', help='Print versioned files.',
 
2996
               short_name='V'),
 
2997
        Option('ignored', short_name='i',
 
2998
               help='Print ignored files.'),
 
2999
        Option('kind', short_name='k',
 
3000
               help=('List entries of a particular kind: file, '
 
3001
                     'directory, symlink, tree-reference.'),
 
3002
               type=text_type),
 
3003
        'null',
 
3004
        'show-ids',
 
3005
        'directory',
 
3006
        ]
 
3007
 
2990
3008
    @display_command
2991
3009
    def run(self, revision=None, verbose=False,
2992
3010
            recursive=False, from_root=False,
2997
3015
            raise errors.BzrCommandError(gettext('invalid kind specified'))
2998
3016
 
2999
3017
        if verbose and null:
3000
 
            raise errors.BzrCommandError(gettext('Cannot set both --verbose and --null'))
 
3018
            raise errors.BzrCommandError(
 
3019
                gettext('Cannot set both --verbose and --null'))
3001
3020
        all = not (unknown or versioned or ignored)
3002
3021
 
3003
 
        selection = {'I':ignored, '?':unknown, 'V':versioned}
 
3022
        selection = {'I': ignored, '?': unknown, 'V': versioned}
3004
3023
 
3005
3024
        if path is None:
3006
3025
            fs_path = '.'
3007
3026
        else:
3008
3027
            if from_root:
3009
3028
                raise errors.BzrCommandError(gettext('cannot specify both --from-root'
3010
 
                                             ' and PATH'))
 
3029
                                                     ' and PATH'))
3011
3030
            fs_path = path
3012
3031
        tree, branch, relpath = \
3013
3032
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
3033
3052
 
3034
3053
        self.add_cleanup(tree.lock_read().unlock)
3035
3054
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
3036
 
            from_dir=relpath, recursive=recursive):
 
3055
                                                         from_dir=relpath, recursive=recursive):
3037
3056
            # Apply additional masking
3038
3057
            if not all and not selection[fc]:
3039
3058
                continue
3169
3188
    _see_also = ['status', 'ignored', 'patterns']
3170
3189
    takes_args = ['name_pattern*']
3171
3190
    takes_options = ['directory',
3172
 
        Option('default-rules',
3173
 
               help='Display the default ignore rules that brz uses.')
3174
 
        ]
 
3191
                     Option('default-rules',
 
3192
                            help='Display the default ignore rules that brz uses.')
 
3193
                     ]
3175
3194
 
3176
3195
    def run(self, name_pattern_list=None, default_rules=None,
3177
3196
            directory=u'.'):
3183
3202
            return
3184
3203
        if not name_pattern_list:
3185
3204
            raise errors.BzrCommandError(gettext("ignore requires at least one "
3186
 
                "NAME_PATTERN or --default-rules."))
 
3205
                                                 "NAME_PATTERN or --default-rules."))
3187
3206
        name_pattern_list = [globbing.normalize_pattern(p)
3188
3207
                             for p in name_pattern_list]
3189
3208
        bad_patterns = ''
3200
3219
            raise lazy_regex.InvalidPattern('')
3201
3220
        for name_pattern in name_pattern_list:
3202
3221
            if (name_pattern[0] == '/' or
3203
 
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
 
3222
                    (len(name_pattern) > 1 and name_pattern[1] == ':')):
3204
3223
                raise errors.BzrCommandError(gettext(
3205
3224
                    "NAME_PATTERN should not be an absolute path"))
3206
3225
        tree, relpath = WorkingTree.open_containing(directory)
3216
3235
                    matches.append(filename)
3217
3236
        if len(matches) > 0:
3218
3237
            self.outf.write(gettext("Warning: the following files are version "
3219
 
                  "controlled and match your ignore pattern:\n%s"
3220
 
                  "\nThese files will continue to be version controlled"
3221
 
                  " unless you 'brz remove' them.\n") % ("\n".join(matches),))
 
3238
                                    "controlled and match your ignore pattern:\n%s"
 
3239
                                    "\nThese files will continue to be version controlled"
 
3240
                                    " unless you 'brz remove' them.\n") % ("\n".join(matches),))
3222
3241
 
3223
3242
 
3224
3243
class cmd_ignored(Command):
3243
3262
        for path, file_class, kind, file_id, entry in tree.list_files():
3244
3263
            if file_class != 'I':
3245
3264
                continue
3246
 
            ## XXX: Slightly inefficient since this was already calculated
 
3265
            # XXX: Slightly inefficient since this was already calculated
3247
3266
            pat = tree.is_ignored(path)
3248
3267
            self.outf.write('%-50s %s\n' % (path, pat))
3249
3268
 
3265
3284
        except ValueError:
3266
3285
            raise errors.BzrCommandError(gettext("not a valid revision-number: %r")
3267
3286
                                         % revno)
3268
 
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
 
3287
        revid = WorkingTree.open_containing(
 
3288
            directory)[0].branch.get_rev_id(revno)
3269
3289
        self.outf.write("%s\n" % revid.decode('utf-8'))
3270
3290
 
3271
3291
 
3301
3321
    encoding_type = 'exact'
3302
3322
    takes_args = ['dest', 'branch_or_subdir?']
3303
3323
    takes_options = ['directory',
3304
 
        Option('format',
3305
 
               help="Type of file to export to.",
3306
 
               type=text_type),
3307
 
        'revision',
3308
 
        Option('filters', help='Apply content filters to export the '
3309
 
                'convenient form.'),
3310
 
        Option('root',
3311
 
               type=text_type,
3312
 
               help="Name of the root directory inside the exported file."),
3313
 
        Option('per-file-timestamps',
3314
 
               help='Set modification time of files to that of the last '
3315
 
                    'revision in which it was changed.'),
3316
 
        Option('uncommitted',
3317
 
               help='Export the working tree contents rather than that of the '
3318
 
                    'last revision.'),
3319
 
        ]
 
3324
                     Option('format',
 
3325
                            help="Type of file to export to.",
 
3326
                            type=text_type),
 
3327
                     'revision',
 
3328
                     Option('filters', help='Apply content filters to export the '
 
3329
                            'convenient form.'),
 
3330
                     Option('root',
 
3331
                            type=text_type,
 
3332
                            help="Name of the root directory inside the exported file."),
 
3333
                     Option('per-file-timestamps',
 
3334
                            help='Set modification time of files to that of the last '
 
3335
                            'revision in which it was changed.'),
 
3336
                     Option('uncommitted',
 
3337
                            help='Export the working tree contents rather than that of the '
 
3338
                            'last revision.'),
 
3339
                     ]
3320
3340
 
3321
3341
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
3322
 
        root=None, filters=False, per_file_timestamps=False, uncommitted=False,
3323
 
        directory=u'.'):
 
3342
            root=None, filters=False, per_file_timestamps=False, uncommitted=False,
 
3343
            directory=u'.'):
3324
3344
        from .export import export, guess_format, get_root_name
3325
3345
 
3326
3346
        if branch_or_subdir is None:
3338
3358
            export_tree = tree
3339
3359
        else:
3340
3360
            export_tree = _get_one_revision_tree(
3341
 
                    'export', revision, branch=b,
3342
 
                    tree=tree)
 
3361
                'export', revision, branch=b,
 
3362
                tree=tree)
3343
3363
 
3344
3364
        if format is None:
3345
3365
            format = guess_format(dest)
3355
3375
        if filters:
3356
3376
            from breezy.filter_tree import ContentFilterTree
3357
3377
            export_tree = ContentFilterTree(
3358
 
                    export_tree, export_tree._content_filter_stack)
 
3378
                export_tree, export_tree._content_filter_stack)
3359
3379
 
3360
3380
        try:
3361
3381
            export(export_tree, dest, format, root, subdir,
3376
3396
 
3377
3397
    _see_also = ['ls']
3378
3398
    takes_options = ['directory',
3379
 
        Option('name-from-revision', help='The path name in the old tree.'),
3380
 
        Option('filters', help='Apply content filters to display the '
3381
 
                'convenience form.'),
3382
 
        'revision',
3383
 
        ]
 
3399
                     Option('name-from-revision',
 
3400
                            help='The path name in the old tree.'),
 
3401
                     Option('filters', help='Apply content filters to display the '
 
3402
                            'convenience form.'),
 
3403
                     'revision',
 
3404
                     ]
3384
3405
    takes_args = ['filename']
3385
3406
    encoding_type = 'exact'
3386
3407
 
3389
3410
            filters=False, directory=None):
3390
3411
        if revision is not None and len(revision) != 1:
3391
3412
            raise errors.BzrCommandError(gettext("brz cat --revision takes exactly"
3392
 
                                         " one revision specifier"))
 
3413
                                                 " one revision specifier"))
3393
3414
        tree, branch, relpath = \
3394
3415
            _open_directory_or_containing_tree_or_branch(filename, directory)
3395
3416
        self.add_cleanup(branch.lock_read().unlock)
3397
3418
                         name_from_revision, filters)
3398
3419
 
3399
3420
    def _run(self, tree, b, relpath, filename, revision, name_from_revision,
3400
 
        filtered):
 
3421
             filtered):
3401
3422
        import shutil
3402
3423
        if tree is None:
3403
3424
            tree = b.basis_tree()
3432
3453
        if filtered:
3433
3454
            from .filter_tree import ContentFilterTree
3434
3455
            filter_tree = ContentFilterTree(rev_tree,
3435
 
                rev_tree._content_filter_stack)
 
3456
                                            rev_tree._content_filter_stack)
3436
3457
            fileobj = filter_tree.get_file(relpath, actual_file_id)
3437
3458
        else:
3438
3459
            fileobj = rev_tree.get_file(relpath, actual_file_id)
3449
3470
        self.outf.write("%s\n" % osutils.local_time_offset())
3450
3471
 
3451
3472
 
3452
 
 
3453
3473
class cmd_commit(Command):
3454
3474
    __doc__ = """Commit changes into a new revision.
3455
3475
 
3510
3530
    _see_also = ['add', 'bugs', 'hooks', 'uncommit']
3511
3531
    takes_args = ['selected*']
3512
3532
    takes_options = [
3513
 
            ListOption('exclude', type=text_type, short_name='x',
3514
 
                help="Do not consider changes made to a given path."),
3515
 
            Option('message', type=text_type,
3516
 
                   short_name='m',
3517
 
                   help="Description of the new revision."),
3518
 
            'verbose',
3519
 
             Option('unchanged',
3520
 
                    help='Commit even if nothing has changed.'),
3521
 
             Option('file', type=text_type,
3522
 
                    short_name='F',
3523
 
                    argname='msgfile',
3524
 
                    help='Take commit message from this file.'),
3525
 
             Option('strict',
3526
 
                    help="Refuse to commit if there are unknown "
3527
 
                    "files in the working tree."),
3528
 
             Option('commit-time', type=text_type,
3529
 
                    help="Manually set a commit time using commit date "
3530
 
                    "format, e.g. '2009-10-10 08:00:00 +0100'."),
3531
 
             ListOption('fixes', type=text_type,
3532
 
                    help="Mark a bug as being fixed by this revision "
3533
 
                         "(see \"brz help bugs\")."),
3534
 
             ListOption('author', type=text_type,
3535
 
                    help="Set the author's name, if it's different "
3536
 
                         "from the committer."),
3537
 
             Option('local',
3538
 
                    help="Perform a local commit in a bound "
3539
 
                         "branch.  Local commits are not pushed to "
3540
 
                         "the master branch until a normal commit "
3541
 
                         "is performed."
3542
 
                    ),
3543
 
             Option('show-diff', short_name='p',
3544
 
                    help='When no message is supplied, show the diff along'
3545
 
                    ' with the status summary in the message editor.'),
3546
 
             Option('lossy',
3547
 
                    help='When committing to a foreign version control '
3548
 
                    'system do not push data that can not be natively '
 
3533
        ListOption('exclude', type=text_type, short_name='x',
 
3534
                   help="Do not consider changes made to a given path."),
 
3535
        Option('message', type=text_type,
 
3536
               short_name='m',
 
3537
               help="Description of the new revision."),
 
3538
        'verbose',
 
3539
        Option('unchanged',
 
3540
               help='Commit even if nothing has changed.'),
 
3541
        Option('file', type=text_type,
 
3542
               short_name='F',
 
3543
               argname='msgfile',
 
3544
               help='Take commit message from this file.'),
 
3545
        Option('strict',
 
3546
               help="Refuse to commit if there are unknown "
 
3547
               "files in the working tree."),
 
3548
        Option('commit-time', type=text_type,
 
3549
               help="Manually set a commit time using commit date "
 
3550
               "format, e.g. '2009-10-10 08:00:00 +0100'."),
 
3551
        ListOption('fixes', type=text_type,
 
3552
                   help="Mark a bug as being fixed by this revision "
 
3553
                   "(see \"brz help bugs\")."),
 
3554
        ListOption('author', type=text_type,
 
3555
                   help="Set the author's name, if it's different "
 
3556
                   "from the committer."),
 
3557
        Option('local',
 
3558
               help="Perform a local commit in a bound "
 
3559
               "branch.  Local commits are not pushed to "
 
3560
               "the master branch until a normal commit "
 
3561
               "is performed."
 
3562
               ),
 
3563
        Option('show-diff', short_name='p',
 
3564
               help='When no message is supplied, show the diff along'
 
3565
               ' with the status summary in the message editor.'),
 
3566
        Option('lossy',
 
3567
               help='When committing to a foreign version control '
 
3568
               'system do not push data that can not be natively '
3549
3569
                    'represented.'),
3550
 
             ]
 
3570
        ]
3551
3571
    aliases = ['ci', 'checkin']
3552
3572
 
3553
3573
    def _iter_bug_fix_urls(self, fixes, branch):
3642
3662
                warning_msg = (
3643
3663
                    'The commit message is a file name: "%(f)s".\n'
3644
3664
                    '(use --file "%(f)s" to take commit message from that file)'
3645
 
                    % { 'f': message })
 
3665
                    % {'f': message})
3646
3666
                ui.ui_factory.show_warning(warning_msg)
3647
3667
            if '\r' in message:
3648
3668
                message = message.replace('\r\n', '\n')
3662
3682
                # No message supplied: make one up.
3663
3683
                # text is the status of the tree
3664
3684
                text = make_commit_message_template_encoded(tree,
3665
 
                        selected_list, diff=show_diff,
3666
 
                        output_encoding=osutils.get_user_encoding())
 
3685
                                                            selected_list, diff=show_diff,
 
3686
                                                            output_encoding=osutils.get_user_encoding())
3667
3687
                # start_message is the template generated from hooks
3668
3688
                # XXX: Warning - looks like hooks return unicode,
3669
3689
                # make_commit_message_template_encoded returns user encoding.
3671
3691
                # avoid this.
3672
3692
                my_message = set_commit_message(commit_obj)
3673
3693
                if my_message is None:
3674
 
                    start_message = generate_commit_message_template(commit_obj)
 
3694
                    start_message = generate_commit_message_template(
 
3695
                        commit_obj)
3675
3696
                    if start_message is not None:
3676
3697
                        start_message = start_message.encode(
3677
 
                                osutils.get_user_encoding())
 
3698
                            osutils.get_user_encoding())
3678
3699
                    my_message = edit_commit_message_encoded(text,
3679
 
                        start_message=start_message)
 
3700
                                                             start_message=start_message)
3680
3701
                if my_message is None:
3681
3702
                    raise errors.BzrCommandError(gettext("please specify a commit"
3682
 
                        " message with either --message or --file"))
 
3703
                                                         " message with either --message or --file"))
3683
3704
                if my_message == "":
3684
3705
                    raise errors.BzrCommandError(gettext("Empty commit message specified."
3685
 
                            " Please specify a commit message with either"
3686
 
                            " --message or --file or leave a blank message"
3687
 
                            " with --message \"\"."))
 
3706
                                                         " Please specify a commit message with either"
 
3707
                                                         " --message or --file or leave a blank message"
 
3708
                                                         " with --message \"\"."))
3688
3709
            return my_message
3689
3710
 
3690
3711
        # The API permits a commit with a filter of [] to mean 'select nothing'
3702
3723
                        lossy=lossy)
3703
3724
        except PointlessCommit:
3704
3725
            raise errors.BzrCommandError(gettext("No changes to commit."
3705
 
                " Please 'brz add' the files you want to commit, or use"
3706
 
                " --unchanged to force an empty commit."))
 
3726
                                                 " Please 'brz add' the files you want to commit, or use"
 
3727
                                                 " --unchanged to force an empty commit."))
3707
3728
        except ConflictsInTree:
3708
3729
            raise errors.BzrCommandError(gettext('Conflicts detected in working '
3709
 
                'tree.  Use "brz conflicts" to list, "brz resolve FILE" to'
3710
 
                ' resolve.'))
 
3730
                                                 'tree.  Use "brz conflicts" to list, "brz resolve FILE" to'
 
3731
                                                 ' resolve.'))
3711
3732
        except StrictCommitFailed:
3712
3733
            raise errors.BzrCommandError(gettext("Commit refused because there are"
3713
 
                              " unknown files in the working tree."))
 
3734
                                                 " unknown files in the working tree."))
3714
3735
        except errors.BoundBranchOutOfDate as e:
3715
3736
            e.extra_help = (gettext("\n"
3716
 
                'To commit to master branch, run update and then commit.\n'
3717
 
                'You can also pass --local to commit to continue working '
3718
 
                'disconnected.'))
 
3737
                                    'To commit to master branch, run update and then commit.\n'
 
3738
                                    'You can also pass --local to commit to continue working '
 
3739
                                    'disconnected.'))
3719
3740
            raise
3720
3741
 
3721
3742
 
3826
3847
    takes_args = ['url?']
3827
3848
    takes_options = [
3828
3849
        RegistryOption('format',
3829
 
            help='Upgrade to a specific format.  See "brz help'
3830
 
                 ' formats" for details.',
3831
 
            lazy_registry=('breezy.controldir', 'format_registry'),
3832
 
            converter=lambda name: controldir.format_registry.make_controldir(name),
3833
 
            value_switches=True, title='Branch format'),
 
3850
                       help='Upgrade to a specific format.  See "brz help'
 
3851
                       ' formats" for details.',
 
3852
                       lazy_registry=('breezy.controldir', 'format_registry'),
 
3853
                       converter=lambda name: controldir.format_registry.make_controldir(
 
3854
                           name),
 
3855
                       value_switches=True, title='Branch format'),
3834
3856
        Option('clean',
3835
 
            help='Remove the backup.bzr directory if successful.'),
 
3857
               help='Remove the backup.bzr directory if successful.'),
3836
3858
        Option('dry-run',
3837
 
            help="Show what would be done, but don't actually do anything."),
 
3859
               help="Show what would be done, but don't actually do anything."),
3838
3860
    ]
3839
3861
 
3840
3862
    def run(self, url='.', format=None, clean=False, dry_run=False):
3860
3882
 
3861
3883
            brz whoami "Frank Chu <fchu@example.com>"
3862
3884
    """
3863
 
    takes_options = [ 'directory',
3864
 
                      Option('email',
3865
 
                             help='Display email address only.'),
3866
 
                      Option('branch',
3867
 
                             help='Set identity for the current branch instead of '
3868
 
                                  'globally.'),
3869
 
                    ]
 
3885
    takes_options = ['directory',
 
3886
                     Option('email',
 
3887
                            help='Display email address only.'),
 
3888
                     Option('branch',
 
3889
                            help='Set identity for the current branch instead of '
 
3890
                            'globally.'),
 
3891
                     ]
3870
3892
    takes_args = ['name?']
3871
3893
    encoding_type = 'replace'
3872
3894
 
3891
3913
 
3892
3914
        if email:
3893
3915
            raise errors.BzrCommandError(gettext("--email can only be used to display existing "
3894
 
                                         "identity"))
 
3916
                                                 "identity"))
3895
3917
 
3896
3918
        # display a warning if an email address isn't included in the given name.
3897
3919
        try:
3976
3998
            if equal_pos == -1:
3977
3999
                self.print_alias(name)
3978
4000
            else:
3979
 
                self.set_alias(name[:equal_pos], name[equal_pos+1:])
 
4001
                self.set_alias(name[:equal_pos], name[equal_pos + 1:])
3980
4002
 
3981
4003
    def remove_alias(self, alias_name):
3982
4004
        if alias_name is None:
4061
4083
    """
4062
4084
    # NB: this is used from the class without creating an instance, which is
4063
4085
    # why it does not have a self parameter.
 
4086
 
4064
4087
    def get_transport_type(typestring):
4065
4088
        """Parse and return a transport specifier."""
4066
4089
        if typestring == "sftp":
4080
4103
    takes_args = ['testspecs*']
4081
4104
    takes_options = ['verbose',
4082
4105
                     Option('one',
4083
 
                             help='Stop when one test fails.',
4084
 
                             short_name='1',
4085
 
                             ),
 
4106
                            help='Stop when one test fails.',
 
4107
                            short_name='1',
 
4108
                            ),
4086
4109
                     Option('transport',
4087
4110
                            help='Use a different transport by default '
4088
4111
                                 'throughout the test suite.',
4102
4125
                     Option('list-only',
4103
4126
                            help='List the tests instead of running them.'),
4104
4127
                     RegistryOption('parallel',
4105
 
                        help="Run the test suite in parallel.",
4106
 
                        lazy_registry=('breezy.tests', 'parallel_registry'),
4107
 
                        value_switches=False,
4108
 
                        ),
 
4128
                                    help="Run the test suite in parallel.",
 
4129
                                    lazy_registry=(
 
4130
                                        'breezy.tests', 'parallel_registry'),
 
4131
                                    value_switches=False,
 
4132
                                    ),
4109
4133
                     Option('randomize', type=text_type, argname="SEED",
4110
4134
                            help='Randomize the order of tests using the given'
4111
4135
                                 ' seed or "now" for the current time.'),
4125
4149
                                help='Turn on a selftest debug flag.'),
4126
4150
                     ListOption('starting-with', type=text_type, argname='TESTID',
4127
4151
                                param_name='starting_with', short_name='s',
4128
 
                                help=
4129
 
                                'Load only the tests starting with TESTID.'),
 
4152
                                help='Load only the tests starting with TESTID.'),
4130
4153
                     Option('sync',
4131
4154
                            help="By default we disable fsync and fdatasync"
4132
4155
                                 " while running the test suite.")
4160
4183
            from . import tests
4161
4184
        except ImportError:
4162
4185
            raise errors.BzrCommandError("tests not available. Install the "
4163
 
                "breezy tests to run the breezy testsuite.")
 
4186
                                         "breezy tests to run the breezy testsuite.")
4164
4187
 
4165
4188
        if testspecs_list is not None:
4166
4189
            pattern = '|'.join(testspecs_list)
4180
4203
            # following code can be deleted when it's sufficiently deployed
4181
4204
            # -- vila/mgz 20100514
4182
4205
            if (sys.platform == "win32"
4183
 
                and getattr(sys.stdout, 'fileno', None) is not None):
 
4206
                    and getattr(sys.stdout, 'fileno', None) is not None):
4184
4207
                import msvcrt
4185
4208
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
4186
4209
        if subunit2:
4207
4230
        if not sync:
4208
4231
            self._disable_fsync()
4209
4232
        selftest_kwargs = {"verbose": verbose,
4210
 
                          "pattern": pattern,
4211
 
                          "stop_on_failure": one,
4212
 
                          "transport": transport,
4213
 
                          "test_suite_factory": test_suite_factory,
4214
 
                          "lsprof_timed": lsprof_timed,
4215
 
                          "lsprof_tests": lsprof_tests,
4216
 
                          "matching_tests_first": first,
4217
 
                          "list_only": list_only,
4218
 
                          "random_seed": randomize,
4219
 
                          "exclude_pattern": exclude_pattern,
4220
 
                          "strict": strict,
4221
 
                          "load_list": load_list,
4222
 
                          "debug_flags": debugflag,
4223
 
                          "starting_with": starting_with
4224
 
                          }
 
4233
                           "pattern": pattern,
 
4234
                           "stop_on_failure": one,
 
4235
                           "transport": transport,
 
4236
                           "test_suite_factory": test_suite_factory,
 
4237
                           "lsprof_timed": lsprof_timed,
 
4238
                           "lsprof_tests": lsprof_tests,
 
4239
                           "matching_tests_first": first,
 
4240
                           "list_only": list_only,
 
4241
                           "random_seed": randomize,
 
4242
                           "exclude_pattern": exclude_pattern,
 
4243
                           "strict": strict,
 
4244
                           "load_list": load_list,
 
4245
                           "debug_flags": debugflag,
 
4246
                           "starting_with": starting_with
 
4247
                           }
4225
4248
        selftest_kwargs.update(self.additional_selftest_args)
4226
4249
 
4227
4250
        # Make deprecation warnings visible, unless -Werror is set
4292
4315
        base_rev_id = graph.find_unique_lca(last1, last2)
4293
4316
 
4294
4317
        self.outf.write(gettext('merge base is revision %s\n') %
4295
 
                base_rev_id.decode('utf-8'))
 
4318
                        base_rev_id.decode('utf-8'))
4296
4319
 
4297
4320
 
4298
4321
class cmd_merge(Command):
4393
4416
        Option('uncommitted', help='Apply uncommitted changes'
4394
4417
               ' from a working copy, instead of branch changes.'),
4395
4418
        Option('pull', help='If the destination is already'
4396
 
                ' completely merged into the source, pull from the'
4397
 
                ' source rather than merging.  When this happens,'
4398
 
                ' you do not need to commit the result.'),
 
4419
               ' completely merged into the source, pull from the'
 
4420
               ' source rather than merging.  When this happens,'
 
4421
               ' you do not need to commit the result.'),
4399
4422
        custom_help('directory',
4400
 
               help='Branch to merge into, '
 
4423
                    help='Branch to merge into, '
4401
4424
                    'rather than the one containing the working directory.'),
4402
4425
        Option('preview', help='Instead of merging, show a diff of the'
4403
4426
               ' merge.'),
4404
4427
        Option('interactive', help='Select changes interactively.',
4405
 
            short_name='i')
 
4428
               short_name='i')
4406
4429
    ]
4407
4430
 
4408
4431
    def run(self, location=None, revision=None, force=False,
4425
4448
        tree = WorkingTree.open_containing(directory)[0]
4426
4449
        if tree.branch.revno() == 0:
4427
4450
            raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
4428
 
                                         'https://bugs.launchpad.net/bzr/+bug/308562'))
 
4451
                                                 'https://bugs.launchpad.net/bzr/+bug/308562'))
4429
4452
 
4430
4453
        # die as quickly as possible if there are uncommitted changes
4431
4454
        if not force:
4441
4464
        if location is not None:
4442
4465
            try:
4443
4466
                mergeable = bundle.read_mergeable_from_url(location,
4444
 
                    possible_transports=possible_transports)
 
4467
                                                           possible_transports=possible_transports)
4445
4468
            except errors.NotABundle:
4446
4469
                mergeable = None
4447
4470
            else:
4448
4471
                if uncommitted:
4449
4472
                    raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4450
 
                        ' with bundles or merge directives.'))
 
4473
                                                         ' with bundles or merge directives.'))
4451
4474
 
4452
4475
                if revision is not None:
4453
4476
                    raise errors.BzrCommandError(gettext(
4454
4477
                        'Cannot use -r with merge directives or bundles'))
4455
4478
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
4456
 
                   mergeable)
 
4479
                                                                    mergeable)
4457
4480
 
4458
4481
        if merger is None and uncommitted:
4459
4482
            if revision is not None and len(revision) > 0:
4460
4483
                raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4461
 
                    ' --revision at the same time.'))
 
4484
                                                     ' --revision at the same time.'))
4462
4485
            merger = self.get_merger_from_uncommitted(tree, location, None)
4463
4486
            allow_pending = False
4464
4487
 
4465
4488
        if merger is None:
4466
4489
            merger, allow_pending = self._get_merger_from_branch(tree,
4467
 
                location, revision, remember, possible_transports, None)
 
4490
                                                                 location, revision, remember, possible_transports, None)
4468
4491
 
4469
4492
        merger.merge_type = merge_type
4470
4493
        merger.reprocess = reprocess
4471
4494
        merger.show_base = show_base
4472
4495
        self.sanity_check_merger(merger)
4473
4496
        if (merger.base_rev_id == merger.other_rev_id and
4474
 
            merger.other_rev_id is not None):
 
4497
                merger.other_rev_id is not None):
4475
4498
            # check if location is a nonexistent file (and not a branch) to
4476
4499
            # disambiguate the 'Nothing to do'
4477
4500
            if merger.interesting_files:
4478
4501
                if not merger.other_tree.has_filename(
4479
 
                    merger.interesting_files[0]):
 
4502
                        merger.interesting_files[0]):
4480
4503
                    note(gettext("merger: ") + str(merger))
4481
4504
                    raise errors.PathsDoNotExist([location])
4482
4505
            note(gettext('Nothing to do.'))
4483
4506
            return 0
4484
4507
        if pull and not preview:
4485
4508
            if merger.interesting_files is not None:
4486
 
                raise errors.BzrCommandError(gettext('Cannot pull individual files'))
 
4509
                raise errors.BzrCommandError(
 
4510
                    gettext('Cannot pull individual files'))
4487
4511
            if (merger.base_rev_id == tree.last_revision()):
4488
4512
                result = tree.pull(merger.other_branch, False,
4489
4513
                                   merger.other_rev_id)
4548
4572
 
4549
4573
    def sanity_check_merger(self, merger):
4550
4574
        if (merger.show_base and
4551
 
            not merger.merge_type is _mod_merge.Merge3Merger):
 
4575
                not merger.merge_type is _mod_merge.Merge3Merger):
4552
4576
            raise errors.BzrCommandError(gettext("Show-base is not supported for this"
4553
 
                                         " merge type. %s") % merger.merge_type)
 
4577
                                                 " merge type. %s") % merger.merge_type)
4554
4578
        if merger.reprocess is None:
4555
4579
            if merger.show_base:
4556
4580
                merger.reprocess = False
4559
4583
                merger.reprocess = merger.merge_type.supports_reprocess
4560
4584
        if merger.reprocess and not merger.merge_type.supports_reprocess:
4561
4585
            raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
4562
 
                                         " for merge type %s.") %
 
4586
                                                 " for merge type %s.") %
4563
4587
                                         merger.merge_type)
4564
4588
        if merger.reprocess and merger.show_base:
4565
4589
            raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
4566
 
                                         " show base."))
 
4590
                                                 " show base."))
4567
4591
 
4568
4592
        if (merger.merge_type.requires_file_merge_plan and
4569
4593
            (not getattr(merger.this_tree, 'plan_file_merge', None) or
4571
4595
             (merger.base_tree is not None and
4572
4596
                 not getattr(merger.base_tree, 'plan_file_merge', None)))):
4573
4597
            raise errors.BzrCommandError(
4574
 
                 gettext('Plan file merge unsupported: '
4575
 
                         'Merge type incompatible with tree formats.'))
 
4598
                gettext('Plan file merge unsupported: '
 
4599
                        'Merge type incompatible with tree formats.'))
4576
4600
 
4577
4601
    def _get_merger_from_branch(self, tree, location, revision, remember,
4578
4602
                                possible_transports, pb):
4579
4603
        """Produce a merger from a location, assuming it refers to a branch."""
4580
4604
        # find the branch locations
4581
4605
        other_loc, user_location = self._select_branch_location(tree, location,
4582
 
            revision, -1)
 
4606
                                                                revision, -1)
4583
4607
        if revision is not None and len(revision) == 2:
4584
4608
            base_loc, _unused = self._select_branch_location(tree,
4585
 
                location, revision, 0)
 
4609
                                                             location, revision, 0)
4586
4610
        else:
4587
4611
            base_loc = other_loc
4588
4612
        # Open the branches
4589
4613
        other_branch, other_path = Branch.open_containing(other_loc,
4590
 
            possible_transports)
 
4614
                                                          possible_transports)
4591
4615
        if base_loc == other_loc:
4592
4616
            base_branch = other_branch
4593
4617
        else:
4594
4618
            base_branch, base_path = Branch.open_containing(base_loc,
4595
 
                possible_transports)
 
4619
                                                            possible_transports)
4596
4620
        # Find the revision ids
4597
4621
        other_revision_id = None
4598
4622
        base_revision_id = None
4610
4634
        # - user ask to remember or there is no previous location set to merge
4611
4635
        #   from and user didn't ask to *not* remember
4612
4636
        if (user_location is not None
4613
 
            and ((remember
4614
 
                  or (remember is None
4615
 
                      and tree.branch.get_submit_branch() is None)))):
 
4637
            and ((remember or
 
4638
              (remember is None and
 
4639
                   tree.branch.get_submit_branch() is None)))):
4616
4640
            tree.branch.set_submit_branch(other_branch.base)
4617
4641
        # Merge tags (but don't set them in the master branch yet, the user
4618
4642
        # might revert this merge).  Commit will propagate them.
4619
4643
        other_branch.tags.merge_to(tree.branch.tags, ignore_master=True)
4620
4644
        merger = _mod_merge.Merger.from_revision_ids(tree,
4621
 
            other_revision_id, base_revision_id, other_branch, base_branch)
 
4645
                                                     other_revision_id, base_revision_id, other_branch, base_branch)
4622
4646
        if other_path != '':
4623
4647
            allow_pending = False
4624
4648
            merger.interesting_files = [other_path]
4659
4683
            will be the user-entered location.
4660
4684
        """
4661
4685
        if (revision is not None and index is not None
4662
 
            and revision[index] is not None):
 
4686
                and revision[index] is not None):
4663
4687
            branch = revision[index].get_branch()
4664
4688
            if branch is not None:
4665
4689
                return branch, branch
4681
4705
            stored_location_type = "parent"
4682
4706
        mutter("%s", stored_location)
4683
4707
        if stored_location is None:
4684
 
            raise errors.BzrCommandError(gettext("No location specified or remembered"))
 
4708
            raise errors.BzrCommandError(
 
4709
                gettext("No location specified or remembered"))
4685
4710
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4686
4711
        note(gettext("{0} remembered {1} location {2}").format(verb_string,
4687
 
                stored_location_type, display_url))
 
4712
                                                               stored_location_type, display_url))
4688
4713
        return stored_location
4689
4714
 
4690
4715
 
4712
4737
    """
4713
4738
    takes_args = ['file*']
4714
4739
    takes_options = [
4715
 
            'merge-type',
4716
 
            'reprocess',
4717
 
            Option('show-base',
4718
 
                   help="Show base revision text in conflicts."),
4719
 
            ]
 
4740
        'merge-type',
 
4741
        'reprocess',
 
4742
        Option('show-base',
 
4743
               help="Show base revision text in conflicts."),
 
4744
        ]
4720
4745
 
4721
4746
    def run(self, file_list=None, merge_type=None, show_base=False,
4722
4747
            reprocess=False):
4728
4753
        parents = tree.get_parent_ids()
4729
4754
        if len(parents) != 2:
4730
4755
            raise errors.BzrCommandError(gettext("Sorry, remerge only works after normal"
4731
 
                                         " merges.  Not cherrypicking or"
4732
 
                                         " multi-merges."))
 
4756
                                                 " merges.  Not cherrypicking or"
 
4757
                                                 " multi-merges."))
4733
4758
        repository = tree.branch.repository
4734
4759
        interesting_files = None
4735
4760
        new_conflicts = []
4857
4882
    def _revert_tree_to_revision(tree, revision, file_list, no_backup):
4858
4883
        rev_tree = _get_one_revision_tree('revert', revision, tree=tree)
4859
4884
        tree.revert(file_list, rev_tree, not no_backup, None,
4860
 
            report_changes=True)
 
4885
                    report_changes=True)
4861
4886
 
4862
4887
 
4863
4888
class cmd_assert_fail(Command):
4876
4901
 
4877
4902
    _see_also = ['topics']
4878
4903
    takes_options = [
4879
 
            Option('long', 'Show help on all commands.'),
4880
 
            ]
 
4904
        Option('long', 'Show help on all commands.'),
 
4905
        ]
4881
4906
    takes_args = ['topic?']
4882
4907
    aliases = ['?', '--help', '-?', '-h']
4883
4908
 
4954
4979
        'show-ids',
4955
4980
        'verbose',
4956
4981
        custom_help('revision',
4957
 
             help='Filter on other branch revisions (inclusive). '
4958
 
                'See "help revisionspec" for details.'),
 
4982
                    help='Filter on other branch revisions (inclusive). '
 
4983
                    'See "help revisionspec" for details.'),
4959
4984
        Option('my-revision',
4960
 
            type=_parse_revision_str,
4961
 
            help='Filter on local branch revisions (inclusive). '
4962
 
                'See "help revisionspec" for details.'),
 
4985
               type=_parse_revision_str,
 
4986
               help='Filter on local branch revisions (inclusive). '
 
4987
               'See "help revisionspec" for details.'),
4963
4988
        Option('include-merged',
4964
4989
               'Show all revisions in addition to the mainline ones.'),
4965
4990
        Option('include-merges', hidden=True,
5003
5028
            other_branch = parent
5004
5029
            if other_branch is None:
5005
5030
                raise errors.BzrCommandError(gettext("No peer location known"
5006
 
                                             " or specified."))
 
5031
                                                     " or specified."))
5007
5032
            display_url = urlutils.unescape_for_display(parent,
5008
5033
                                                        self.outf.encoding)
5009
5034
            message(gettext("Using saved parent location: {0}\n").format(
5017
5042
 
5018
5043
        local_revid_range = _revision_range_to_revid_range(
5019
5044
            _get_revision_range(my_revision, local_branch,
5020
 
                self.name()))
 
5045
                                self.name()))
5021
5046
 
5022
5047
        remote_revid_range = _revision_range_to_revid_range(
5023
5048
            _get_revision_range(revision,
5024
 
                remote_branch, self.name()))
 
5049
                                remote_branch, self.name()))
5025
5050
 
5026
5051
        local_extra, remote_extra = find_unmerged(
5027
5052
            local_branch, remote_branch, restrict,
5042
5067
            message(ngettext("You have %d extra revision:\n",
5043
5068
                             "You have %d extra revisions:\n",
5044
5069
                             len(local_extra)) %
5045
 
                len(local_extra))
 
5070
                    len(local_extra))
5046
5071
            rev_tag_dict = {}
5047
5072
            if local_branch.supports_tags():
5048
5073
                rev_tag_dict = local_branch.tags.get_reverse_tag_dict()
5049
5074
            for revision in iter_log_revisions(local_extra,
5050
 
                                local_branch.repository,
5051
 
                                verbose,
5052
 
                                rev_tag_dict):
 
5075
                                               local_branch.repository,
 
5076
                                               verbose,
 
5077
                                               rev_tag_dict):
5053
5078
                lf.log_revision(revision)
5054
5079
            printed_local = True
5055
5080
            status_code = 1
5062
5087
            message(ngettext("You are missing %d revision:\n",
5063
5088
                             "You are missing %d revisions:\n",
5064
5089
                             len(remote_extra)) %
5065
 
                len(remote_extra))
 
5090
                    len(remote_extra))
5066
5091
            if remote_branch.supports_tags():
5067
5092
                rev_tag_dict = remote_branch.tags.get_reverse_tag_dict()
5068
5093
            for revision in iter_log_revisions(remote_extra,
5069
 
                                remote_branch.repository,
5070
 
                                verbose,
5071
 
                                rev_tag_dict):
 
5094
                                               remote_branch.repository,
 
5095
                                               verbose,
 
5096
                                               rev_tag_dict):
5072
5097
                lf.log_revision(revision)
5073
5098
            status_code = 1
5074
5099
 
5114
5139
    _see_also = ['repositories']
5115
5140
    takes_args = ['branch_or_repo?']
5116
5141
    takes_options = [
5117
 
        Option('clean-obsolete-packs', 'Delete obsolete packs to save disk space.'),
 
5142
        Option('clean-obsolete-packs',
 
5143
               'Delete obsolete packs to save disk space.'),
5118
5144
        ]
5119
5145
 
5120
5146
    def run(self, branch_or_repo='.', clean_obsolete_packs=False):
5159
5185
class cmd_testament(Command):
5160
5186
    __doc__ = """Show testament (signing-form) of a revision."""
5161
5187
    takes_options = [
5162
 
            'revision',
5163
 
            Option('long', help='Produce long-format testament.'),
5164
 
            Option('strict',
5165
 
                   help='Produce a strict-format testament.')]
 
5188
        'revision',
 
5189
        Option('long', help='Produce long-format testament.'),
 
5190
        Option('strict',
 
5191
               help='Produce a strict-format testament.')]
5166
5192
    takes_args = ['branch?']
5167
5193
    encoding_type = 'exact'
 
5194
 
5168
5195
    @display_command
5169
5196
    def run(self, branch=u'.', revision=None, long=False, strict=False):
5170
5197
        from .testament import Testament, StrictTestament
5234
5261
            # If there is a tree and we're not annotating historical
5235
5262
            # versions, annotate the working tree's content.
5236
5263
            annotate_file_tree(wt, relpath, self.outf, long, all,
5237
 
                show_ids=show_ids, file_id=file_id)
 
5264
                               show_ids=show_ids, file_id=file_id)
5238
5265
        else:
5239
5266
            annotate_file_tree(tree, relpath, self.outf, long, all,
5240
 
                show_ids=show_ids, branch=branch, file_id=file_id)
 
5267
                               show_ids=show_ids, branch=branch, file_id=file_id)
5241
5268
 
5242
5269
 
5243
5270
class cmd_re_sign(Command):
5244
5271
    __doc__ = """Create a digital signature for an existing revision."""
5245
5272
    # TODO be able to replace existing ones.
5246
5273
 
5247
 
    hidden = True # is this right ?
 
5274
    hidden = True  # is this right ?
5248
5275
    takes_args = ['revision_id*']
5249
5276
    takes_options = ['directory', 'revision']
5250
5277
 
5251
5278
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
5252
5279
        if revision_id_list is not None and revision is not None:
5253
 
            raise errors.BzrCommandError(gettext('You can only supply one of revision_id or --revision'))
 
5280
            raise errors.BzrCommandError(
 
5281
                gettext('You can only supply one of revision_id or --revision'))
5254
5282
        if revision_id_list is None and revision is None:
5255
 
            raise errors.BzrCommandError(gettext('You must supply either --revision or a revision_id'))
 
5283
            raise errors.BzrCommandError(
 
5284
                gettext('You must supply either --revision or a revision_id'))
5256
5285
        b = WorkingTree.open_containing(directory)[0].branch
5257
5286
        self.add_cleanup(b.lock_write().unlock)
5258
5287
        return self._run(b, revision_id_list, revision)
5290
5319
                if to_revid is None:
5291
5320
                    to_revno = b.revno()
5292
5321
                if from_revno is None or to_revno is None:
5293
 
                    raise errors.BzrCommandError(gettext('Cannot sign a range of non-revision-history revisions'))
 
5322
                    raise errors.BzrCommandError(
 
5323
                        gettext('Cannot sign a range of non-revision-history revisions'))
5294
5324
                b.repository.start_write_group()
5295
5325
                try:
5296
5326
                    for revno in range(from_revno, to_revno + 1):
5302
5332
                else:
5303
5333
                    b.repository.commit_write_group()
5304
5334
            else:
5305
 
                raise errors.BzrCommandError(gettext('Please supply either one revision, or a range.'))
 
5335
                raise errors.BzrCommandError(
 
5336
                    gettext('Please supply either one revision, or a range.'))
5306
5337
 
5307
5338
 
5308
5339
class cmd_bind(Command):
5328
5359
                location = b.get_old_bound_location()
5329
5360
            except errors.UpgradeRequired:
5330
5361
                raise errors.BzrCommandError(gettext('No location supplied.  '
5331
 
                    'This format does not remember old locations.'))
 
5362
                                                     'This format does not remember old locations.'))
5332
5363
            else:
5333
5364
                if location is None:
5334
5365
                    if b.get_bound_location() is not None:
5343
5374
            b.bind(b_other)
5344
5375
        except errors.DivergedBranches:
5345
5376
            raise errors.BzrCommandError(gettext('These branches have diverged.'
5346
 
                                         ' Try merging, and then bind again.'))
 
5377
                                                 ' Try merging, and then bind again.'))
5347
5378
        if b.get_config().has_explicit_nickname():
5348
5379
            b.nick = b_other.nick
5349
5380
 
5387
5418
    # information in shared branches as well.
5388
5419
    _see_also = ['commit']
5389
5420
    takes_options = ['verbose', 'revision',
5390
 
                    Option('dry-run', help='Don\'t actually make changes.'),
5391
 
                    Option('force', help='Say yes to all questions.'),
5392
 
                    Option('keep-tags',
5393
 
                           help='Keep tags that point to removed revisions.'),
5394
 
                    Option('local',
5395
 
                           help="Only remove the commits from the local branch"
5396
 
                                " when in a checkout."
5397
 
                           ),
5398
 
                    ]
 
5421
                     Option('dry-run', help='Don\'t actually make changes.'),
 
5422
                     Option('force', help='Say yes to all questions.'),
 
5423
                     Option('keep-tags',
 
5424
                            help='Keep tags that point to removed revisions.'),
 
5425
                     Option('local',
 
5426
                            help="Only remove the commits from the local branch"
 
5427
                            " when in a checkout."
 
5428
                            ),
 
5429
                     ]
5399
5430
    takes_args = ['location?']
5400
5431
    aliases = []
5401
5432
    encoding_type = 'replace'
5457
5488
 
5458
5489
        if dry_run:
5459
5490
            self.outf.write(gettext('Dry-run, pretending to remove'
5460
 
                            ' the above revisions.\n'))
 
5491
                                    ' the above revisions.\n'))
5461
5492
        else:
5462
 
            self.outf.write(gettext('The above revision(s) will be removed.\n'))
 
5493
            self.outf.write(
 
5494
                gettext('The above revision(s) will be removed.\n'))
5463
5495
 
5464
5496
        if not force:
5465
5497
            if not ui.ui_factory.confirm_action(
5474
5506
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5475
5507
                 revno=revno, local=local, keep_tags=keep_tags)
5476
5508
        self.outf.write(gettext('You can restore the old tip by running:\n'
5477
 
             '  brz pull . -r revid:%s\n') % last_rev_id.decode('utf-8'))
 
5509
                                '  brz pull . -r revid:%s\n') % last_rev_id.decode('utf-8'))
5478
5510
 
5479
5511
 
5480
5512
class cmd_break_lock(Command):
5500
5532
        Option('config',
5501
5533
               help='LOCATION is the directory where the config lock is.'),
5502
5534
        Option('force',
5503
 
            help='Do not ask for confirmation before breaking the lock.'),
 
5535
               help='Do not ask for confirmation before breaking the lock.'),
5504
5536
        ]
5505
5537
 
5506
5538
    def run(self, location=None, config=False, force=False):
5508
5540
            location = u'.'
5509
5541
        if force:
5510
5542
            ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
5511
 
                None,
5512
 
                {'breezy.lockdir.break': True})
 
5543
                                                               None,
 
5544
                                                               {'breezy.lockdir.break': True})
5513
5545
        if config:
5514
5546
            conf = _mod_config.LockableConfig(file_name=location)
5515
5547
            conf.break_lock()
5544
5576
        Option('inet',
5545
5577
               help='Serve on stdin/out for use from inetd or sshd.'),
5546
5578
        RegistryOption('protocol',
5547
 
               help="Protocol to serve.",
5548
 
               lazy_registry=('breezy.transport', 'transport_server_registry'),
5549
 
               value_switches=True),
 
5579
                       help="Protocol to serve.",
 
5580
                       lazy_registry=('breezy.transport',
 
5581
                                      'transport_server_registry'),
 
5582
                       value_switches=True),
5550
5583
        Option('listen',
5551
5584
               help='Listen for connections on nominated address.', type=text_type),
5552
5585
        Option('port',
5555
5588
                    'port.  The default port depends on the protocol.',
5556
5589
               type=int),
5557
5590
        custom_help('directory',
5558
 
               help='Serve contents of this directory.'),
 
5591
                    help='Serve contents of this directory.'),
5559
5592
        Option('allow-writes',
5560
5593
               help='By default the server is a readonly server.  Supplying '
5561
5594
                    '--allow-writes enables write access to the contents of '
5564
5597
                    'external authentication is arranged supplying this '
5565
5598
                    'option leads to global uncontrolled write access to your '
5566
5599
                    'file system.'
5567
 
                ),
 
5600
               ),
5568
5601
        Option('client-timeout', type=float,
5569
5602
               help='Override the default idle client timeout (5min).'),
5570
5603
        ]
5600
5633
    _see_also = ['split']
5601
5634
    takes_args = ['tree']
5602
5635
    takes_options = [
5603
 
            Option('reference', help='Join by reference.', hidden=True),
5604
 
            ]
 
5636
        Option('reference', help='Join by reference.', hidden=True),
 
5637
        ]
5605
5638
 
5606
5639
    def run(self, tree, reference=False):
5607
5640
        from breezy.mutabletree import BadReferenceTarget
5621
5654
                # XXX: Would be better to just raise a nicely printable
5622
5655
                # exception from the real origin.  Also below.  mbp 20070306
5623
5656
                raise errors.BzrCommandError(
5624
 
                       gettext("Cannot join {0}.  {1}").format(tree, e.reason))
 
5657
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5625
5658
        else:
5626
5659
            try:
5627
5660
                containing_tree.subsume(sub_tree)
5628
5661
            except errors.BadSubsumeSource as e:
5629
5662
                raise errors.BzrCommandError(
5630
 
                       gettext("Cannot join {0}.  {1}").format(tree, e.reason))
 
5663
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5631
5664
 
5632
5665
 
5633
5666
class cmd_split(Command):
5682
5715
    takes_options = [
5683
5716
        'directory',
5684
5717
        RegistryOption.from_kwargs('patch-type',
5685
 
            'The type of patch to include in the directive.',
5686
 
            title='Patch type',
5687
 
            value_switches=True,
5688
 
            enum_switch=False,
5689
 
            bundle='Bazaar revision bundle (default).',
5690
 
            diff='Normal unified diff.',
5691
 
            plain='No patch, just directive.'),
 
5718
                                   'The type of patch to include in the directive.',
 
5719
                                   title='Patch type',
 
5720
                                   value_switches=True,
 
5721
                                   enum_switch=False,
 
5722
                                   bundle='Bazaar revision bundle (default).',
 
5723
                                   diff='Normal unified diff.',
 
5724
                                   plain='No patch, just directive.'),
5692
5725
        Option('sign', help='GPG-sign the directive.'), 'revision',
5693
5726
        Option('mail-to', type=text_type,
5694
 
            help='Instead of printing the directive, email to this address.'),
 
5727
               help='Instead of printing the directive, email to this address.'),
5695
5728
        Option('message', type=text_type, short_name='m',
5696
 
            help='Message to use when committing this merge.')
 
5729
               help='Message to use when committing this merge.')
5697
5730
        ]
5698
5731
 
5699
5732
    encoding_type = 'exact'
5717
5750
        if submit_branch is None:
5718
5751
            submit_branch = branch.get_parent()
5719
5752
        if submit_branch is None:
5720
 
            raise errors.BzrCommandError(gettext('No submit branch specified or known'))
 
5753
            raise errors.BzrCommandError(
 
5754
                gettext('No submit branch specified or known'))
5721
5755
 
5722
5756
        stored_public_branch = branch.get_public_branch()
5723
5757
        if public_branch is None:
5727
5761
            branch.set_public_branch(public_branch)
5728
5762
        if not include_bundle and public_branch is None:
5729
5763
            raise errors.BzrCommandError(gettext('No public branch specified or'
5730
 
                                         ' known'))
 
5764
                                                 ' known'))
5731
5765
        base_revision_id = None
5732
5766
        if revision is not None:
5733
5767
            if len(revision) > 2:
5734
5768
                raise errors.BzrCommandError(gettext('brz merge-directive takes '
5735
 
                    'at most two one revision identifiers'))
 
5769
                                                     'at most two one revision identifiers'))
5736
5770
            revision_id = revision[-1].as_revision_id(branch)
5737
5771
            if len(revision) == 2:
5738
5772
                base_revision_id = revision[0].as_revision_id(branch)
5949
5983
            output = '-'
5950
5984
        from .send import send
5951
5985
        return send(submit_branch, revision, public_branch, remember,
5952
 
                         format, no_bundle, no_patch, output,
5953
 
                         kwargs.get('from', '.'), None, None, None,
5954
 
                         self.outf, strict=strict)
 
5986
                    format, no_bundle, no_patch, output,
 
5987
                    kwargs.get('from', '.'), None, None, None,
 
5988
                    self.outf, strict=strict)
5955
5989
 
5956
5990
 
5957
5991
class cmd_tag(Command):
5980
6014
    takes_args = ['tag_name?']
5981
6015
    takes_options = [
5982
6016
        Option('delete',
5983
 
            help='Delete this tag rather than placing it.',
5984
 
            ),
 
6017
               help='Delete this tag rather than placing it.',
 
6018
               ),
5985
6019
        custom_help('directory',
5986
 
            help='Branch in which to place the tag.'),
 
6020
                    help='Branch in which to place the tag.'),
5987
6021
        Option('force',
5988
 
            help='Replace existing tags.',
5989
 
            ),
 
6022
               help='Replace existing tags.',
 
6023
               ),
5990
6024
        'revision',
5991
6025
        ]
5992
6026
 
6000
6034
        self.add_cleanup(branch.lock_write().unlock)
6001
6035
        if delete:
6002
6036
            if tag_name is None:
6003
 
                raise errors.BzrCommandError(gettext("No tag specified to delete."))
 
6037
                raise errors.BzrCommandError(
 
6038
                    gettext("No tag specified to delete."))
6004
6039
            branch.tags.delete_tag(tag_name)
6005
6040
            note(gettext('Deleted tag %s.') % tag_name)
6006
6041
        else:
6042
6077
    _see_also = ['tag']
6043
6078
    takes_options = [
6044
6079
        custom_help('directory',
6045
 
            help='Branch whose tags should be displayed.'),
 
6080
                    help='Branch whose tags should be displayed.'),
6046
6081
        RegistryOption('sort',
6047
 
            'Sort tags by different criteria.', title='Sorting',
6048
 
            lazy_registry=('breezy.tag', 'tag_sort_methods')
6049
 
            ),
 
6082
                       'Sort tags by different criteria.', title='Sorting',
 
6083
                       lazy_registry=('breezy.tag', 'tag_sort_methods')
 
6084
                       ),
6050
6085
        'show-ids',
6051
6086
        'revision',
6052
6087
    ]
6105
6140
        tagged_revids = branch.tags.get_reverse_tag_dict()
6106
6141
        found = []
6107
6142
        for r in branch.iter_merge_sorted_revisions(
6108
 
            start_revision_id=revid2, stop_revision_id=revid1,
6109
 
            stop_rule='include'):
 
6143
                start_revision_id=revid2, stop_revision_id=revid1,
 
6144
                stop_rule='include'):
6110
6145
            revid_tags = tagged_revids.get(r[0], None)
6111
6146
            if revid_tags:
6112
6147
                found.extend([(tag, r[0]) for tag in revid_tags])
6139
6174
            tree='Reconfigure to be an unbound branch with a working tree.',
6140
6175
            checkout='Reconfigure to be a bound branch with a working tree.',
6141
6176
            lightweight_checkout='Reconfigure to be a lightweight'
6142
 
                ' checkout (with no local history).',
 
6177
            ' checkout (with no local history).',
6143
6178
            ),
6144
6179
        RegistryOption.from_kwargs(
6145
6180
            'repository_type',
6147
6182
            help='Location fo the repository.',
6148
6183
            value_switches=True, enum_switch=False,
6149
6184
            standalone='Reconfigure to be a standalone branch '
6150
 
                '(i.e. stop using shared repository).',
 
6185
            '(i.e. stop using shared repository).',
6151
6186
            use_shared='Reconfigure to use a shared repository.',
6152
6187
            ),
6153
6188
        RegistryOption.from_kwargs(
6156
6191
            help='Whether new branches in the repository have trees.',
6157
6192
            value_switches=True, enum_switch=False,
6158
6193
            with_trees='Reconfigure repository to create '
6159
 
                'working trees on branches by default.',
 
6194
            'working trees on branches by default.',
6160
6195
            with_no_trees='Reconfigure repository to not create '
6161
 
                'working trees on branches by default.'
 
6196
            'working trees on branches by default.'
6162
6197
            ),
6163
6198
        Option('bind-to', help='Branch to bind checkout to.', type=text_type),
6164
6199
        Option('force',
6165
 
            help='Perform reconfiguration even if local changes'
6166
 
            ' will be lost.'),
 
6200
               help='Perform reconfiguration even if local changes'
 
6201
               ' will be lost.'),
6167
6202
        Option('stacked-on',
6168
 
            help='Reconfigure a branch to be stacked on another branch.',
6169
 
            type=text_type,
6170
 
            ),
 
6203
               help='Reconfigure a branch to be stacked on another branch.',
 
6204
               type=text_type,
 
6205
               ),
6171
6206
        Option('unstacked',
6172
 
            help='Reconfigure a branch to be unstacked.  This '
6173
 
                'may require copying substantial data into it.',
6174
 
            ),
 
6207
               help='Reconfigure a branch to be unstacked.  This '
 
6208
               'may require copying substantial data into it.',
 
6209
               ),
6175
6210
        ]
6176
6211
 
6177
6212
    def run(self, location=None, bind_to=None, force=False,
6179
6214
            stacked_on=None, unstacked=None):
6180
6215
        directory = controldir.ControlDir.open(location)
6181
6216
        if stacked_on and unstacked:
6182
 
            raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
 
6217
            raise errors.BzrCommandError(
 
6218
                gettext("Can't use both --stacked-on and --unstacked"))
6183
6219
        elif stacked_on is not None:
6184
6220
            reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
6185
6221
        elif unstacked:
6189
6225
        # to ban it.
6190
6226
        if (tree_type is None and
6191
6227
            repository_type is None and
6192
 
            repository_trees is None):
 
6228
                repository_trees is None):
6193
6229
            if stacked_on or unstacked:
6194
6230
                return
6195
6231
            else:
6196
6232
                raise errors.BzrCommandError(gettext('No target configuration '
6197
 
                    'specified'))
 
6233
                                                     'specified'))
6198
6234
        reconfiguration = None
6199
6235
        if tree_type == 'branch':
6200
6236
            reconfiguration = reconfigure.Reconfigure.to_branch(directory)
6253
6289
    takes_args = ['to_location?']
6254
6290
    takes_options = ['directory',
6255
6291
                     Option('force',
6256
 
                        help='Switch even if local commits will be lost.'),
 
6292
                            help='Switch even if local commits will be lost.'),
6257
6293
                     'revision',
6258
6294
                     Option('create-branch', short_name='b',
6259
 
                        help='Create the target branch from this one before'
6260
 
                             ' switching to it.'),
 
6295
                            help='Create the target branch from this one before'
 
6296
                            ' switching to it.'),
6261
6297
                     Option('store',
6262
 
                        help='Store and restore uncommitted changes in the'
6263
 
                             ' branch.'),
6264
 
                    ]
 
6298
                            help='Store and restore uncommitted changes in the'
 
6299
                            ' branch.'),
 
6300
                     ]
6265
6301
 
6266
6302
    def run(self, to_location=None, force=False, create_branch=False,
6267
6303
            revision=None, directory=u'.', store=False):
6270
6306
        revision = _get_one_revision('switch', revision)
6271
6307
        possible_transports = []
6272
6308
        control_dir = controldir.ControlDir.open_containing(tree_location,
6273
 
            possible_transports=possible_transports)[0]
 
6309
                                                            possible_transports=possible_transports)[0]
6274
6310
        if to_location is None:
6275
6311
            if revision is None:
6276
6312
                raise errors.BzrCommandError(gettext('You must supply either a'
6277
 
                                             ' revision or a location'))
 
6313
                                                     ' revision or a location'))
6278
6314
            to_location = tree_location
6279
6315
        try:
6280
6316
            branch = control_dir.open_branch(
6288
6324
                raise errors.BzrCommandError(
6289
6325
                    gettext('cannot create branch without source branch'))
6290
6326
            to_location = lookup_new_sibling_branch(control_dir, to_location,
6291
 
                 possible_transports=possible_transports)
 
6327
                                                    possible_transports=possible_transports)
6292
6328
            to_branch = branch.controldir.sprout(to_location,
6293
 
                 possible_transports=possible_transports,
6294
 
                 source_branch=branch).open_branch()
 
6329
                                                 possible_transports=possible_transports,
 
6330
                                                 source_branch=branch).open_branch()
6295
6331
        else:
6296
6332
            try:
6297
6333
                to_branch = Branch.open(to_location,
6298
 
                    possible_transports=possible_transports)
 
6334
                                        possible_transports=possible_transports)
6299
6335
            except errors.NotBranchError:
6300
6336
                to_branch = open_sibling_branch(control_dir, to_location,
6301
 
                    possible_transports=possible_transports)
 
6337
                                                possible_transports=possible_transports)
6302
6338
        if revision is not None:
6303
6339
            revision = revision.as_revision_id(to_branch)
6304
6340
        try:
6306
6342
                          store_uncommitted=store)
6307
6343
        except controldir.BranchReferenceLoop:
6308
6344
            raise errors.BzrCommandError(
6309
 
                    gettext('switching would create a branch reference loop. '
6310
 
                            'Use the "bzr up" command to switch to a '
6311
 
                            'different revision.'))
 
6345
                gettext('switching would create a branch reference loop. '
 
6346
                        'Use the "bzr up" command to switch to a '
 
6347
                        'different revision.'))
6312
6348
        if had_explicit_nick:
6313
 
            branch = control_dir.open_branch() #get the new branch!
 
6349
            branch = control_dir.open_branch()  # get the new branch!
6314
6350
            branch.nick = to_branch.nick
6315
6351
        note(gettext('Switched to branch: %s'),
6316
 
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6317
 
 
 
6352
             urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6318
6353
 
6319
6354
 
6320
6355
class cmd_view(Command):
6383
6418
    takes_args = ['file*']
6384
6419
    takes_options = [
6385
6420
        Option('all',
6386
 
            help='Apply list or delete action to all views.',
6387
 
            ),
 
6421
               help='Apply list or delete action to all views.',
 
6422
               ),
6388
6423
        Option('delete',
6389
 
            help='Delete the view.',
6390
 
            ),
 
6424
               help='Delete the view.',
 
6425
               ),
6391
6426
        Option('name',
6392
 
            help='Name of the view to define, list or delete.',
6393
 
            type=text_type,
6394
 
            ),
 
6427
               help='Name of the view to define, list or delete.',
 
6428
               type=text_type,
 
6429
               ),
6395
6430
        Option('switch',
6396
 
            help='Name of the view to switch to.',
6397
 
            type=text_type,
6398
 
            ),
 
6431
               help='Name of the view to switch to.',
 
6432
               type=text_type,
 
6433
               ),
6399
6434
        ]
6400
6435
 
6401
6436
    def run(self, file_list,
6405
6440
            switch=None,
6406
6441
            ):
6407
6442
        tree, file_list = WorkingTree.open_containing_paths(file_list,
6408
 
            apply_view=False)
 
6443
                                                            apply_view=False)
6409
6444
        current_view, view_dict = tree.views.get_view_info()
6410
6445
        if name is None:
6411
6446
            name = current_view
6420
6455
                tree.views.set_view_info(None, {})
6421
6456
                self.outf.write(gettext("Deleted all views.\n"))
6422
6457
            elif name is None:
6423
 
                raise errors.BzrCommandError(gettext("No current view to delete"))
 
6458
                raise errors.BzrCommandError(
 
6459
                    gettext("No current view to delete"))
6424
6460
            else:
6425
6461
                tree.views.delete_view(name)
6426
6462
                self.outf.write(gettext("Deleted '%s' view.\n") % name)
6433
6469
                    "Both --switch and --all specified"))
6434
6470
            elif switch == 'off':
6435
6471
                if current_view is None:
6436
 
                    raise errors.BzrCommandError(gettext("No current view to disable"))
 
6472
                    raise errors.BzrCommandError(
 
6473
                        gettext("No current view to disable"))
6437
6474
                tree.views.set_view_info(None, view_dict)
6438
 
                self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
 
6475
                self.outf.write(gettext("Disabled '%s' view.\n") %
 
6476
                                (current_view))
6439
6477
            else:
6440
6478
                tree.views.set_view_info(switch, view_dict)
6441
6479
                view_str = views.view_display_str(tree.views.lookup_view())
6442
 
                self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
 
6480
                self.outf.write(
 
6481
                    gettext("Using '{0}' view: {1}\n").format(switch, view_str))
6443
6482
        elif all:
6444
6483
            if view_dict:
6445
6484
                self.outf.write(gettext('Views defined:\n'))
6461
6500
                    "Cannot change the 'off' pseudo view"))
6462
6501
            tree.views.set_view(name, sorted(file_list))
6463
6502
            view_str = views.view_display_str(tree.views.lookup_view())
6464
 
            self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
 
6503
            self.outf.write(
 
6504
                gettext("Using '{0}' view: {1}\n").format(name, view_str))
6465
6505
        else:
6466
6506
            # list the files
6467
6507
            if name is None:
6469
6509
                self.outf.write(gettext('No current view.\n'))
6470
6510
            else:
6471
6511
                view_str = views.view_display_str(tree.views.lookup_view(name))
6472
 
                self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
 
6512
                self.outf.write(
 
6513
                    gettext("'{0}' view is: {1}\n").format(name, view_str))
6473
6514
 
6474
6515
 
6475
6516
class cmd_hooks(Command):
6509
6550
    takes_args = ["location?"]
6510
6551
 
6511
6552
    takes_options = ['directory',
6512
 
        Option('force', help='Remove branch even if it is the active branch.')]
 
6553
                     Option('force', help='Remove branch even if it is the active branch.')]
6513
6554
 
6514
6555
    aliases = ["rmbranch"]
6515
6556
 
6521
6562
            except errors.NotBranchError:
6522
6563
                active_branch = None
6523
6564
            if (active_branch is not None and
6524
 
                br.control_url == active_branch.control_url):
 
6565
                    br.control_url == active_branch.control_url):
6525
6566
                raise errors.BzrCommandError(
6526
6567
                    gettext("Branch is active. Use --force to remove it."))
6527
6568
        br.controldir.destroy_branch(br.name)
6590
6631
            writer = breezy.option.diff_writer_registry.get()
6591
6632
        try:
6592
6633
            shelver = Shelver.from_args(writer(self.outf), revision, all,
6593
 
                file_list, message, destroy=destroy, directory=directory)
 
6634
                                        file_list, message, destroy=destroy, directory=directory)
6594
6635
            try:
6595
6636
                shelver.run()
6596
6637
            finally:
6705
6746
        branchdir = '.'
6706
6747
        if path is not None:
6707
6748
            branchdir = path
6708
 
        tree, branch, relpath =(
 
6749
        tree, branch, relpath = (
6709
6750
            controldir.ControlDir.open_containing_tree_or_branch(branchdir))
6710
6751
        if path is not None:
6711
6752
            path = relpath
6737
6778
 
6738
6779
    hidden = True
6739
6780
    takes_options = [Option('plugin',
6740
 
                            help='Export help text from named command '\
 
6781
                            help='Export help text from named command '
6741
6782
                                 '(defaults to all built in commands).',
6742
6783
                            type=text_type),
6743
6784
                     Option('include-duplicates',
6744
6785
                            help='Output multiple copies of the same msgid '
6745
6786
                                 'string if it appears more than once.'),
6746
 
                            ]
 
6787
                     ]
6747
6788
 
6748
6789
    def run(self, plugin=None, include_duplicates=False):
6749
6790
        from .export_pot import export_pot
6817
6858
    # register lazy builtins from other modules; called at startup and should
6818
6859
    # be only called once.
6819
6860
    for (name, aliases, module_name) in [
6820
 
        ('cmd_bisect', [], 'breezy.bisect'),
6821
 
        ('cmd_bundle_info', [], 'breezy.bundle.commands'),
6822
 
        ('cmd_config', [], 'breezy.config'),
6823
 
        ('cmd_dump_btree', [], 'breezy.bzr.debug_commands'),
6824
 
        ('cmd_version_info', [], 'breezy.cmd_version_info'),
6825
 
        ('cmd_resolve', ['resolved'], 'breezy.conflicts'),
6826
 
        ('cmd_conflicts', [], 'breezy.conflicts'),
6827
 
        ('cmd_ping', [], 'breezy.bzr.smart.ping'),
6828
 
        ('cmd_sign_my_commits', [], 'breezy.commit_signature_commands'),
6829
 
        ('cmd_verify_signatures', [], 'breezy.commit_signature_commands'),
6830
 
        ('cmd_test_script', [], 'breezy.cmd_test_script'),
6831
 
        ]:
 
6861
            ('cmd_bisect', [], 'breezy.bisect'),
 
6862
            ('cmd_bundle_info', [], 'breezy.bundle.commands'),
 
6863
            ('cmd_config', [], 'breezy.config'),
 
6864
            ('cmd_dump_btree', [], 'breezy.bzr.debug_commands'),
 
6865
            ('cmd_version_info', [], 'breezy.cmd_version_info'),
 
6866
            ('cmd_resolve', ['resolved'], 'breezy.conflicts'),
 
6867
            ('cmd_conflicts', [], 'breezy.conflicts'),
 
6868
            ('cmd_ping', [], 'breezy.bzr.smart.ping'),
 
6869
            ('cmd_sign_my_commits', [], 'breezy.commit_signature_commands'),
 
6870
            ('cmd_verify_signatures', [], 'breezy.commit_signature_commands'),
 
6871
            ('cmd_test_script', [], 'breezy.cmd_test_script'),
 
6872
            ]:
6832
6873
        builtin_command_registry.register_lazy(name, aliases, module_name)