/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: Vincent Ladeuil
  • Date: 2010-07-07 11:21:19 UTC
  • mto: (5193.7.1 unify-confs)
  • mto: This revision was merged to the branch mainline in revision 5349.
  • Revision ID: v.ladeuil+lp@free.fr-20100707112119-jwyh312df41w6l0o
Revert previous change as I can't reproduce the related problem anymore.

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
 
2720
2721
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2721
2722
        ignored = globbing.Globster(name_pattern_list)
2722
2723
        matches = []
2723
 
        tree.lock_read()
 
2724
        self.add_cleanup(tree.lock_read().unlock)
2724
2725
        for entry in tree.list_files():
2725
2726
            id = entry[3]
2726
2727
            if id is not None:
2727
2728
                filename = entry[0]
2728
2729
                if ignored.match(filename):
2729
2730
                    matches.append(filename)
2730
 
        tree.unlock()
2731
2731
        if len(matches) > 0:
2732
2732
            self.outf.write("Warning: the following files are version controlled and"
2733
2733
                  " match your ignore pattern:\n%s"
3150
3150
        def get_message(commit_obj):
3151
3151
            """Callback to get commit message"""
3152
3152
            if file:
3153
 
                my_message = codecs.open(
3154
 
                    file, 'rt', osutils.get_user_encoding()).read()
 
3153
                f = codecs.open(file, 'rt', osutils.get_user_encoding())
 
3154
                try:
 
3155
                    my_message = f.read()
 
3156
                finally:
 
3157
                    f.close()
3155
3158
            elif message is not None:
3156
3159
                my_message = message
3157
3160
            else:
3311
3314
 
3312
3315
            bzr whoami "Frank Chu <fchu@example.com>"
3313
3316
    """
3314
 
    takes_options = [ Option('email',
 
3317
    takes_options = [ 'directory',
 
3318
                      Option('email',
3315
3319
                             help='Display email address only.'),
3316
3320
                      Option('branch',
3317
3321
                             help='Set identity for the current branch instead of '
3321
3325
    encoding_type = 'replace'
3322
3326
 
3323
3327
    @display_command
3324
 
    def run(self, email=False, branch=False, name=None):
 
3328
    def run(self, email=False, branch=False, name=None, directory=None):
3325
3329
        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()
 
3330
            if directory is None:
 
3331
                # use branch if we're inside one; otherwise global config
 
3332
                try:
 
3333
                    c = Branch.open_containing(u'.')[0].get_config()
 
3334
                except errors.NotBranchError:
 
3335
                    c = config.GlobalConfig()
 
3336
            else:
 
3337
                c = Branch.open(directory).get_config()
3331
3338
            if email:
3332
3339
                self.outf.write(c.user_email() + '\n')
3333
3340
            else:
3343
3350
 
3344
3351
        # use global config unless --branch given
3345
3352
        if branch:
3346
 
            c = Branch.open_containing('.')[0].get_config()
 
3353
            if directory is None:
 
3354
                c = Branch.open_containing(u'.')[0].get_config()
 
3355
            else:
 
3356
                c = Branch.open(directory).get_config()
3347
3357
        else:
3348
3358
            c = config.GlobalConfig()
3349
3359
        c.set_user_option('email', name)
3594
3604
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3595
3605
            # On Windows, disable automatic conversion of '\n' to '\r\n' in
3596
3606
            # stdout, which would corrupt the subunit stream. 
3597
 
            if sys.platform == "win32" and sys.stdout.fileno() >= 0:
 
3607
            # FIXME: This has been fixed in subunit trunk (>0.0.5) so the
 
3608
            # following code can be deleted when it's sufficiently deployed
 
3609
            # -- vila/mgz 20100514
 
3610
            if (sys.platform == "win32"
 
3611
                and getattr(sys.stdout, 'fileno', None) is not None):
3598
3612
                import msvcrt
3599
3613
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3600
3614
        if parallel:
3881
3895
    def _do_preview(self, merger):
3882
3896
        from bzrlib.diff import show_diff_trees
3883
3897
        result_tree = self._get_preview(merger)
 
3898
        path_encoding = osutils.get_diff_header_encoding()
3884
3899
        show_diff_trees(merger.this_tree, result_tree, self.outf,
3885
 
                        old_label='', new_label='')
 
3900
                        old_label='', new_label='',
 
3901
                        path_encoding=path_encoding)
3886
3902
 
3887
3903
    def _do_merge(self, merger, change_reporter, allow_pending, verified):
3888
3904
        merger.change_reporter = change_reporter
4287
4303
    _see_also = ['merge', 'pull']
4288
4304
    takes_args = ['other_branch?']
4289
4305
    takes_options = [
 
4306
        'directory',
4290
4307
        Option('reverse', 'Reverse the order of revisions.'),
4291
4308
        Option('mine-only',
4292
4309
               'Display changes in the local branch only.'),
4314
4331
            theirs_only=False,
4315
4332
            log_format=None, long=False, short=False, line=False,
4316
4333
            show_ids=False, verbose=False, this=False, other=False,
4317
 
            include_merges=False, revision=None, my_revision=None):
 
4334
            include_merges=False, revision=None, my_revision=None,
 
4335
            directory=u'.'):
4318
4336
        from bzrlib.missing import find_unmerged, iter_log_revisions
4319
4337
        def message(s):
4320
4338
            if not is_quiet():
4333
4351
        elif theirs_only:
4334
4352
            restrict = 'remote'
4335
4353
 
4336
 
        local_branch = Branch.open_containing(u".")[0]
 
4354
        local_branch = Branch.open_containing(directory)[0]
4337
4355
        self.add_cleanup(local_branch.lock_read().unlock)
4338
4356
 
4339
4357
        parent = local_branch.get_parent()
4901
4919
 
4902
4920
    def run(self, port=None, inet=False, directory=None, allow_writes=False,
4903
4921
            protocol=None):
4904
 
        from bzrlib.transport import get_transport, transport_server_registry
 
4922
        from bzrlib import transport
4905
4923
        if directory is None:
4906
4924
            directory = os.getcwd()
4907
4925
        if protocol is None:
4908
 
            protocol = transport_server_registry.get()
 
4926
            protocol = transport.transport_server_registry.get()
4909
4927
        host, port = self.get_host_and_port(port)
4910
4928
        url = urlutils.local_path_to_url(directory)
4911
4929
        if not allow_writes:
4912
4930
            url = 'readonly+' + url
4913
 
        transport = get_transport(url)
4914
 
        protocol(transport, host, port, inet)
 
4931
        t = transport.get_transport(url)
 
4932
        protocol(t, host, port, inet)
4915
4933
 
4916
4934
 
4917
4935
class cmd_join(Command):
5010
5028
    _see_also = ['send']
5011
5029
 
5012
5030
    takes_options = [
 
5031
        'directory',
5013
5032
        RegistryOption.from_kwargs('patch-type',
5014
5033
            'The type of patch to include in the directive.',
5015
5034
            title='Patch type',
5028
5047
    encoding_type = 'exact'
5029
5048
 
5030
5049
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5031
 
            sign=False, revision=None, mail_to=None, message=None):
 
5050
            sign=False, revision=None, mail_to=None, message=None,
 
5051
            directory=u'.'):
5032
5052
        from bzrlib.revision import ensure_null, NULL_REVISION
5033
5053
        include_patch, include_bundle = {
5034
5054
            'plain': (False, False),
5035
5055
            'diff': (True, False),
5036
5056
            'bundle': (True, True),
5037
5057
            }[patch_type]
5038
 
        branch = Branch.open('.')
 
5058
        branch = Branch.open(directory)
5039
5059
        stored_submit_branch = branch.get_submit_branch()
5040
5060
        if submit_branch is None:
5041
5061
            submit_branch = stored_submit_branch
5126
5146
    given, in which case it is sent to a file.
5127
5147
 
5128
5148
    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.
 
5149
    on Windows (it uses MAPI).  On Unix, it requires the xdg-email utility.
5130
5150
    If the preferred client can't be found (or used), your editor will be used.
5131
5151
 
5132
5152
    To use a specific mail program, set the mail_client configuration option.
5529
5549
    """
5530
5550
 
5531
5551
    takes_args = ['to_location?']
5532
 
    takes_options = [Option('force',
 
5552
    takes_options = ['directory',
 
5553
                     Option('force',
5533
5554
                        help='Switch even if local commits will be lost.'),
5534
5555
                     'revision',
5535
5556
                     Option('create-branch', short_name='b',
5538
5559
                    ]
5539
5560
 
5540
5561
    def run(self, to_location=None, force=False, create_branch=False,
5541
 
            revision=None):
 
5562
            revision=None, directory=u'.'):
5542
5563
        from bzrlib import switch
5543
 
        tree_location = '.'
 
5564
        tree_location = directory
5544
5565
        revision = _get_one_revision('switch', revision)
5545
5566
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5546
5567
        if to_location is None:
5547
5568
            if revision is None:
5548
5569
                raise errors.BzrCommandError('You must supply either a'
5549
5570
                                             ' revision or a location')
5550
 
            to_location = '.'
 
5571
            to_location = tree_location
5551
5572
        try:
5552
5573
            branch = control_dir.open_branch()
5553
5574
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5828
5849
    takes_args = ['file*']
5829
5850
 
5830
5851
    takes_options = [
 
5852
        'directory',
5831
5853
        'revision',
5832
5854
        Option('all', help='Shelve all changes.'),
5833
5855
        'message',
5842
5864
    _see_also = ['unshelve']
5843
5865
 
5844
5866
    def run(self, revision=None, all=False, file_list=None, message=None,
5845
 
            writer=None, list=False, destroy=False):
 
5867
            writer=None, list=False, destroy=False, directory=u'.'):
5846
5868
        if list:
5847
5869
            return self.run_for_list()
5848
5870
        from bzrlib.shelf_ui import Shelver
5850
5872
            writer = bzrlib.option.diff_writer_registry.get()
5851
5873
        try:
5852
5874
            shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5853
 
                file_list, message, destroy=destroy)
 
5875
                file_list, message, destroy=destroy, directory=directory)
5854
5876
            try:
5855
5877
                shelver.run()
5856
5878
            finally:
5884
5906
 
5885
5907
    takes_args = ['shelf_id?']
5886
5908
    takes_options = [
 
5909
        'directory',
5887
5910
        RegistryOption.from_kwargs(
5888
5911
            'action', help="The action to perform.",
5889
5912
            enum_switch=False, value_switches=True,
5897
5920
    ]
5898
5921
    _see_also = ['shelve']
5899
5922
 
5900
 
    def run(self, shelf_id=None, action='apply'):
 
5923
    def run(self, shelf_id=None, action='apply', directory=u'.'):
5901
5924
        from bzrlib.shelf_ui import Unshelver
5902
 
        unshelver = Unshelver.from_args(shelf_id, action)
 
5925
        unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5903
5926
        try:
5904
5927
            unshelver.run()
5905
5928
        finally: