/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 bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2010-06-20 22:54:30 UTC
  • mfrom: (5308 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5309.
  • Revision ID: robertc@robertcollins.net-20100620225430-gzgig1g6ltba5sbk
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
491
491
    takes_options = [
492
492
        Option('force',
493
493
               help='Remove the working tree even if it has '
494
 
                    'uncommitted changes.'),
 
494
                    'uncommitted or shelved changes.'),
495
495
        ]
496
496
 
497
497
    def run(self, location_list, force=False):
511
511
            if not force:
512
512
                if (working.has_changes()):
513
513
                    raise errors.UncommittedChanges(working)
 
514
                if working.get_shelf_manager().last_shelf() is not None:
 
515
                    raise errors.ShelvedChanges(working)
514
516
 
515
517
            if working.user_url != working.branch.user_url:
516
518
                raise errors.BzrCommandError("You cannot remove the working tree"
1336
1338
            except errors.NoWorkingTree:
1337
1339
                source.bzrdir.create_workingtree(revision_id)
1338
1340
                return
1339
 
 
1340
 
        if not lightweight:
1341
 
            message = ('Copying history to "%s". '
1342
 
                'To checkout without local history use --lightweight.' % to_location)
1343
 
            ui.ui_factory.show_message(message)
1344
1341
        source.create_checkout(to_location, revision_id, lightweight,
1345
1342
                               accelerator_tree, hardlink)
1346
1343
 
1973
1970
         old_branch, new_branch,
1974
1971
         specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
1975
1972
            file_list, revision, old, new, self.add_cleanup, apply_view=True)
 
1973
        # GNU diff on Windows uses ANSI encoding for filenames
 
1974
        path_encoding = osutils.get_diff_header_encoding()
1976
1975
        return show_diff_trees(old_tree, new_tree, sys.stdout,
1977
1976
                               specific_files=specific_files,
1978
1977
                               external_diff_options=diff_options,
1979
1978
                               old_label=old_label, new_label=new_label,
1980
 
                               extra_trees=extra_trees, using=using,
 
1979
                               extra_trees=extra_trees,
 
1980
                               path_encoding=path_encoding,
 
1981
                               using=using,
1981
1982
                               format_cls=format)
1982
1983
 
1983
1984
 
3150
3151
        def get_message(commit_obj):
3151
3152
            """Callback to get commit message"""
3152
3153
            if file:
3153
 
                my_message = codecs.open(
3154
 
                    file, 'rt', osutils.get_user_encoding()).read()
 
3154
                f = codecs.open(file, 'rt', osutils.get_user_encoding())
 
3155
                try:
 
3156
                    my_message = f.read()
 
3157
                finally:
 
3158
                    f.close()
3155
3159
            elif message is not None:
3156
3160
                my_message = message
3157
3161
            else:
3311
3315
 
3312
3316
            bzr whoami "Frank Chu <fchu@example.com>"
