~ubuntu-branches/debian/experimental/bzr/experimental

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-03-31 12:03:48 UTC
  • mfrom: (1.1.65 upstream) (9.1.19 sid)
  • Revision ID: james.westby@ubuntu.com-20110331120348-udzyazjjzx8ywahr
Tags: 2.4.0~beta1-1
* New upstream release.
 + Drop patches merged upstream: 01_test_locale, 04_cpu_count,
 05_kfreebsd_tests, 06_format_gc_chk_sha1_record
 + Fixes directory modes in zip files. LP: #207253

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
250
250
    To skip the display of pending merge information altogether, use
251
251
    the no-pending option or specify a file/directory.
252
252
 
253
 
    If a revision argument is given, the status is calculated against
254
 
    that revision, or between two revisions if two are provided.
 
253
    To compare the working directory to a specific revision, pass a
 
254
    single revision to the revision argument.
 
255
 
 
256
    To see which files have changed in a specific revision, or between
 
257
    two revisions, pass a revision range to the revision argument.
 
258
    This will produce the same results as calling 'bzr diff --summarize'.
255
259
    """
256
260
 
257
261
    # TODO: --no-recurse, --recurse options
324
328
        if revision_id is None and revision is None:
325
329
            raise errors.BzrCommandError('You must supply either'
326
330
                                         ' --revision or a revision_id')
327
 
        b = WorkingTree.open_containing(directory)[0].branch
 
331
 
 
332
        b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
328
333
 
329
334
        revisions = b.repository.revisions
330
335
        if revisions is None:
408
413
                self.outf.write(page_bytes[:header_end])
409
414
                page_bytes = data
410
415
            self.outf.write('\nPage %d\n' % (page_idx,))
411
 
            decomp_bytes = zlib.decompress(page_bytes)
412
 
            self.outf.write(decomp_bytes)
413
 
            self.outf.write('\n')
 
416
            if len(page_bytes) == 0:
 
417
                self.outf.write('(empty)\n');
 
418
            else:
 
419
                decomp_bytes = zlib.decompress(page_bytes)
 
420
                self.outf.write(decomp_bytes)
 
421
                self.outf.write('\n')
414
422
 
415
423
    def _dump_entries(self, trans, basename):
416
424
        try:
477
485
            d.destroy_workingtree()
478
486
 
479
487
 
 
488
class cmd_repair_workingtree(Command):
 
489
    __doc__ = """Reset the working tree state file.
 
490
 
 
491
    This is not meant to be used normally, but more as a way to recover from
 
492
    filesystem corruption, etc. This rebuilds the working inventory back to a
 
493
    'known good' state. Any new modifications (adding a file, renaming, etc)
 
494
    will be lost, though modified files will still be detected as such.
 
495
 
 
496
    Most users will want something more like "bzr revert" or "bzr update"
 
497
    unless the state file has become corrupted.
 
498
 
 
499
    By default this attempts to recover the current state by looking at the
 
500
    headers of the state file. If the state file is too corrupted to even do
 
501
    that, you can supply --revision to force the state of the tree.
 
502
    """
 
503
 
 
504
    takes_options = ['revision', 'directory',
 
505
        Option('force',
 
506
               help='Reset the tree even if it doesn\'t appear to be'
 
507
                    ' corrupted.'),
 
508
    ]
 
509
    hidden = True
 
510
 
 
511
    def run(self, revision=None, directory='.', force=False):
 
512
        tree, _ = WorkingTree.open_containing(directory)
 
513
        self.add_cleanup(tree.lock_tree_write().unlock)
 
514
        if not force:
 
515
            try:
 
516
                tree.check_state()
 
517
            except errors.BzrError:
 
518
                pass # There seems to be a real error here, so we'll reset
 
519
            else:
 
520
                # Refuse
 
521
                raise errors.BzrCommandError(
 
522
                    'The tree does not appear to be corrupt. You probably'
 
523
                    ' want "bzr revert" instead. Use "--force" if you are'
 
524
                    ' sure you want to reset the working tree.')
 
525
        if revision is None:
 
526
            revision_ids = None
 
527
        else:
 
528
            revision_ids = [r.as_revision_id(tree.branch) for r in revision]
 
529
        try:
 
530
            tree.reset_state(revision_ids)
 
531
        except errors.BzrError, e:
 
532
            if revision_ids is None:
 
533
                extra = (', the header appears corrupt, try passing -r -1'
 
534
                         ' to set the state to the last commit')
 
535
            else:
 
536
                extra = ''
 
537
            raise errors.BzrCommandError('failed to reset the tree state'
 
538
                                         + extra)
 
539
 
 
540
 
480
541
class cmd_revno(Command):
481
542
    __doc__ = """Show current revision number.
