~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
import cStringIO
 
24
import itertools
 
25
import re
24
26
import sys
25
27
import time
26
28
 
250
252
    To skip the display of pending merge information altogether, use
251
253
    the no-pending option or specify a file/directory.
252
254
 
253
 
    If a revision argument is given, the status is calculated against
254
 
    that revision, or between two revisions if two are provided.
 
255
    To compare the working directory to a specific revision, pass a
 
256
    single revision to the revision argument.
 
257
 
 
258
    To see which files have changed in a specific revision, or between
 
259
    two revisions, pass a revision range to the revision argument.
 
260
    This will produce the same results as calling 'bzr diff --summarize'.
255
261
    """
256
262
 
257
263
    # TODO: --no-recurse, --recurse options
923
929
                 "branch.  Local pulls are not applied to "
924
930
                 "the master branch."
925
931
            ),
 
932
        Option('show-base',
 
933
            help="Show base revision text in conflicts.")
926
934
        ]
927
935
    takes_args = ['location?']
928
936
    encoding_type = 'replace'
929
937
 
930
938
    def run(self, location=None, remember=False, overwrite=False,
931
939
            revision=None, verbose=False,
932
 
            directory=None, local=False):
 
940
            directory=None, local=False,
 
941
            show_base=False):
933
942
        # FIXME: too much stuff is in the command class
934
943
        revision_id = None
935
944
        mergeable = None
944
953
            branch_to = Branch.open_containing(directory)[0]
945
954
            self.add_cleanup(branch_to.lock_write().unlock)
946
955
 
 
956
        if tree_to is None and show_base:
 
957
            raise errors.BzrCommandError("Need working tree for --show-base.")
 
958
 
947
959
        if local and not branch_to.get_bound_location():
948
960
            raise errors.LocalRequiresBoundBranch()
949
961
 
994
1006
                view_info=view_info)
995
1007
            result = tree_to.pull(
996
1008
                branch_from, overwrite, revision_id, change_reporter,
997
 
                possible_transports=possible_transports, local=local)
 
1009
                possible_transports=possible_transports, local=local,
 
1010
                show_base=show_base)
998
1011
        else:
999
1012
            result = branch_to.pull(
1000
1013
                branch_from, overwrite, revision_id, local=local)
1056
1069
        Option('strict',
1057
1070
               help='Refuse to push if there are uncommitted changes in'
1058
1071
               ' the working tree, --no-strict disables the check.'),
 
1072
        Option('no-tree',
 
1073
               help="Don't populate the working tree, even for protocols"
 
1074
               " that support it."),
1059
1075
        ]
1060
1076
    takes_args = ['location?']
1061
1077
    encoding_type = 'replace'
1063
1079
    def run(self, location=None, remember=False, overwrite=False,
1064
1080
        create_prefix=False, verbose=False, revision=None,
1065
1081
        use_existing_dir=False, directory=None, stacked_on=None,
1066
 
        stacked=False, strict=None):
 
1082
        stacked=False, strict=None, no_tree=False):
1067
1083
        from bzrlib.push import _show_push_branch
1068
1084
 
1069
1085
        if directory is None:
1115
1131
        _show_push_branch(br_from, revision_id, location, self.outf,
1116
1132
            verbose=verbose, overwrite=overwrite, remember=remember,
1117
1133
            stacked_on=stacked_on, create_prefix=create_prefix,
1118
 
            use_existing_dir=use_existing_dir)
 
1134
            use_existing_dir=use_existing_dir, no_tree=no_tree)
1119
1135
 
1120
1136
 
1121
1137
class cmd_branch(Command):
1354
1370
    If you want to discard your local changes, you can just do a
1355
1371
    'bzr revert' instead of 'bzr commit' after the update.
1356
1372
 
 
1373
    If you want to restore a file that has been removed locally, use
 
1374
    'bzr revert' instead of 'bzr update'.
 
1375
 
1357
1376
    If the tree's branch is bound to a master branch, it will also update
1358
1377
    the branch from the master.
1359
1378
    """
1360
1379
 
1361
1380
    _see_also = ['pull', 'working-trees', 'status-flags']
1362
1381
    takes_args = ['dir?']
1363
 
    takes_options = ['revision']
 
1382
    takes_options = ['revision',
 
1383
                     Option('show-base',
 
1384
                            help="Show base revision text in conflicts."),
 
1385
                     ]
1364
1386
    aliases = ['up']
1365
1387
 