3313
3317
    """
3314
 
    takes_options = [ Option('email',
 
3318
    takes_options = [ 'directory',
 
3319
                      Option('email',
3315
3320
                             help='Display email address only.'),
3316
3321
                      Option('branch',
3317
3322
                             help='Set identity for the current branch instead of '
3321
3326
    encoding_type = 'replace'
3322
3327
 
3323
3328
    @display_command
3324
 
    def run(self, email=False, branch=False, name=None):
 
3329
    def run(self, email=False, branch=False, name=None, directory=None):
3325
3330
        if name is None:
3326
 
            # use branch if we're inside one; otherwise global config
3327
 
            try:
3328
 
                c = Branch.open_containing('.')[0].get_config()
3329
 
            except errors.NotBranchError:
3330
 
                c = config.GlobalConfig()
 
3331
            if directory is None:
 
3332
                # use branch if we're inside one; otherwise global config
 
3333
                try:
 
3334
                    c = Branch.open_containing(u'.')[0].get_config()
 
3335
                except errors.NotBranchError:
 
3336
                    c = config.GlobalConfig()
 
3337
            else:
 
3338
                c = Branch.open(directory).get_config()
3331
3339
            if email:
3332
3340
                self.outf.write(c.user_email() + '\n')
3333
3341
            else:
3343
3351
 
3344
3352
        # use global config unless --branch given
3345
3353
        if branch:
3346
 
            c = Branch.open_containing('.')[0].get_config()
 
3354
            if directory is None:
 
3355
                c = Branch.open_containing(u'.')[0].get_config()
 
3356
            else:
 
3357
                c = Branch.open(directory).get_config()
3347
3358
        else:
3348
3359
            c = config.GlobalConfig()
3349
3360
        c.set_user_option('email', name)
3594
3605
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3595
3606
            # On Windows, disable automatic conversion of '\n' to '\r\n' in
3596
3607
            # stdout, which would corrupt the subunit stream. 
3597
 
            if sys.platform == "win32" and sys.stdout.fileno() >= 0:
 
3608
            # FIXME: This has been fixed in subunit trunk (>0.0.5) so the
 
3609
            # following code can be deleted when it's sufficiently deployed
 
3610
            # -- vila/mgz 20100514
 
3611
            if (sys.platform == "win32"
 
3612
                and getattr(sys.stdout, 'fileno', None) is not None):
3598
3613
                import msvcrt
3599
3614
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3600
3615
        if parallel:
3881
3896
    def _do_preview(self, merger):
3882
3897
        from bzrlib.diff import show_diff_trees
3883
3898
        result_tree = self._get_preview(merger)
 
3899
        path_encoding = osutils.get_diff_header_encoding()
3884
3900
        show_diff_trees(merger.this_tree, result_tree, self.outf,
3885
 
                        old_label='', new_label='')
 
3901
                        old_label='', new_label='',
 
3902
                        path_encoding=path_encoding)
3886
3903
 
3887
3904
    def _do_merge(self, merger, change_reporter, allow_pending, verified):
3888
3905
        merger.change_reporter = change_reporter
4287
4304
    _see_also = ['merge', 'pull']
4288
4305
    takes_args = ['other_branch?']
4289
4306
    takes_options = [
 
4307
        'directory',
4290
4308
        Option('reverse', 'Reverse the order of revisions.'),
4291
4309
        Option('mine-only',
4292
4310
               'Display changes in the local branch only.'),
4314
4332
            theirs_only=False,
4315
4333
            log_format=None, long=False, short=False, line=False,
4316
4334
            show_ids=False, verbose=False, this=False, other=False,
4317
 
            include_merges=False, revision=None, my_revision=None):
 
4335
            include_merges=False, revision=None, my_revision=None,
 
4336
            directory=u'.'):
4318
4337
        from bzrlib.missing import find_unmerged, iter_log_revisions
4319
4338
        def message(s):
4320
4339
            if not is_quiet():
4333
4352
        elif theirs_only:
4334
4353
            restrict = 'remote'
4335
4354
 
4336
 
        local_branch = Branch.open_containing(u".")[0]
 
4355
        local_branch = Branch.open_containing(directory)[0]
4337
4356
        self.add_cleanup(local_branch.lock_read().unlock)
4338
4357
 
4339
4358
        parent = local_branch.get_parent()
5010
5029
    _see_also = ['send']
5011
5030
 
5012
5031
    takes_options = [
 
5032
        'directory',
5013
5033
        RegistryOption.from_kwargs('patch-type',
5014
5034
            'The type of patch to include in the directive.',
5015
5035
            title='Patch type',
5028
5048
    encoding_type = 'exact'
5029
5049
 
5030
5050
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5031
 
            sign=False, revision=None, mail_to=None, message=None):
 
5051
            sign=False, revision=None, mail_to=None, message=None,
 
5052
            directory=u'.'):
5032
5053
        from bzrlib.revision import ensure_null, NULL_REVISION
5033
5054
        include_patch, include_bundle = {
5034
5055
            'plain': (False, False),
5035
5056
            'diff': (True, False),
5036
5057
            'bundle': (True, True),
5037
5058
            }[patch_type]
5038
 
        branch = Branch.open('.')
 
5059
        branch = Branch.open(directory)
5039
5060
        stored_submit_branch = branch.get_submit_branch()
5040
5061
        if submit_branch is None:
5041
5062
            submit_branch = stored_submit_branch
5126
5147
    given, in which case it is sent to a file.
5127
5148
 
5128
5149
    Mail is sent using your preferred mail program.  This should be transparent
5129
 
    on Windows (it uses MAPI).  On Linux, it requires the xdg-email utility.
 
5150
    on Windows (it uses MAPI).  On Unix, it requires the xdg-email utility.
5130
5151
    If the preferred client can't be found (or used), your editor will be used.
5131
5152
 
5132
5153
    To use a specific mail program, set the mail_client configuration option.
5529
5550
    """