482
543
 
923
984
                 "branch.  Local pulls are not applied to "
924
985
                 "the master branch."
925
986
            ),
 
987
        Option('show-base',
 
988
            help="Show base revision text in conflicts.")
926
989
        ]
927
990
    takes_args = ['location?']
928
991
    encoding_type = 'replace'
929
992
 
930
993
    def run(self, location=None, remember=False, overwrite=False,
931
994
            revision=None, verbose=False,
932
 
            directory=None, local=False):
 
995
            directory=None, local=False,
 
996
            show_base=False):
933
997
        # FIXME: too much stuff is in the command class
934
998
        revision_id = None
935
999
        mergeable = None
944
1008
            branch_to = Branch.open_containing(directory)[0]
945
1009
            self.add_cleanup(branch_to.lock_write().unlock)
946
1010
 
 
1011
        if tree_to is None and show_base:
 
1012
            raise errors.BzrCommandError("Need working tree for --show-base.")
 
1013
 
947
1014
        if local and not branch_to.get_bound_location():
948
1015
            raise errors.LocalRequiresBoundBranch()
949
1016
 
994
1061
                view_info=view_info)
995
1062
            result = tree_to.pull(
996
1063
                branch_from, overwrite, revision_id, change_reporter,
997
 
                possible_transports=possible_transports, local=local)
 
1064
                possible_transports=possible_transports, local=local,
 
1065
                show_base=show_base)
998
1066
        else:
999
1067
            result = branch_to.pull(
1000
1068
                branch_from, overwrite, revision_id, local=local)
1004
1072
            log.show_branch_change(
1005
1073
                branch_to, self.outf, result.old_revno,
1006
1074
                result.old_revid)
 
1075
        if getattr(result, 'tag_conflicts', None):
 
1076
            return 1
 
1077
        else:
 
1078
            return 0
1007
1079
 
1008
1080
 
1009
1081
class cmd_push(Command):
1056
1128
        Option('strict',
1057
1129
               help='Refuse to push if there are uncommitted changes in'
1058
1130
               ' the working tree, --no-strict disables the check.'),
 
1131
        Option('no-tree',
 
1132
               help="Don't populate the working tree, even for protocols"
 
1133
               " that support it."),
1059
1134
        ]
1060
1135
    takes_args = ['location?']
1061
1136
    encoding_type = 'replace'
1063
1138
    def run(self, location=None, remember=False, overwrite=False,
1064
1139
        create_prefix=False, verbose=False, revision=None,
1065
1140
        use_existing_dir=False, directory=None, stacked_on=None,
1066
 
        stacked=False, strict=None):
 
1141
        stacked=False, strict=None, no_tree=False):
1067
1142
        from bzrlib.push import _show_push_branch
1068
1143
 
1069
1144
        if directory is None:
1115
1190
        _show_push_branch(br_from, revision_id, location, self.outf,
1116
1191
            verbose=verbose, overwrite=overwrite, remember=remember,
1117
1192
            stacked_on=stacked_on, create_prefix=create_prefix,
1118
 
            use_existing_dir=use_existing_dir)
 
1193
            use_existing_dir=use_existing_dir, no_tree=no_tree)
1119
1194
 
1120
1195
 
1121
1196
class cmd_branch(Command):
1354
1429
    If you want to discard your local changes, you can just do a
1355
1430
    'bzr revert' instead of 'bzr commit' after the update.
1356
1431
 
 
1432
    If you want to restore a file that has been removed locally, use
 
1433
    'bzr revert' instead of 'bzr update'.
 
1434
 
1357
1435
    If the tree's branch is bound to a master branch, it will also update
1358
1436
    the branch from the master.
1359
1437
    """
1360
1438
 
1361
1439
    _see_also = ['pull', 'working-trees', 'status-flags']
1362
1440
    takes_args = ['dir?']
1363
 
    takes_options = ['revision']
 
1441
    takes_options = ['revision',
 
1442
                     Option('show-base',
 
1443
                            help="Show base revision text in conflicts."),
 
1444
                     ]
1364
1445
    aliases = ['up']
1365
1446
 
1366
 
    def run(self, dir='.', revision=None):
 
1447
    def run(self, dir='.', revision=None, show_base=None):
1367
1448
        if revision is not None and len(revision) != 1:
1368
1449
            raise errors.BzrCommandError(
1369
1450
                        "bzr update --revision takes exactly one revision")
1409
1490
                change_reporter,
1410
1491
                possible_transports=possible_transports,
1411
1492
                revision=revision_id,
1412
 
                old_tip=old_tip)
 
1493
                old_tip=old_tip,
 
1494
                show_base=show_base)
1413
1495
        except errors.NoSuchRevision, e:
1414
1496
            raise errors.BzrCommandError(
1415
1497
                                  "branch has no revision %s\n"
1491
1573
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1492
1574
            safe='Backup changed files (default).',
1493
1575
            keep='Delete from bzr but leave the working copy.',
 
1576
            no_backup='Don\'t backup changed files.',
1494
1577
            force='Delete all the specified files, even if they can not be '
1495
 
                'recovered and even if they are non-empty directories.')]
 
1578
                'recovered and even if they are non-empty directories. '
 
1579
                '(deprecated, use no-backup)')]
1496
1580
    aliases = ['rm', 'del']
1497
1581
    encoding_type = 'replace'
1498
1582
 
1499
1583
    def run(self, file_list, verbose=False, new=False,
1500
1584
        file_deletion_strategy='safe'):
 
1585
        if file_deletion_strategy == 'force':
 
1586
            note("(The --force option is deprecated, rather use --no-backup "
 
1587
                "in future.)")
 
1588
            file_deletion_strategy = 'no-backup'
 
1589
 
1501
1590
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1502
1591
 
1503
1592
        if file_list is not None:
1524
1613
            file_deletion_strategy = 'keep'
1525
1614
        tree.remove(file_list, verbose=verbose, to_file=self.outf,
1526
1615
            keep_files=file_deletion_strategy=='keep',
1527
 
            force=file_deletion_strategy=='force')
 
1616
            force=(file_deletion_strategy=='no-backup'))
1528
1617
 
1529
1618
 
1530
1619
class cmd_file_id(Command):
1685
1774
                ),
1686
1775
         Option('append-revisions-only',
1687
1776
                help='Never change revnos or the existing log.'
1688
 
                '  Append revisions to it only.')
 
1777
                '  Append revisions to it only.'),
 
1778
         Option('no-tree',
 
1779
                'Create a branch without a working tree.')
1689
1780
         ]
1690
1781
    def run(self, location=None, format=None, append_revisions_only=False,
1691
 
            create_prefix=False):
 
1782
            create_prefix=False, no_tree=False):
1692
1783
        if format is None:
1693
1784
            format = bzrdir.format_registry.make_bzrdir('default')
1694
1785
        if location is None:
1717
1808
        except errors.NotBranchError:
1718
1809
            # really a NotBzrDir error...
1719
1810
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1811
            if no_tree:
 
1812
                force_new_tree = False
 
1813
            else:
 
1814
                force_new_tree = None
1720
1815
            branch = create_branch(to_transport.base, format=format,
1721
 
                                   possible_transports=[to_transport])
 
1816
                                   possible_transports=[to_transport],
 
1817
                                   force_new_tree=force_new_tree)
1722
1818
            a_bzrdir = branch.bzrdir
1723
1819
        else:
1724
1820
            from bzrlib.transport.local import LocalTransport
1728
1824
                        raise errors.BranchExistsWithoutWorkingTree(location)
1729
1825
                raise errors.AlreadyBranchError(location)
1730
1826
            branch = a_bzrdir.create_branch()
1731
 
            a_bzrdir.create_workingtree()
 
1827
            if not no_tree:
 
1828
                a_bzrdir.create_workingtree()
1732
1829
        if append_revisions_only:
1733
1830
            try:
1734
1831
                branch.set_append_revisions_only(True)
1828
1925
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1829
1926
    produces patches suitable for "patch -p1".
1830
1927
 
 
1928
    Note that when using the -r argument with a range of revisions, the
 
1929
    differences are computed between the two specified revisions.  That
 
1930
    is, the command does not show the changes introduced by the first 
 
1931
    revision in the range.  This differs from the interpretation of 
 
1932
    revision ranges used by "bzr log" which includes the first revision
 
1933
    in the range.
 
1934
 
1831
1935
    :Exit values:
1832
1936
        1 - changed
1833
1937
        2 - unrepresentable changes
1851
1955
 
1852
1956
            bzr diff -r1..3 xxx
1853
1957
 
1854
 
        To see the changes introduced in revision X::
 
1958
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1959
 
 
1960
            bzr diff -c2
 
1961
 
 
1962
        To see the changes introduced by revision X::
1855
1963
        
1856
1964
            bzr diff -cX
1857
1965
 
1861
1969
 
1862
1970
            bzr diff -r<chosen_parent>..X
1863
1971
 
1864
 
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1972
        The changes between the current revision and the previous revision
 
1973
        (equivalent to -c-1 and -r-2..-1)
1865
1974
 
1866
 
            bzr diff -c2
 
1975
            bzr diff -r-2..
1867
1976
 
1868
1977
        Show just the differences for file NEWS::
1869
1978
 
1913
2022
            type=unicode,
1914
2023
            ),
1915
2024
        RegistryOption('format',
 
2025
            short_name='F',
1916
2026
            help='Diff format to use.',
1917
2027
            lazy_registry=('bzrlib.diff', 'format_registry'),
1918
 
            value_switches=False, title='Diff format'),
 
2028
            title='Diff format'),
1919
2029
        ]
1920
2030
    aliases = ['di', 'dif']
1921
2031
    encoding_type = 'exact'
2002
2112
    @display_command
2003
2113
    def run(self, null=False, directory=u'.'):
2004
2114
        tree = WorkingTree.open_containing(directory)[0]
 
2115
        self.add_cleanup(tree.lock_read().unlock)
2005
2116
        td = tree.changes_from(tree.basis_tree())
 
2117
        self.cleanup_now()
2006
2118
        for path, id, kind, text_modified, meta_modified in td.modified:
2007
2119
            if null:
2008
2120
                self.outf.write(path + '\0')
2638
2750
    Patterns prefixed with '!!' act as regular ignore patterns, but have
2639
2751
    precedence over the '!' exception patterns.
2640
2752
 
2641
 
    Note: ignore patterns containing shell wildcards must be quoted from
2642
 
    the shell on Unix.
 
2753
    :Notes: 
 
2754
        
 
2755
    * Ignore patterns containing shell wildcards must be quoted from
 
2756
      the shell on Unix.
 
2757
 
 
2758
    * Ignore patterns starting with "#" act as comments in the ignore file.
 
2759
      To ignore patterns that begin with that character, use the "RE:" prefix.
2643
2760
 
2644
2761
    :Examples:
2645
2762
        Ignore the top level Makefile::
2654
2771
 
2655
2772
            bzr ignore "!special.class"
2656
2773
 
 
2774
        Ignore files whose name begins with the "#" character::
 
2775
 
 
2776
            bzr ignore "RE:^#"
 
2777
 
2657
2778
        Ignore .o files under the lib directory::
2658
2779
 
2659
2780
            bzr ignore "lib/**/*.o"
2801
2922
         zip                          .zip
2802
2923
      =================       =========================
2803
2924
    """
 