1366
 
    def run(self, dir='.', revision=None):
 
1388
    def run(self, dir='.', revision=None, show_base=None):
1367
1389
        if revision is not None and len(revision) != 1:
1368
1390
            raise errors.BzrCommandError(
1369
1391
                        "bzr update --revision takes exactly one revision")
1409
1431
                change_reporter,
1410
1432
                possible_transports=possible_transports,
1411
1433
                revision=revision_id,
1412
 
                old_tip=old_tip)
 
1434
                old_tip=old_tip,
 
1435
                show_base=show_base)
1413
1436
        except errors.NoSuchRevision, e:
1414
1437
            raise errors.BzrCommandError(
1415
1438
                                  "branch has no revision %s\n"
1491
1514
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1492
1515
            safe='Backup changed files (default).',
1493
1516
            keep='Delete from bzr but leave the working copy.',
 
1517
            no_backup='Don\'t backup changed files.',
1494
1518
            force='Delete all the specified files, even if they can not be '
1495
 
                'recovered and even if they are non-empty directories.')]
 
1519
                'recovered and even if they are non-empty directories. '
 
1520
                '(deprecated, use no-backup)')]
1496
1521
    aliases = ['rm', 'del']
1497
1522
    encoding_type = 'replace'
1498
1523
 
1499
1524
    def run(self, file_list, verbose=False, new=False,
1500
1525
        file_deletion_strategy='safe'):
 
1526
        if file_deletion_strategy == 'force':
 
1527
            note("(The --force option is deprecated, rather use --no-backup "
 
1528
                "in future.)")
 
1529
            file_deletion_strategy = 'no-backup'
 
1530
 
1501
1531
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1502
1532
 
1503
1533
        if file_list is not None:
1524
1554
            file_deletion_strategy = 'keep'
1525
1555
        tree.remove(file_list, verbose=verbose, to_file=self.outf,
1526
1556
            keep_files=file_deletion_strategy=='keep',
1527
 
            force=file_deletion_strategy=='force')
 
1557
            force=(file_deletion_strategy=='no-backup'))
1528
1558
 
1529
1559
 
1530
1560
class cmd_file_id(Command):
1685
1715
                ),
1686
1716
         Option('append-revisions-only',
1687
1717
                help='Never change revnos or the existing log.'
1688
 
                '  Append revisions to it only.')
 
1718
                '  Append revisions to it only.'),
 
1719
         Option('no-tree',
 
1720
                'Create a branch without a working tree.')
1689
1721
         ]
1690
1722
    def run(self, location=None, format=None, append_revisions_only=False,
1691
 
            create_prefix=False):
 
1723
            create_prefix=False, no_tree=False):
1692
1724
        if format is None:
1693
1725
            format = bzrdir.format_registry.make_bzrdir('default')
1694
1726
        if location is None:
1717
1749
        except errors.NotBranchError:
1718
1750
            # really a NotBzrDir error...
1719
1751
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1752
            if no_tree:
 
1753
                force_new_tree = False
 
1754
            else:
 
1755
                force_new_tree = None
1720
1756
            branch = create_branch(to_transport.base, format=format,
1721
 
                                   possible_transports=[to_transport])
 
1757
                                   possible_transports=[to_transport],
 
1758
                                   force_new_tree=force_new_tree)
1722
1759
            a_bzrdir = branch.bzrdir
1723
1760
        else:
1724
1761
            from bzrlib.transport.local import LocalTransport
1728
1765
                        raise errors.BranchExistsWithoutWorkingTree(location)
1729
1766
                raise errors.AlreadyBranchError(location)
1730
1767
            branch = a_bzrdir.create_branch()
1731
 
            a_bzrdir.create_workingtree()
 
1768
            if not no_tree:
 
1769
                a_bzrdir.create_workingtree()
1732
1770
        if append_revisions_only:
1733
1771
            try:
1734
1772
                branch.set_append_revisions_only(True)
1828
1866
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1829
1867
    produces patches suitable for "patch -p1".
1830
1868
 
 
1869
    Note that when using the -r argument with a range of revisions, the
 
1870
    differences are computed between the two specified revisions.  That
 
1871
    is, the command does not show the changes introduced by the first 
 
1872
    revision in the range.  This differs from the interpretation of 
 
1873
    revision ranges used by "bzr log" which includes the first revision
 
1874
    in the range.
 
1875
 
1831
1876
    :Exit values:
1832
1877
        1 - changed
1833
1878
        2 - unrepresentable changes