5530
5551
 
5531
5552
    takes_args = ['to_location?']
5532
 
    takes_options = [Option('force',
 
5553
    takes_options = ['directory',
 
5554
                     Option('force',
5533
5555
                        help='Switch even if local commits will be lost.'),
5534
5556
                     'revision',
5535
5557
                     Option('create-branch', short_name='b',
5538
5560
                    ]
5539
5561
 
5540
5562
    def run(self, to_location=None, force=False, create_branch=False,
5541
 
            revision=None):
 
5563
            revision=None, directory=u'.'):
5542
5564
        from bzrlib import switch
5543
 
        tree_location = '.'
 
5565
        tree_location = directory
5544
5566
        revision = _get_one_revision('switch', revision)
5545
5567
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5546
5568
        if to_location is None:
5547
5569
            if revision is None:
5548
5570
                raise errors.BzrCommandError('You must supply either a'
5549
5571
                                             ' revision or a location')
5550
 
            to_location = '.'
 
5572
            to_location = tree_location
5551
5573
        try:
5552
5574
            branch = control_dir.open_branch()
5553
5575
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5828
5850
    takes_args = ['file*']
5829
5851
 
5830
5852
    takes_options = [
 
5853
        'directory',
5831
5854
        'revision',
5832
5855
        Option('all', help='Shelve all changes.'),
5833
5856
        'message',
5842
5865
    _see_also = ['unshelve']
5843
5866
 
5844
5867
    def run(self, revision=None, all=False, file_list=None, message=None,
5845
 
            writer=None, list=False, destroy=False):
 
5868
            writer=None, list=False, destroy=False, directory=u'.'):
5846
5869
        if list:
5847
5870
            return self.run_for_list()
5848
5871
        from bzrlib.shelf_ui import Shelver
5850
5873
            writer = bzrlib.option.diff_writer_registry.get()
5851
5874
        try:
5852
5875
            shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5853
 
                file_list, message, destroy=destroy)
 
5876
                file_list, message, destroy=destroy, directory=directory)
5854
5877
            try:
5855
5878
                shelver.run()
5856
5879
            finally:
5884
5907
 
5885
5908
    takes_args = ['shelf_id?']
5886
5909
    takes_options = [
 
5910
        'directory',
5887
5911
        RegistryOption.from_kwargs(
5888
5912
            'action', help="The action to perform.",
5889
5913
            enum_switch=False, value_switches=True,
5897
5921
    ]
5898
5922
    _see_also = ['shelve']
5899
5923
 
5900
 
    def run(self, shelf_id=None, action='apply'):
 
5924
    def run(self, shelf_id=None, action='apply', directory=u'.'):
5901
5925
        from bzrlib.shelf_ui import Unshelver
5902
 
        unshelver = Unshelver.from_args(shelf_id, action)
 
5926
        unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5903
5927
        try:
5904
5928
            unshelver.run()
5905
5929
        finally: