~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

remove all trailing whitespace from bzr source

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
 
95
95
    The filenames given are not required to exist.
96
96
 
97
 
    :param file_list: Filenames to convert.  
 
97
    :param file_list: Filenames to convert.
98
98
 
99
99
    :param default_branch: Fallback tree path to use if file_list is empty or
100
100
        None.
168
168
 
169
169
    To see ignored files use 'bzr ignored'.  For details on the
170
170
    changes to file texts, use 'bzr diff'.
171
 
    
 
171
 
172
172
    Note that --short or -S gives status flags for each item, similar
173
173
    to Subversion's status command. To get output similar to svn -q,
174
174
    use bzr status -SV.
186
186
    If a revision argument is given, the status is calculated against
187
187
    that revision, or between two revisions if two are provided.
188
188
    """
189
 
    
 
189
 
190
190
    # TODO: --no-recurse, --recurse options
191
 
    
 
191
 
192
192
    takes_args = ['file*']
193
193
    takes_options = ['show-ids', 'revision', 'change', 'verbose',
194
194
                     Option('short', help='Use short status indicators.',
202
202
 
203
203
    encoding_type = 'replace'
204
204
    _see_also = ['diff', 'revert', 'status-flags']
205
 
    
 
205
 
206
206
    @display_command
207
207
    def run(self, show_ids=False, file_list=None, revision=None, short=False,
208
208
            versioned=False, no_pending=False, verbose=False):
230
230
 
231
231
class cmd_cat_revision(Command):
232
232
    """Write out metadata for a revision.
233
 
    
 
233
 
234
234
    The revision to print can either be specified by a specific
235
235
    revision identifier, or you can use --revision.
236
236
    """
240
240
    takes_options = ['revision']
241
241
    # cat-revision is more for frontends so should be exact
242
242
    encoding = 'strict'
243
 
    
 
243
 
244
244
    @display_command
245
245
    def run(self, revision_id=None, revision=None):
246
246
        if revision_id is not None and revision is not None:
361
361
 
362
362
    def run(self, location='.', force=False):
363
363
        d = bzrdir.BzrDir.open(location)
364
 
        
 
364
 
365
365
        try:
366
366
            working = d.open_workingtree()
367
367
        except errors.NoWorkingTree:
379
379
        if working_path != branch_path:
380
380
            raise errors.BzrCommandError("You cannot remove the working tree from "
381
381
                                         "a lightweight checkout")
382
 
        
 
382
 
383
383
        d.destroy_workingtree()
384
 
        
 
384
 
385
385
 
386
386
class cmd_revno(Command):
387
387
    """Show current revision number.
437
437
                revno = '.'.join(str(i) for i in dotted_map[revision_id])
438
438
            print '%s %s' % (revno, revision_id)
439
439
 
440
 
    
 
440
 
441
441
class cmd_add(Command):
442
442
    """Add specified files or directories.
443
443
 
461
461
    you should never need to explicitly add a directory, they'll just
462
462
    get added when you add a file in the directory.
463
463
 
464
 
    --dry-run will show which files would be added, but not actually 
 
464
    --dry-run will show which files would be added, but not actually
465
465
    add them.
466
466
 
467
467
    --file-ids-from will try to use the file ids from the supplied path.
523
523
            if verbose:
524
524
                for glob in sorted(ignored.keys()):
525
525
                    for path in ignored[glob]:
526
 
                        self.outf.write("ignored %s matching \"%s\"\n" 
 
526
                        self.outf.write("ignored %s matching \"%s\"\n"
527
527
                                        % (path, glob))
528
528
            else:
529
529
                match_len = 0
556
556
 
557
557
    takes_args = ['filename']
558
558
    hidden = True
559
 
    
 
559
 
560
560
    @display_command
561
561
    def run(self, filename):
562
562
        # TODO: jam 20050106 Can relpath return a munged path if
736
736
                        # pathjoin with an empty tail adds a slash, which breaks
737
737
                        # relpath :(
738
738
                        dest_parent_fq = tree.basedir
739
 
    
 
739
 
740
740
                    dest_tail = osutils.canonical_relpath(
741
741
                                    dest_parent_fq,
742
742
                                    osutils.pathjoin(dest_parent_fq, spec_tail))
868
868
 
869
869
class cmd_push(Command):
870
870
    """Update a mirror of this branch.
871
 
    
 
871
 
872
872
    The target branch will not have its working tree populated because this
873
873
    is both expensive, and is not supported on remote file systems.
874
 
    
 
874
 
875
875
    Some smart servers or protocols *may* put the working tree in place in
876
876
    the future.
877
877
 
881
881
 
882
882
    If branches have diverged, you can use 'bzr push --overwrite' to replace
883
883
    the other branch completely, discarding its unmerged changes.
884
 
    
 
884
 
885
885
    If you want to ensure you have the different changes in the other branch,
886
886
    do a merge (see bzr help merge) from the other branch, and commit that.
887
887
    After that you will be able to do a push without '--overwrite'.
1068
1068
    the branch found in '.'. This is useful if you have removed the working tree
1069
1069
    or if it was never created - i.e. if you pushed the branch to its current
1070
1070
    location using SFTP.
1071
 
    
 
1071
 
1072
1072
    If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
1073
1073
    be used.  In other words, "checkout ../foo/bar" will attempt to create ./bar.
1074
1074
    If the BRANCH_LOCATION has no / or path separator embedded, the TO_LOCATION
1120
1120
            revision_id = None
1121
1121
        if to_location is None:
1122
1122
            to_location = urlutils.derive_to_location(branch_location)
1123
 
        # if the source and to_location are the same, 
 
1123
        # if the source and to_location are the same,
1124
1124
        # and there is no working tree,
1125
1125
        # then reconstitute a branch