1851
1896
 
1852
1897
            bzr diff -r1..3 xxx
1853
1898
 
1854
 
        To see the changes introduced in revision X::
 
1899
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1900
 
 
1901
            bzr diff -c2
 
1902
 
 
1903
        To see the changes introduced by revision X::
1855
1904
        
1856
1905
            bzr diff -cX
1857
1906
 
1861
1910
 
1862
1911
            bzr diff -r<chosen_parent>..X
1863
1912
 
1864
 
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1913
        The changes between the current revision and the previous revision
 
1914
        (equivalent to -c-1 and -r-2..-1)
1865
1915
 
1866
 
            bzr diff -c2
 
1916
            bzr diff -r-2..
1867
1917
 
1868
1918
        Show just the differences for file NEWS::
1869
1919
 
2638
2688
    Patterns prefixed with '!!' act as regular ignore patterns, but have
2639
2689
    precedence over the '!' exception patterns.
2640
2690
 
2641
 
    Note: ignore patterns containing shell wildcards must be quoted from
2642
 
    the shell on Unix.
 
2691
    :Notes: 
 
2692
        
 
2693
    * Ignore patterns containing shell wildcards must be quoted from
 
2694
      the shell on Unix.
 
2695
 
 
2696
    * Ignore patterns starting with "#" act as comments in the ignore file.
 
2697
      To ignore patterns that begin with that character, use the "RE:" prefix.
2643
2698
 
2644
2699
    :Examples:
2645
2700
        Ignore the top level Makefile::
2654
2709
 
2655
2710
            bzr ignore "!special.class"
2656
2711
 
 
2712
        Ignore files whose name begins with the "#" character::
 
2713
 
 
2714
            bzr ignore "RE:^#"
 
2715
 
2657
2716
        Ignore .o files under the lib directory::
2658
2717
 
2659
2718
            bzr ignore "lib/**/*.o"
3481
3540
    If you set BZR_TEST_PDB=1 when running selftest, failing tests will drop
3482
3541
    into a pdb postmortem session.
3483
3542
 
 
3543
    The --coverage=DIRNAME global option produces a report with covered code
 
3544
    indicated.
 
3545
 
3484
3546
    :Examples:
3485
3547
        Run only tests relating to 'ignore'::
3486
3548
 
3687
3749
    with bzr send. If neither is specified, the default is the upstream branch
3688
3750
    or the branch most recently merged using --remember.
3689
3751
 
3690
 
    When merging a branch, by default the tip will be merged. To pick a different
3691
 
    revision, pass --revision. If you specify two values, the first will be used as
3692
 
    BASE and the second one as OTHER. Merging individual revisions, or a subset of
3693
 
    available revisions, like this is commonly referred to as "cherrypicking".
3694
 
 
3695
 
    Revision numbers are always relative to the branch being merged.
3696
 
 
3697
 
    By default, bzr will try to merge in all new work from the other
3698
 
    branch, automatically determining an appropriate base.  If this
3699
 
    fails, you may need to give an explicit base.
 
3752
    When merging from a branch, by default bzr will try to merge in all new
 
3753
    work from the other branch, automatically determining an appropriate base
 
3754
    revision.  If this fails, you may need to give an explicit base.
 
3755
 
 
3756
    To pick a different ending revision, pass "--revision OTHER".  bzr will
 
3757
    try to merge in all new work up to and including revision OTHER.
 
3758
 
 
3759
    If you specify two values, "--revision BASE..OTHER", only revisions BASE
 
3760
    through OTHER, excluding BASE but including OTHER, will be merged.  If this
 
3761
    causes some revisions to be skipped, i.e. if the destination branch does
 
3762
    not already contain revision BASE, such a merge is commonly referred to as
 
3763
    a "cherrypick".
 
3764
 
 
3765
    Revision numbers are always relative to the source branch.
3700
3766
 
3701
3767
    Merge will do its best to combine the changes in two branches, but there
3702
3768
    are some kinds of problems only a human can fix.  When it encounters those,
3726
3792
    you to apply each diff hunk and file change, similar to "shelve".
3727
3793
 
3728
3794
    :Examples:
3729
 
        To merge the latest revision from bzr.dev::
 
3795
        To merge all new revisions from bzr.dev::
3730
3796
 
3731
3797
            bzr merge ../bzr.dev
3732
3798
 
3966
4032
        if ((remember or tree.branch.get_submit_branch() is None) and
3967
4033
             user_location is not None):