2925
    encoding = 'exact'
2804
2926
    takes_args = ['dest', 'branch_or_subdir?']
2805
2927
    takes_options = ['directory',
2806
2928
        Option('format',
3269
3391
 
3270
3392
 
3271
3393
class cmd_upgrade(Command):
3272
 
    __doc__ = """Upgrade branch storage to current format.
3273
 
 
3274
 
    The check command or bzr developers may sometimes advise you to run
3275
 
    this command. When the default format has changed you may also be warned
3276
 
    during other operations to upgrade.
 
3394
    __doc__ = """Upgrade a repository, branch or working tree to a newer format.
 
3395
 
 
3396
    When the default format has changed after a major new release of
 
3397
    Bazaar, you may be informed during certain operations that you
 
3398
    should upgrade. Upgrading to a newer format may improve performance
 
3399
    or make new features available. It may however limit interoperability
 
3400
    with older repositories or with older versions of Bazaar.
 
3401
 
 
3402
    If you wish to upgrade to a particular format rather than the
 
3403
    current default, that can be specified using the --format option.
 
3404
    As a consequence, you can use the upgrade command this way to
 
3405
    "downgrade" to an earlier format, though some conversions are
 
3406
    a one way process (e.g. changing from the 1.x default to the
 
3407
    2.x default) so downgrading is not always possible.
 
3408
 
 
3409
    A backup.bzr.~#~ directory is created at the start of the conversion
 
3410
    process (where # is a number). By default, this is left there on
 
3411
    completion. If the conversion fails, delete the new .bzr directory
 
3412
    and rename this one back in its place. Use the --clean option to ask
 
3413
    for the backup.bzr directory to be removed on successful conversion.
 
3414
    Alternatively, you can delete it by hand if everything looks good
 
3415
    afterwards.
 
3416
 
 
3417
    If the location given is a shared repository, dependent branches
 
3418
    are also converted provided the repository converts successfully.
 
3419
    If the conversion of a branch fails, remaining branches are still
 
3420
    tried.
 
3421
 
 
3422
    For more information on upgrades, see the Bazaar Upgrade Guide,
 
3423
    http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3277
3424
    """
3278
3425
 
3279
 
    _see_also = ['check']
 
3426
    _see_also = ['check', 'reconcile', 'formats']
3280
3427
    takes_args = ['url?']
3281
3428
    takes_options = [
3282
 
                    RegistryOption('format',
3283
 
                        help='Upgrade to a specific format.  See "bzr help'
3284
 
                             ' formats" for details.',
3285
 
                        lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3286
 
                        converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3287
 
                        value_switches=True, title='Branch format'),
3288
 
                    ]
 
3429
        RegistryOption('format',
 
3430
            help='Upgrade to a specific format.  See "bzr help'
 
3431
                 ' formats" for details.',
 
3432
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
 
3433
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3434
            value_switches=True, title='Branch format'),
 
3435
        Option('clean',
 
3436
            help='Remove the backup.bzr directory if successful.'),
 
3437
        Option('dry-run',
 
3438
            help="Show what would be done, but don't actually do anything."),
 
3439
    ]
3289
3440
 
3290
 
    def run(self, url='.', format=None):
 
3441
    def run(self, url='.', format=None, clean=False, dry_run=False):
3291
3442
        from bzrlib.upgrade import upgrade
3292
 
        upgrade(url, format)
 
3443
        exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
 
3444
        if exceptions:
 
3445
            if len(exceptions) == 1:
 
3446
                # Compatibility with historical behavior
 
3447
                raise exceptions[0]
 
3448
            else:
 
3449
                return 3
3293
3450
 
3294
3451
 
3295
3452
class cmd_whoami(Command):
3331
3488
                self.outf.write(c.username() + '\n')
3332
3489
            return
3333
3490
 
 
3491
        if email:
 
3492
            raise errors.BzrCommandError("--email can only be used to display existing "
 
3493
                                         "identity")
 
3494
 
3334
3495
        # display a warning if an email address isn't included in the given name.
3335
3496
        try:
3336
3497
            _mod_config.extract_email_address(name)
3690
3851
    with bzr send. If neither is specified, the default is the upstream branch
3691
3852
    or the branch most recently merged using --remember.
3692
3853
 
3693
 
    When merging a branch, by default the tip will be merged. To pick a different
3694
 
    revision, pass --revision. If you specify two values, the first will be used as
3695
 
    BASE and the second one as OTHER. Merging individual revisions, or a subset of
3696
 
    available revisions, like this is commonly referred to as "cherrypicking".
3697
 
 
3698
 
    Revision numbers are always relative to the branch being merged.
3699
 
 
3700
 
    By default, bzr will try to merge in all new work from the other
3701
 
    branch, automatically determining an appropriate base.  If this
3702
 
    fails, you may need to give an explicit base.
 
3854
    When merging from a branch, by default bzr will try to merge in all new
 
3855
    work from the other branch, automatically determining an appropriate base
 
3856
    revision.  If this fails, you may need to give an explicit base.
 
3857
 
 
3858
    To pick a different ending revision, pass "--revision OTHER".  bzr will
 
3859
    try to merge in all new work up to and including revision OTHER.
 
3860
 
 
3861
    If you specify two values, "--revision BASE..OTHER", only revisions BASE
 
3862
    through OTHER, excluding BASE but including OTHER, will be merged.  If this
 
3863
    causes some revisions to be skipped, i.e. if the destination branch does
 
3864
    not already contain revision BASE, such a merge is commonly referred to as
 
3865
    a "cherrypick".
 
3866
 
 
3867
    Revision numbers are always relative to the source branch.
3703
3868
 
3704
3869
    Merge will do its best to combine the changes in two branches, but there
3705
3870
    are some kinds of problems only a human can fix.  When it encounters those,
3729
3894
    you to apply each diff hunk and file change, similar to "shelve".
3730
3895
 
3731
3896
    :Examples:
3732
 
        To merge the latest revision from bzr.dev::
 
3897
        To merge all new revisions from bzr.dev::
3733
3898
 
3734
3899
            bzr merge ../bzr.dev
3735
3900
 
3969
4134
        if ((remember or tree.branch.get_submit_branch() is None) and
3970
4135
             user_location is not None):
3971
4136
            tree.branch.set_submit_branch(other_branch.base)
3972
 
        _merge_tags_if_possible(other_branch, tree.branch)
 
4137
        # Merge tags (but don't set them in the master branch yet, the user
 
4138
        # might revert this merge).  Commit will propagate them.
 
4139
        _merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
3973
4140
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3974
4141
            other_revision_id, base_revision_id, other_branch, base_branch)
3975
4142
        if other_path != '':
4143
4310
    last committed revision is used.
4144
4311
 
4145
4312
    To remove only some changes, without reverting to a prior version, use
4146
 
    merge instead.  For example, "merge . --revision -2..-3" will remove the
4147
 
    changes introduced by -2, without affecting the changes introduced by -1.
4148
 
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
 
4313
    merge instead.  For example, "merge . -r -2..-3" (don't forget the ".")
 
4314
    will remove the changes introduced by the second last commit (-2), without
 
4315
    affecting the changes introduced by the last commit (-1).  To remove
 
4316
    certain changes on a hunk-by-hunk basis, see the shelve command.
4149
4317
 
4150
4318
    By default, any files that have been manually changed will be backed up
4151
4319
    first.  (Files changed only by merge are not backed up.)  Backup files have
4181
4349
    target branches.
4182
4350
    """
4183
4351
 
4184
 
    _see_also = ['cat', 'export']
 
4352
    _see_also = ['cat', 'export', 'merge', 'shelve']
4185
4353
    takes_options = [
4186
4354
        'revision',
4187
4355
        Option('no-backup', "Do not save backups of reverted files."),
4480
4648
 
4481
4649
    @display_command
4482
4650
    def run(self, verbose=False):
4483
 
        import bzrlib.plugin
4484
 
        from inspect import getdoc
4485
 
        result = []
4486
 
        for name, plugin in bzrlib.plugin.plugins().items():
4487
 
            version = plugin.__version__
4488
 
            if version == 'unknown':
4489
 
                version = ''
4490
 
            name_ver = '%s %s' % (name, version)
4491
 
            d = getdoc(plugin.module)
4492
 
            if d:
4493
 
                doc = d.split('\n')[0]
4494
 
            else:
4495
 
                doc = '(no description)'
4496
 
            result.append((name_ver, doc, plugin.path()))
4497
 
        for name_ver, doc, path in sorted(result):
4498
 
            self.outf.write("%s\n" % name_ver)
4499
 
            self.outf.write("   %s\n" % doc)
4500
 
            if verbose:
4501
 
                self.outf.write("   %s\n" % path)
4502
 
            self.outf.write("\n")
 
4651
        from bzrlib import plugin
 
4652
        self.outf.writelines(
 
4653
            plugin.describe_plugins(show_paths=verbose))
4503
4654
 
4504
4655
 
4505
4656
class cmd_testament(Command):
4567
4718
            self.add_cleanup(branch.lock_read().unlock)
4568
4719
        tree = _get_one_revision_tree('annotate', revision, branch=branch)
4569
4720
        self.add_cleanup(tree.lock_read().unlock)
4570
 
        if wt is not None:
 
4721
        if wt is not None and revision is None:
4571
4722
            file_id = wt.path2id(relpath)
4572
4723
        else:
4573
4724
            file_id = tree.path2id(relpath)
4574
4725
        if file_id is None:
4575
4726
            raise errors.NotVersionedError(filename)
4576
 
        file_version = tree.inventory[file_id].revision
4577
4727
        if wt is not None and revision is None:
4578
4728
            # If there is a tree and we're not annotating historical
4579
4729
            # versions, annotate the working tree's content.
4580
4730
            annotate_file_tree(wt, file_id, self.outf, long, all,
4581
4731
                show_ids=show_ids)
4582
4732
        else:
 
4733
            file_version = tree.inventory[file_id].revision
4583
4734
            annotate_file(branch, file_version, file_id, long, all, self.outf,
4584
4735
                          show_ids=show_ids)
4585
4736
 
4838
4989
    takes_options = [
4839
4990
        Option('config',
4840
4991
               help='LOCATION is the directory where the config lock is.'),
 
4992
        Option('force',
 
4993
            help='Do not ask for confirmation before breaking the lock.'),
4841
4994
        ]
4842
4995
 
4843
 
    def run(self, location=None, config=False):
 
4996
    def run(self, location=None, config=False, force=False):
4844
4997
        if location is None:
4845
4998
            location = u'.'
 
4999
        if force:
 
5000
            ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
 
5001
                None,
 
5002
                {'bzrlib.lockdir.break': True})
4846
5003
        if config:
4847
5004
            conf = _mod_config.LockableConfig(file_name=location)
4848
5005
            conf.break_lock()
4942
5099
    not part of it.  (Such trees can be produced by "bzr split", but also by
4943
5100
    running "bzr branch" with the target inside a tree.)
4944
5101
 
4945
 
    The result is a combined tree, with the subtree no longer an independant
 
5102
    The result is a combined tree, with the subtree no longer an independent
4946
5103
    part.  This is marked as a merge of the subtree into the containing tree,
4947
5104
    and all history is preserved.
4948
5105
    """
5344
5501
            if tag_name is None:
5345
5502
                raise errors.BzrCommandError("No tag specified to delete.")
5346
5503
            branch.tags.delete_tag(tag_name)
5347
 
            self.outf.write('Deleted tag %s.\n' % tag_name)
 
5504
            note('Deleted tag %s.' % tag_name)
5348
5505
        else:
5349
5506
            if revision:
5350
5507
                if len(revision) != 1:
5362
5519
            if (not force) and branch.tags.has_tag(tag_name):
5363
5520
                raise errors.TagAlreadyExists(tag_name)
5364
5521
            branch.tags.set_tag(tag_name, revision_id)
5365
 
            self.outf.write('Created tag %s.\n' % tag_name)
 
5522
            note('Created tag %s.' % tag_name)
5366
5523
 
5367
5524
 
5368
5525
class cmd_tags(Command):
5375
5532
    takes_options = [
5376
5533
        custom_help('directory',
5377
5534
            help='Branch whose tags should be displayed.'),
5378
 
        RegistryOption.from_kwargs('sort',
 
5535
        RegistryOption('sort',
5379
5536
            'Sort tags by different criteria.', title='Sorting',
5380
 
            alpha='Sort tags lexicographically (default).',
5381
 
            time='Sort tags chronologically.',
 
5537
            lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5382
5538
            ),
5383
5539
        'show-ids',
5384
5540
        'revision',
5385
5541
    ]
5386
5542
 
5387
5543
    @display_command
5388
 
    def run(self,
5389
 
            directory='.',
5390
 
            sort='alpha',
5391
 
            show_ids=False,
5392
 
            revision=None,
5393
 
            ):
 
5544
    def run(self, directory='.', sort=None, show_ids=False, revision=None):
 
5545
        from bzrlib.tag import tag_sort_methods
5394
5546
        branch, relpath = Branch.open_containing(directory)
5395
5547
 
5396
5548
        tags = branch.tags.get_tag_dict().items()
5405
5557
            # only show revisions between revid1 and revid2 (inclusive)
5406
5558
            tags = [(tag, revid) for tag, revid in tags if
5407
5559
                graph.is_between(revid, revid1, revid2)]
5408
 
        if sort == 'alpha':
5409
 
            tags.sort()
5410
 
        elif sort == 'time':
5411
 
            timestamps = {}
5412
 
            for tag, revid in tags:
5413
 
                try:
5414
 
                    revobj = branch.repository.get_revision(revid)
5415
 
                except errors.NoSuchRevision:
5416
 
                    timestamp = sys.maxint # place them at the end
5417
 
                else:
5418
 
                    timestamp = revobj.timestamp
5419
 
                timestamps[revid] = timestamp
5420
 
            tags.sort(key=lambda x: timestamps[x[1]])
 
5560
        if sort is None:
 
5561
            sort = tag_sort_methods.get()
 
5562
        sort(branch, tags)
5421
5563
        if not show_ids:
5422
5564
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5423
5565
            for index, (tag, revid) in enumerate(tags):
5425
5567
                    revno = branch.revision_id_to_dotted_revno(revid)
5426
5568
                    if isinstance(revno, tuple):
5427
5569
                        revno = '.'.join(map(str, revno))
5428
 
                except errors.NoSuchRevision:
 
5570
                except (errors.NoSuchRevision, errors.GhostRevisionsHaveNoRevno):
5429
5571
                    # Bad tag data/merges can lead to tagged revisions
5430
5572
                    # which are not in this branch. Fail gracefully ...
5431
5573
                    revno = '?'
5821
5963
            location = "."
5822
5964
        branch = Branch.open_containing(location)[0]
5823
5965
        branch.bzrdir.destroy_branch()
5824
 
        
 
5966
 
5825
5967
 
5826
5968
class cmd_shelve(Command):
5827
5969
    __doc__ = """Temporarily set aside some changes from the current tree.
5846
5988
 
5847
5989
    You can put multiple items on the shelf, and by default, 'unshelve' will
5848
5990
    restore the most recently shelved changes.
 
5991
 
 
5992
    For complicated changes, it is possible to edit the changes in a separate
 
5993
    editor program to decide what the file remaining in the working copy
 
5994
    should look like.  To do this, add the configuration option
 
5995
 
 
5996
        change_editor = PROGRAM @new_path @old_path
 
5997
 
 
5998
    where @new_path is replaced with the path of the new version of the 
 
5999
    file and @old_path is replaced with the path of the old version of 
 
6000
    the file.  The PROGRAM should save the new file with the desired 
 
6001
    contents of the file in the working tree.
 
6002
        
5849
6003
    """
5850
6004
 
5851
6005
    takes_args = ['file*']
5863
6017
        Option('destroy',
5864
6018
               help='Destroy removed changes instead of shelving them.'),
5865
6019
    ]
5866
 
    _see_also = ['unshelve']
 
6020
    _see_also = ['unshelve', 'configuration']
5867
6021
 
5868
6022
    def run(self, revision=None, all=False, file_list=None, message=None,
5869
 
            writer=None, list=False, destroy=False, directory=u'.'):
 
6023
            writer=None, list=False, destroy=False, directory=None):
5870
6024
        if list:
5871
 
            return self.run_for_list()
 
6025
            return self.run_for_list(directory=directory)
5872
6026
        from bzrlib.shelf_ui import Shelver
5873
6027
        if writer is None:
5874
6028
            writer = bzrlib.option.diff_writer_registry.get()
5882
6036
        except errors.UserAbort:
5883
6037
            return 0
5884
6038
 
5885
 
    def run_for_list(self):
5886
 
        tree = WorkingTree.open_containing('.')[0]
 
6039
    def run_for_list(self, directory=None):
 
6040
        if directory is None:
 
6041
            directory = u'.'
 
6042
        tree = WorkingTree.open_containing(directory)[0]
5887
6043
        self.add_cleanup(tree.lock_read().unlock)
5888
6044
        manager = tree.get_shelf_manager()
5889
6045
        shelves = manager.active_shelves()
5948
6104
    """
5949
6105
    takes_options = ['directory',
5950
6106
                     Option('ignored', help='Delete all ignored files.'),
5951
 
                     Option('detritus', help='Delete conflict files, merge'
 
6107
                     Option('detritus', help='Delete conflict files, merge and revert'
5952
6108
                            ' backups, and failed selftest dirs.'),
5953
6109
                     Option('unknown',
5954
6110
                            help='Delete files unknown to bzr (default).'),
6018
6174
    # be only called once.
6019
6175
    for (name, aliases, module_name) in [
6020
6176
        ('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
 
6177
        ('cmd_config', [], 'bzrlib.config'),
6021
6178
        ('cmd_dpush', [], 'bzrlib.foreign'),
6022
6179
        ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6023
6180
        ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6024
6181
        ('cmd_conflicts', [], 'bzrlib.conflicts'),
6025
6182
        ('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
 
6183
        ('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6026
6184
        ]:
6027
6185
        builtin_command_registry.register_lazy(name, aliases, module_name)