1126
1126
        if (osutils.abspath(to_location) ==
1172
1172
 
1173
1173
class cmd_update(Command):
1174
1174
    """Update a tree to have the latest code committed to its branch.
1175
 
    
 
1175
 
1176
1176
    This will perform a merge into the working tree, and may generate
1177
 
    conflicts. If you have any local changes, you will still 
 
1177
    conflicts. If you have any local changes, you will still
1178
1178
    need to commit them after the update for the update to be complete.
1179
 
    
1180
 
    If you want to discard your local changes, you can just do a 
 
1179
 
 
1180
    If you want to discard your local changes, you can just do a
1181
1181
    'bzr revert' instead of 'bzr commit' after the update.
1182
1182
    """
1183
1183
 
1352
1352
 
1353
1353
    This can correct data mismatches that may have been caused by
1354
1354
    previous ghost operations or bzr upgrades. You should only
1355
 
    need to run this command if 'bzr check' or a bzr developer 
 
1355
    need to run this command if 'bzr check' or a bzr developer
1356
1356
    advises you to run it.
1357
1357
 
1358
1358
    If a second branch is provided, cross-branch reconciliation is
1360
1360
    id which was not present in very early bzr versions is represented
1361
1361
    correctly in both branches.
1362
1362
 
1363
 
    At the same time it is run it may recompress data resulting in 
 
1363
    At the same time it is run it may recompress data resulting in
1364
1364
    a potential saving in disk space or performance gain.
1365
1365
 
1366
1366
    The branch *MUST* be on a listable system such as local disk or sftp.
1422
1422
    Use this to create an empty branch, or before importing an
1423
1423
    existing project.
1424
1424
 
1425
 
    If there is a repository in a parent directory of the location, then 
 
1425
    If there is a repository in a parent directory of the location, then
1426
1426
    the history of the branch will be stored in the repository.  Otherwise
1427
1427
    init creates a standalone branch which carries its own history
1428
1428
    in the .bzr directory.
1581
1581
 
1582
1582
class cmd_diff(Command):
1583
1583
    """Show differences in the working tree, between revisions or branches.
1584
 
    
 
1584
 
1585
1585
    If no arguments are given, all changes for the current tree are listed.
1586
1586
    If files are given, only the changes in those files are listed.
1587
1587
    Remote and multiple branches can be compared by using the --old and
1687
1687
 
1688
1688
        old_tree, new_tree, specific_files, extra_trees = \
1689
1689
                _get_trees_to_diff(file_list, revision, old, new)
1690
 
        return show_diff_trees(old_tree, new_tree, sys.stdout, 
 
1690
        return show_diff_trees(old_tree, new_tree, sys.stdout,
1691
1691
                               specific_files=specific_files,
1692
1692
                               external_diff_options=diff_options,
1693
1693
                               old_label=old_label, new_label=new_label,
1904
1904
                        location)
1905
1905
        else:
1906
1906
            # local dir only
1907
 
            # FIXME ? log the current subdir only RBC 20060203 
 
1907
            # FIXME ? log the current subdir only RBC 20060203
1908
1908
            if revision is not None \
1909
1909
                    and len(revision) > 0 and revision[0].get_branch():
1910
1910
                location = revision[0].get_branch()
2111
2111
    using this command or directly by using an editor, be sure to commit
2112
2112
    it.
2113
2113
 
2114
 
    Note: ignore patterns containing shell wildcards must be quoted from 
 
2114
    Note: ignore patterns containing shell wildcards must be quoted from
2115
2115
    the shell on Unix.
2116
2116
 
2117
2117
    :Examples:
2142
2142
        Option('old-default-rules',
2143
2143
               help='Write out the ignore rules bzr < 0.9 always used.')
2144
2144
        ]
2145
 
    
 
2145
 
2146
2146
    def run(self, name_pattern_list=None, old_default_rules=None):
2147
2147
        from bzrlib import ignores
2148
2148
        if old_default_rules is not None:
2153
2153
        if not name_pattern_list:
2154
2154
            raise errors.BzrCommandError("ignore requires at least one "
2155
2155
                                  "NAME_PATTERN or --old-default-rules")
2156
 
        name_pattern_list = [globbing.normalize_pattern(p) 
 
2156
        name_pattern_list = [globbing.normalize_pattern(p)
2157
2157
                             for p in name_pattern_list]
2158
2158
        for name_pattern in name_pattern_list:
2159
 
            if (name_pattern[0] == '/' or 
 
2159
            if (name_pattern[0] == '/' or
2160
2160
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2161
2161
                raise errors.BzrCommandError(
2162
2162
                    "NAME_PATTERN should not be an absolute path")
2214
2214
    """
2215
2215
    hidden = True
2216
2216
    takes_args = ['revno']
2217
 
    
 
2217
 
2218
2218
    @display_command
2219
2219
    def run(self, revno):
2220
2220
        try:
2288
2288
    If no revision is nominated, the last revision is used.
2289
2289
 
2290
2290
    Note: Take care to redirect standard output when using this command on a
2291
 
    binary file. 
 
2291
    binary file.
2292
2292
    """
2293
2293
 
2294
2294
    _see_also = ['ls']
2341
2341
 
2342
2342
class cmd_local_time_offset(Command):
2343
2343
    """Show the offset in seconds from GMT to local time."""
2344
 
    hidden = True    
 
2344
    hidden = True
2345
2345
    @display_command
2346
2346
    def run(self):
2347
2347
        print osutils.local_time_offset()
2350
2350
 
2351
2351
class cmd_commit(Command):
2352
2352
    """Commit changes into a new revision.
2353
 
    
 
2353
 
2354
2354
    If no arguments are given, the entire tree is committed.
2355
2355
 
2356
2356
    If selected files are specified, only changes to those files are
2357
 
    committed.  If a directory is specified then the directory and everything 
 
2357
    committed.  If a directory is specified then the directory and everything
2358
2358
    within it is committed.
2359
2359
 
2360
2360
    When excludes are given, they take precedence over selected files.
2469
2469
        # TODO: Need a blackbox test for invoking the external editor; may be
2470
2470
        # slightly problematic to run this cross-platform.
2471
2471
 
2472
 
        # TODO: do more checks that the commit will succeed before 
 
2472
        # TODO: do more checks that the commit will succeed before
2473
2473
        # spending the user's valuable time typing a commit message.
2474
2474
 
2475
2475
        properties = {}
2498
2498
                        selected_list, diff=show_diff,
2499
2499
                        output_encoding=osutils.get_user_encoding())
2500
2500
                start_message = generate_commit_message_template(commit_obj)
2501
 
                my_message = edit_commit_message_encoded(t, 
 
2501
                my_message = edit_commit_message_encoded(t,
2502
2502
                    start_message=start_message)
2503
2503
                if my_message is None:
2504
2504
                    raise errors.BzrCommandError("please specify a commit"
2628
2628
 
2629
2629
class cmd_whoami(Command):
2630
2630
    """Show or set bzr user id.
2631
 
    
 
2631
 
2632
2632
    :Examples:
2633
2633
        Show the email of the current user::
2634
2634
 
2646
2646
                    ]
2647
2647
    takes_args = ['name?']
2648
2648
    encoding_type = 'replace'
2649
 
    
 
2649
 
2650
2650
    @display_command
2651
2651
    def run(self, email=False, branch=False, name=None):
2652
2652
        if name is None:
2667
2667
        except errors.NoEmailInUsername, e:
2668
2668
            warning('"%s" does not seem to contain an email address.  '
2669
2669
                    'This is allowed, but not recommended.', name)
2670
 
        
 
2670
 
2671
2671
        # use global config unless --branch given
2672
2672
        if branch:
2673
2673
            c = Branch.open_containing('.')[0].get_config()
2772
2772
 
2773
2773
class cmd_selftest(Command):
2774
2774
    """Run internal test suite.
2775
 
    
 
2775
 
2776
2776
    If arguments are given, they are regular expressions that say which tests
2777
2777
    should run.  Tests matching any expression are run, and other tests are
2778
2778
    not run.
2801
2801
    modified by plugins will not be tested, and tests provided by plugins will
2802
2802
    not be run.
2803
2803
 
2804
 
    Tests that need working space on disk use a common temporary directory, 
 
2804
    Tests that need working space on disk use a common temporary directory,
2805
2805
    typically inside $TMPDIR or /tmp.
2806
2806
 
2807
2807
    :Examples:
2971
2971
    #       merging only part of the history.
2972
2972
    takes_args = ['branch', 'other']
2973
2973
    hidden = True
2974
 
    
 
2974
 
2975
2975
    @display_command
2976
2976
    def run(self, branch, other):
2977
2977
        from bzrlib.revision import ensure_null
2978
 
        
 
2978
 
2979
2979
        branch1 = Branch.open_containing(branch)[0]
2980
2980
        branch2 = Branch.open_containing(other)[0]
2981
2981
        branch1.lock_read()
2997
2997
 
2998
2998
class cmd_merge(Command):
2999
2999
    """Perform a three-way merge.
3000
 
    
 
3000
 
3001
3001
    The source of the merge can be specified either in the form of a branch,
3002
3002
    or in the form of a path to a file containing a merge directive generated
3003
3003
    with bzr send. If neither is specified, the default is the upstream branch
3013
3013
    By default, bzr will try to merge in all new work from the other
3014
3014
    branch, automatically determining an appropriate base.  If this
3015
3015
    fails, you may need to give an explicit base.
3016
 
    
 
3016
 
3017
3017
    Merge will do its best to combine the changes in two branches, but there
3018
3018
    are some kinds of problems only a human can fix.  When it encounters those,
3019
3019
    it will mark a conflict.  A conflict means that you need to fix something,
3029
3029
    The results of the merge are placed into the destination working
3030
3030
    directory, where they can be reviewed (with bzr diff), tested, and then
3031
3031
    committed to record the result of the merge.
3032
 
    
 
3032
 
3033
3033
    merge refuses to run if there are any uncommitted changes, unless
3034
3034
    --force is given.
3035
3035
 
3300
3300
    """Redo a merge.
3301
3301
 
3302
3302
    Use this if you want to try a different merge technique while resolving
3303
 
    conflicts.  Some merge techniques are better than others, and remerge 
 
3303
    conflicts.  Some merge techniques are better than others, and remerge
3304
3304
    lets you try different ones on different files.
3305
3305
 
3306
3306
    The options for remerge have the same meaning and defaults as the ones for
3310
3310
    :Examples:
3311
3311
        Re-do the merge of all conflicted files, and show the base text in
3312
3312
        conflict regions, in addition to the usual THIS and OTHER texts::
3313
 
      
 
3313
 
3314
3314
            bzr remerge --show-base
3315
3315
 
3316
3316
        Re-do the merge of "foobar", using the weave merge algorithm, with
3317
3317
        additional processing to reduce the size of conflict regions::
3318
 
      
 
3318
 
3319
3319
            bzr remerge --merge-type weave --reprocess foobar
3320
3320
    """
3321
3321
    takes_args = ['file*']
3351
3351
                    interesting_ids.add(file_id)
3352
3352
                    if tree.kind(file_id) != "directory":
3353
3353
                        continue
3354
 
                    
 
3354
 
3355
3355
                    for name, ie in tree.inventory.iter_entries(file_id):
3356
3356
                        interesting_ids.add(ie.file_id)
3357
3357
                new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
3406
3406
    merge instead.  For example, "merge . --revision -2..-3" will remove the
3407
3407
    changes introduced by -2, without affecting the changes introduced by -1.
3408
3408
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
3409
 
    
 
3409
 
3410
3410
    By default, any files that have been manually changed will be backed up
3411
3411
    first.  (Files changed only by merge are not backed up.)  Backup files have
3412
3412
    '.~#~' appended to their name, where # is a number.
3481
3481
            ]
3482
3482
    takes_args = ['topic?']
3483
3483
    aliases = ['?', '--help', '-?', '-h']
3484
 
    
 
3484
 
3485
3485
    @display_command
3486
3486
    def run(self, topic=None, long=False):
3487
3487
        import bzrlib.help
3498
3498
    takes_args = ['context?']
3499
3499
    aliases = ['s-c']
3500
3500
    hidden = True
3501
 
    
 
3501
 
3502
3502
    @display_command
3503
3503
    def run(self, context=None):
3504
3504
        import shellcomplete
3507
3507
 
3508
3508
class cmd_missing(Command):
3509
3509
    """Show unmerged/unpulled revisions between two branches.
3510
 
    
 
3510
 
3511
3511
    OTHER_BRANCH may be local or remote.
3512
3512
    """
3513
3513
 
3651
3651
 
3652
3652
class cmd_plugins(Command):
3653
3653
    """List the installed plugins.
3654
 
    
 
3654
 
3655
3655
    This command displays the list of installed plugins including
3656
3656
    version of plugin and a short description of each.
3657
3657
 
3734
3734
    This prints out the given file with an annotation on the left side
3735
3735
    indicating which revision, author and date introduced the change.
3736
3736
 
3737
 
    If the origin is the same for a run of consecutive lines, it is 
 
3737
    If the origin is the same for a run of consecutive lines, it is
3738
3738
    shown only at the top, unless the --all option is given.
3739
3739
    """
3740
3740
    # TODO: annotate directories; showing when each file was last changed
3741
 
    # TODO: if the working copy is modified, show annotations on that 
 
3741
    # TODO: if the working copy is modified, show annotations on that
3742
3742
    #       with new uncommitted lines marked
3743
3743
    aliases = ['ann', 'blame', 'praise']
3744
3744
    takes_args = ['filename']
3790
3790
    hidden = True # is this right ?
3791
3791
    takes_args = ['revision_id*']
3792
3792
    takes_options = ['revision']
3793
 
    
 
3793
 
3794
3794
    def run(self, revision_id_list=None, revision=None):
3795
3795
        if revision_id_list is not None and revision is not None:
3796
3796
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4026
4026
    holding the lock has been stopped.
4027
4027
 
4028
4028
    You can get information on what locks are open via the 'bzr info' command.
4029
 
    
 
4029
 
4030
4030
    :Examples:
4031
4031
        bzr break-lock
4032
4032
    """
4040
4040
            control.break_lock()
4041
4041
        except NotImplementedError:
4042
4042
            pass
4043
 
        
 
4043
 
4044
4044
 
4045
4045
class cmd_wait_until_signalled(Command):
4046
4046
    """Test helper for test_start_and_stop_bzr_subprocess_send_signal.
4124
4124
 
4125
4125
class cmd_join(Command):
4126
4126
    """Combine a subtree into its containing tree.
4127
 
    
 
4127
 
4128
4128
    This command is for experimental use only.  It requires the target tree
4129
4129
    to be in dirstate-with-subtree format, which cannot be converted into
4130
4130
    earlier formats.
4172
4172
            try:
4173
4173
                containing_tree.subsume(sub_tree)
4174
4174
            except errors.BadSubsumeSource, e:
4175
 
                raise errors.BzrCommandError("Cannot join %s.  %s" % 
 
4175
                raise errors.BzrCommandError("Cannot join %s.  %s" %
4176
4176
                                             (tree, e.reason))
4177
4177
 
4178
4178
 
4331
4331
    Mail is sent using your preferred mail program.  This should be transparent
4332
4332
    on Windows (it uses MAPI).  On Linux, it requires the xdg-email utility.
4333
4333
    If the preferred client can't be found (or used), your editor will be used.
4334
 
    
 
4334
 
4335
4335
    To use a specific mail program, set the mail_client configuration option.
4336
4336
    (For Thunderbird 1.5, this works around some bugs.)  Supported values for
4337
4337
    specific clients are "claws", "evolution", "kmail", "mutt", and
4340
4340
 
4341
4341
    If mail is being sent, a to address is required.  This can be supplied
4342
4342
    either on the commandline, by setting the submit_to configuration
4343
 
    option in the branch itself or the child_submit_to configuration option 
 
4343
    option in the branch itself or the child_submit_to configuration option
4344
4344
    in the submit branch.
4345
4345
 
4346
4346
    Two formats are currently supported: "4" uses revision bundle format 4 and
4348
4348
    older formats.  It is compatible with Bazaar 0.19 and later.  It is the
4349
4349
    default.  "0.9" uses revision bundle format 0.9 and merge directive
4350
4350
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
4351
 
    
 
4351
 
4352
4352
    Merge directives are applied using the merge command or the pull command.
4353
4353
    """
4354
4354
 
4571
4571
 
4572
4572
class cmd_tag(Command):
4573
4573
    """Create, remove or modify a tag naming a revision.
4574
 
    
 
4574
 
4575
4575
    Tags give human-meaningful names to revisions.  Commands that take a -r
4576
4576
    (--revision) option can be given -rtag:X, where X is any previously
4577
4577
    created tag.
4579
4579
    Tags are stored in the branch.  Tags are copied from one branch to another
4580
4580
    along when you branch, push, pull or merge.
4581
4581
 
4582
 
    It is an error to give a tag name that already exists unless you pass 
 
4582
    It is an error to give a tag name that already exists unless you pass
4583
4583
    --force, in which case the tag is moved to point to the new revision.
4584
4584
 
4585
4585
    To rename a tag (change the name but keep it on the same revsion), run ``bzr
4764
4764
 
4765
4765
class cmd_switch(Command):
4766
4766
    """Set the branch of a checkout and update.
4767
 
    
 
4767
 
4768
4768
    For lightweight checkouts, this changes the branch being referenced.
4769
4769
    For heavyweight checkouts, this checks that there are no local commits
4770
4770
    versus the current bound branch, then it makes the local branch a mirror
4954
4954
 
4955
4955
# these get imported and then picked up by the scan for cmd_*
4956
4956
# TODO: Some more consistent way to split command definitions across files;
4957
 
# we do need to load at least some information about them to know of 
 
4957
# we do need to load at least some information about them to know of
4958
4958
# aliases.  ideally we would avoid loading the implementation until the
4959
4959
# details were needed.
4960
4960
from bzrlib.cmd_version_info import cmd_version_info