3968
4034
            tree.branch.set_submit_branch(other_branch.base)
3969
 
        _merge_tags_if_possible(other_branch, tree.branch)
 
4035
        # Merge tags (but don't set them in the master branch yet, the user
 
4036
        # might revert this merge).  Commit will propagate them.
 
4037
        _merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
3970
4038
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3971
4039
            other_revision_id, base_revision_id, other_branch, base_branch)
3972
4040
        if other_path != '':
4140
4208
    last committed revision is used.
4141
4209
 
4142
4210
    To remove only some changes, without reverting to a prior version, use
4143
 
    merge instead.  For example, "merge . --revision -2..-3" will remove the
4144
 
    changes introduced by -2, without affecting the changes introduced by -1.
4145
 
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
 
4211
    merge instead.  For example, "merge . -r -2..-3" (don't forget the ".")
 
4212
    will remove the changes introduced by the second last commit (-2), without
 
4213
    affecting the changes introduced by the last commit (-1).  To remove
 
4214
    certain changes on a hunk-by-hunk basis, see the shelve command.
4146
4215
 
4147
4216
    By default, any files that have been manually changed will be backed up
4148
4217
    first.  (Files changed only by merge are not backed up.)  Backup files have
4178
4247
    target branches.
4179
4248
    """
4180
4249
 
4181
 
    _see_also = ['cat', 'export']
 
4250
    _see_also = ['cat', 'export', 'merge', 'shelve']
4182
4251
    takes_options = [
4183
4252
        'revision',
4184
4253
        Option('no-backup', "Do not save backups of reverted files."),
4798
4867
            self.outf.write('The above revision(s) will be removed.\n')
4799
4868
 
4800
4869
        if not force:
4801
 
            if not ui.ui_factory.get_boolean('Are you sure'):
4802
 
                self.outf.write('Canceled')
 
4870
            if not ui.ui_factory.confirm_action(
 
4871
                    'Uncommit these revisions',
 
4872
                    'bzrlib.builtins.uncommit',
 
4873
                    {}):
 
4874
                self.outf.write('Canceled\n')
4803
4875
                return 0
4804
4876
 
4805
4877
        mutter('Uncommitting from {%s} to {%s}',
4832
4904
    takes_options = [
4833
4905
        Option('config',
4834
4906
               help='LOCATION is the directory where the config lock is.'),
 
4907
        Option('force',
 
4908
            help='Do not ask for confirmation before breaking the lock.'),
4835
4909
        ]
4836
4910
 
4837
 
    def run(self, location=None, config=False):
 
4911
    def run(self, location=None, config=False, force=False):
4838
4912
        if location is None:
4839
4913
            location = u'.'
 
4914
        if force:
 
4915
            ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
 
4916
                None,
 
4917
                {'bzrlib.lockdir.break': True})
4840
4918
        if config:
4841
4919
            conf = _mod_config.LockableConfig(file_name=location)
4842
4920
            conf.break_lock()
4936
5014
    not part of it.  (Such trees can be produced by "bzr split", but also by
4937
5015
    running "bzr branch" with the target inside a tree.)
4938
5016
 
4939
 
    The result is a combined tree, with the subtree no longer an independant
 
5017
    The result is a combined tree, with the subtree no longer an independent
4940
5018
    part.  This is marked as a merge of the subtree into the containing tree,
4941
5019
    and all history is preserved.
4942
5020
    """
5338
5416
            if tag_name is None:
5339
5417
                raise errors.BzrCommandError("No tag specified to delete.")
5340
5418
            branch.tags.delete_tag(tag_name)
5341
 
            self.outf.write('Deleted tag %s.\n' % tag_name)
 
5419
            note('Deleted tag %s.' % tag_name)
5342
5420
        else:
5343
5421
            if revision:
5344
5422
                if len(revision) != 1:
5356
5434
            if (not force) and branch.tags.has_tag(tag_name):
5357
5435
                raise errors.TagAlreadyExists(tag_name)
5358
5436
            branch.tags.set_tag(tag_name, revision_id)
5359
 
            self.outf.write('Created tag %s.\n' % tag_name)
 
5437
            note('Created tag %s.' % tag_name)
5360
5438
 
5361
5439
 
5362
5440
class cmd_tags(Command):
5371
5449
            help='Branch whose tags should be displayed.'),
5372
5450
        RegistryOption.from_kwargs('sort',
5373
5451
            'Sort tags by different criteria.', title='Sorting',
5374
 
            alpha='Sort tags lexicographically (default).',
 
5452
            natural='Sort numeric substrings as numbers:'
 
5453
                    ' suitable for version numbers. (default)',
 
5454
            alpha='Sort tags lexicographically.',
5375
5455
            time='Sort tags chronologically.',
5376
5456
            ),
5377
5457
        'show-ids',
5381
5461
    @display_command
5382
5462
    def run(self,
5383
5463
            directory='.',
5384
 
            sort='alpha',
 
5464
            sort='natural',
5385
5465
            show_ids=False,
5386
5466
            revision=None,
5387
5467
            ):
5399
5479
            # only show revisions between revid1 and revid2 (inclusive)
5400
5480
            tags = [(tag, revid) for tag, revid in tags if
5401
5481
                graph.is_between(revid, revid1, revid2)]
5402
 
        if sort == 'alpha':
 
5482
        if sort == 'natural':
 
5483
            def natural_sort_key(tag):
 
5484
                return [f(s) for f,s in 
 
5485
                        zip(itertools.cycle((unicode.lower,int)),
 
5486
                                            re.split('([0-9]+)', tag[0]))]
 
5487
            tags.sort(key=natural_sort_key)
 
5488
        elif sort == 'alpha':
5403
5489
            tags.sort()
5404
5490
        elif sort == 'time':
5405
5491
            timestamps = {}
5815
5901
            location = "."
5816
5902
        branch = Branch.open_containing(location)[0]
5817
5903
        branch.bzrdir.destroy_branch()
5818
 
        
 
5904
 
5819
5905
 
5820
5906
class cmd_shelve(Command):
5821
5907
    __doc__ = """Temporarily set aside some changes from the current tree.
5840
5926
 
5841
5927
    You can put multiple items on the shelf, and by default, 'unshelve' will
5842
5928
    restore the most recently shelved changes.
 
5929
 
 
5930
    For complicated changes, it is possible to edit the changes in a separate
 
5931
    editor program to decide what the file remaining in the working copy
 
5932
    should look like.  To do this, add the configuration option
 
5933
 
 
5934
        change_editor = PROGRAM @new_path @old_path
 
5935
 
 
5936
    where @new_path is replaced with the path of the new version of the 
 
5937
    file and @old_path is replaced with the path of the old version of 
 
5938
    the file.  The PROGRAM should save the new file with the desired 
 
5939
    contents of the file in the working tree.
 
5940
        
5843
5941
    """
5844
5942
 
5845
5943
    takes_args = ['file*']
5857
5955
        Option('destroy',
5858
5956
               help='Destroy removed changes instead of shelving them.'),
5859
5957
    ]
5860
 
    _see_also = ['unshelve']
 
5958
    _see_also = ['unshelve', 'configuration']
5861
5959
 
5862
5960
    def run(self, revision=None, all=False, file_list=None, message=None,
5863
 
            writer=None, list=False, destroy=False, directory=u'.'):
 
5961
            writer=None, list=False, destroy=False, directory=None):
5864
5962
        if list:
5865
 
            return self.run_for_list()
 
5963
            return self.run_for_list(directory=directory)
5866
5964
        from bzrlib.shelf_ui import Shelver
5867
5965
        if writer is None:
5868
5966
            writer = bzrlib.option.diff_writer_registry.get()
5876
5974
        except errors.UserAbort:
5877
5975
            return 0
5878
5976
 
5879
 
    def run_for_list(self):
5880
 
        tree = WorkingTree.open_containing('.')[0]
 
5977
    def run_for_list(self, directory=None):
 
5978
        if directory is None:
 
5979
            directory = u'.'
 
5980
        tree = WorkingTree.open_containing(directory)[0]
5881
5981
        self.add_cleanup(tree.lock_read().unlock)
5882
5982
        manager = tree.get_shelf_manager()
5883
5983
        shelves = manager.active_shelves()
6012
6112
    # be only called once.
6013
6113
    for (name, aliases, module_name) in [
6014
6114
        ('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
 
6115
        ('cmd_config', [], 'bzrlib.config'),
6015
6116
        ('cmd_dpush', [], 'bzrlib.foreign'),
6016
6117
        ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6017
6118
        ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6018
6119
        ('cmd_conflicts', [], 'bzrlib.conflicts'),
6019
6120
        ('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
 
6121
        ('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6020
6122
        ]:
6021
6123
        builtin_command_registry.register_lazy(name, aliases, module_name)