~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2010-08-13 07:56:06 UTC
  • mfrom: (5050.17.4 2.2)
  • mto: (5050.17.6 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: mbp@sourcefrog.net-20100813075606-8zgmov3ezwans2zo
merge bzr 2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
180
180
                view_str = views.view_display_str(view_files)
181
181
                note("Ignoring files outside view. View is %s" % view_str)
182
182
        return tree, file_list
183
 
    tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
 
183
    tree = WorkingTree.open_containing(file_list[0])[0]
184
184
    return tree, safe_relpath_files(tree, file_list, canonicalize,
185
185
        apply_view=apply_view)
186
186
 
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"
1968
1970
         old_branch, new_branch,
1969
1971
         specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
1970
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()
1971
1975
        return show_diff_trees(old_tree, new_tree, sys.stdout,
1972
1976
                               specific_files=specific_files,
1973
1977
                               external_diff_options=diff_options,
1974
1978
                               old_label=old_label, new_label=new_label,
1975
 
                               extra_trees=extra_trees, using=using,
 
1979
                               extra_trees=extra_trees,
 
1980
                               path_encoding=path_encoding,
 
1981
                               using=using,
1976
1982
                               format_cls=format)
1977
1983
 
1978
1984
 
2706
2712
                "NAME_PATTERN or --default-rules.")
2707
2713
        name_pattern_list = [globbing.normalize_pattern(p)
2708
2714
                             for p in name_pattern_list]
 
2715
        bad_patterns = ''
 
2716
        for p in name_pattern_list:
 
2717
            if not globbing.Globster.is_pattern_valid(p):
 
2718
                bad_patterns += ('\n  %s' % p)
 
2719
        if bad_patterns:
 
2720
            msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
 
2721
            ui.ui_factory.show_error(msg)
 
2722
            raise errors.InvalidPattern('')
2709
2723
        for name_pattern in name_pattern_list:
2710
2724
            if (name_pattern[0] == '/' or
2711
2725
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2715
2729
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2716
2730
        ignored = globbing.Globster(name_pattern_list)
2717
2731
        matches = []
2718
 
        tree.lock_read()
 
2732
        self.add_cleanup(tree.lock_read().unlock)
2719
2733
        for entry in tree.list_files():
2720
2734
            id = entry[3]
2721
2735
            if id is not None:
2722
2736
                filename = entry[0]
2723
2737
                if ignored.match(filename):
2724
2738
                    matches.append(filename)
2725
 
        tree.unlock()
2726
2739
        if len(matches) > 0:
2727
2740
            self.outf.write("Warning: the following files are version controlled and"
2728
2741
                  " match your ignore pattern:\n%s"
3309
3322
 
3310
3323
            bzr whoami "Frank Chu <fchu@example.com>"
3311
3324
    """
3312
 
    takes_options = [ Option('email',
 
3325
    takes_options = [ 'directory',
 
3326
                      Option('email',
3313
3327
                             help='Display email address only.'),
3314
3328
                      Option('branch',
3315
3329
                             help='Set identity for the current branch instead of '
3319
3333
    encoding_type = 'replace'
3320
3334
 
3321
3335
    @display_command
3322
 
    def run(self, email=False, branch=False, name=None):
 
3336
    def run(self, email=False, branch=False, name=None, directory=None):
3323
3337
        if name is None:
3324
 
            # use branch if we're inside one; otherwise global config
3325
 
            try:
3326
 
                c = Branch.open_containing('.')[0].get_config()
3327
 
            except errors.NotBranchError:
3328
 
                c = config.GlobalConfig()
 
3338
            if directory is None:
 
3339
                # use branch if we're inside one; otherwise global config
 
3340
                try:
 
3341
                    c = Branch.open_containing(u'.')[0].get_config()
 
3342
                except errors.NotBranchError:
 
3343
                    c = config.GlobalConfig()
 
3344
            else:
 
3345
                c = Branch.open(directory).get_config()
3329
3346
            if email:
3330
3347
                self.outf.write(c.user_email() + '\n')
3331
3348
            else:
3341
3358
 
3342
3359
        # use global config unless --branch given
3343
3360
        if branch:
3344
 
            c = Branch.open_containing('.')[0].get_config()
 
3361
            if directory is None:
 
3362
                c = Branch.open_containing(u'.')[0].get_config()
 
3363
            else:
 
3364
                c = Branch.open(directory).get_config()
3345
3365
        else:
3346
3366
            c = config.GlobalConfig()
3347
3367
        c.set_user_option('email', name)
3517
3537
                                 'throughout the test suite.',
3518
3538
                            type=get_transport_type),
3519
3539
                     Option('benchmark',
3520
 
                            help='Run the benchmarks rather than selftests.'),
 
3540
                            help='Run the benchmarks rather than selftests.',
 
3541
                            hidden=True),
3521
3542
                     Option('lsprof-timed',
3522
3543
                            help='Generate lsprof output for benchmarked'
3523
3544
                                 ' sections of code.'),
3524
3545
                     Option('lsprof-tests',
3525
3546
                            help='Generate lsprof output for each test.'),
3526
 
                     Option('cache-dir', type=str,
3527
 
                            help='Cache intermediate benchmark output in this '
3528
 
                                 'directory.'),
3529
3547
                     Option('first',
3530
3548
                            help='Run all tests, but run specified tests first.',
3531
3549
                            short_name='f',
3565
3583
 
3566
3584
    def run(self, testspecs_list=None, verbose=False, one=False,
3567
3585
            transport=None, benchmark=None,
3568
 
            lsprof_timed=None, cache_dir=None,
 
3586
            lsprof_timed=None,
3569
3587
            first=False, list_only=False,
3570
3588
            randomize=None, exclude=None, strict=False,
3571
3589
            load_list=None, debugflag=None, starting_with=None, subunit=False,
3572
3590
            parallel=None, lsprof_tests=False):
3573
3591
        from bzrlib.tests import selftest
3574
 
        import bzrlib.benchmarks as benchmarks
3575
 
        from bzrlib.benchmarks import tree_creator
3576
3592
 
3577
3593
        # Make deprecation warnings visible, unless -Werror is set
3578
3594
        symbol_versioning.activate_deprecation_warnings(override=False)
3579
3595
 
3580
 
        if cache_dir is not None:
3581
 
            tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3582
3596
        if testspecs_list is not None:
3583
3597
            pattern = '|'.join(testspecs_list)
3584
3598
        else:
3603
3617
            self.additional_selftest_args.setdefault(
3604
3618
                'suite_decorators', []).append(parallel)
3605
3619
        if benchmark:
3606
 
            test_suite_factory = benchmarks.test_suite
3607
 
            # Unless user explicitly asks for quiet, be verbose in benchmarks
3608
 
            verbose = not is_quiet()
3609
 
            # TODO: should possibly lock the history file...
3610
 
            benchfile = open(".perf_history", "at", buffering=1)
3611
 
            self.add_cleanup(benchfile.close)
3612
 
        else:
3613
 
            test_suite_factory = None
3614
 
            benchfile = None
 
3620
            raise errors.BzrCommandError(
 
3621
                "--benchmark is no longer supported from bzr 2.2; "
 
3622
                "use bzr-usertest instead")
 
3623
        test_suite_factory = None
3615
3624
        selftest_kwargs = {"verbose": verbose,
3616
3625
                          "pattern": pattern,
3617
3626
                          "stop_on_failure": one,
3619
3628
                          "test_suite_factory": test_suite_factory,
3620
3629
                          "lsprof_timed": lsprof_timed,
3621
3630
                          "lsprof_tests": lsprof_tests,
3622
 
                          "bench_history": benchfile,
3623
3631
                          "matching_tests_first": first,
3624
3632
                          "list_only": list_only,
3625
3633
                          "random_seed": randomize,
3883
3891
    def _do_preview(self, merger):
3884
3892
        from bzrlib.diff import show_diff_trees
3885
3893
        result_tree = self._get_preview(merger)
 
3894
        path_encoding = osutils.get_diff_header_encoding()
3886
3895
        show_diff_trees(merger.this_tree, result_tree, self.outf,
3887
 
                        old_label='', new_label='')
 
3896
                        old_label='', new_label='',
 
3897
                        path_encoding=path_encoding)
3888
3898
 
3889
3899
    def _do_merge(self, merger, change_reporter, allow_pending, verified):
3890
3900
        merger.change_reporter = change_reporter
4289
4299
    _see_also = ['merge', 'pull']
4290
4300
    takes_args = ['other_branch?']
4291
4301
    takes_options = [
 
4302
        'directory',
4292
4303
        Option('reverse', 'Reverse the order of revisions.'),
4293
4304
        Option('mine-only',
4294
4305
               'Display changes in the local branch only.'),
4316
4327
            theirs_only=False,
4317
4328
            log_format=None, long=False, short=False, line=False,
4318
4329
            show_ids=False, verbose=False, this=False, other=False,
4319
 
            include_merges=False, revision=None, my_revision=None):
 
4330
            include_merges=False, revision=None, my_revision=None,
 
4331
            directory=u'.'):
4320
4332
        from bzrlib.missing import find_unmerged, iter_log_revisions
4321
4333
        def message(s):
4322
4334
            if not is_quiet():
4335
4347
        elif theirs_only:
4336
4348
            restrict = 'remote'
4337
4349
 
4338
 
        local_branch = Branch.open_containing(u".")[0]
 
4350
        local_branch = Branch.open_containing(directory)[0]
4339
4351
        self.add_cleanup(local_branch.lock_read().unlock)
4340
4352
 
4341
4353
        parent = local_branch.get_parent()
4903
4915
 
4904
4916
    def run(self, port=None, inet=False, directory=None, allow_writes=False,
4905
4917
            protocol=None):
4906
 
        from bzrlib.transport import get_transport, transport_server_registry
 
4918
        from bzrlib import transport
4907
4919
        if directory is None:
4908
4920
            directory = os.getcwd()
4909
4921
        if protocol is None:
4910
 
            protocol = transport_server_registry.get()
 
4922
            protocol = transport.transport_server_registry.get()
4911
4923
        host, port = self.get_host_and_port(port)
4912
4924
        url = urlutils.local_path_to_url(directory)
4913
4925
        if not allow_writes:
4914
4926
            url = 'readonly+' + url
4915
 
        transport = get_transport(url)
4916
 
        protocol(transport, host, port, inet)
 
4927
        t = transport.get_transport(url)
 
4928
        protocol(t, host, port, inet)
4917
4929
 
4918
4930
 
4919
4931
class cmd_join(Command):
5012
5024
    _see_also = ['send']
5013
5025
 
5014
5026
    takes_options = [
 
5027
        'directory',
5015
5028
        RegistryOption.from_kwargs('patch-type',
5016
5029
            'The type of patch to include in the directive.',
5017
5030
            title='Patch type',
5030
5043
    encoding_type = 'exact'
5031
5044
 
5032
5045
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5033
 
            sign=False, revision=None, mail_to=None, message=None):
 
5046
            sign=False, revision=None, mail_to=None, message=None,
 
5047
            directory=u'.'):
5034
5048
        from bzrlib.revision import ensure_null, NULL_REVISION
5035
5049
        include_patch, include_bundle = {
5036
5050
            'plain': (False, False),
5037
5051
            'diff': (True, False),
5038
5052
            'bundle': (True, True),
5039
5053
            }[patch_type]
5040
 
        branch = Branch.open('.')
 
5054
        branch = Branch.open(directory)
5041
5055
        stored_submit_branch = branch.get_submit_branch()
5042
5056
        if submit_branch is None:
5043
5057
            submit_branch = stored_submit_branch
5531
5545
    """
5532
5546
 
5533
5547
    takes_args = ['to_location?']
5534
 
    takes_options = [Option('force',
 
5548
    takes_options = ['directory',
 
5549
                     Option('force',
5535
5550
                        help='Switch even if local commits will be lost.'),
5536
5551
                     'revision',
5537
5552
                     Option('create-branch', short_name='b',
5540
5555
                    ]
5541
5556
 
5542
5557
    def run(self, to_location=None, force=False, create_branch=False,
5543
 
            revision=None):
 
5558
            revision=None, directory=u'.'):
5544
5559
        from bzrlib import switch
5545
 
        tree_location = '.'
 
5560
        tree_location = directory
5546
5561
        revision = _get_one_revision('switch', revision)
5547
5562
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5548
5563
        if to_location is None:
5549
5564
            if revision is None:
5550
5565
                raise errors.BzrCommandError('You must supply either a'
5551
5566
                                             ' revision or a location')
5552
 
            to_location = '.'
 
5567
            to_location = tree_location
5553
5568
        try:
5554
5569
            branch = control_dir.open_branch()
5555
5570
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5830
5845
    takes_args = ['file*']
5831
5846
 
5832
5847
    takes_options = [
 
5848
        'directory',
5833
5849
        'revision',
5834
5850
        Option('all', help='Shelve all changes.'),
5835
5851
        'message',
5844
5860
    _see_also = ['unshelve']
5845
5861
 
5846
5862
    def run(self, revision=None, all=False, file_list=None, message=None,
5847
 
            writer=None, list=False, destroy=False):
 
5863
            writer=None, list=False, destroy=False, directory=u'.'):
5848
5864
        if list:
5849
5865
            return self.run_for_list()
5850
5866
        from bzrlib.shelf_ui import Shelver
5852
5868
            writer = bzrlib.option.diff_writer_registry.get()
5853
5869
        try:
5854
5870
            shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5855
 
                file_list, message, destroy=destroy)
 
5871
                file_list, message, destroy=destroy, directory=directory)
5856
5872
            try:
5857
5873
                shelver.run()
5858
5874
            finally:
5886
5902
 
5887
5903
    takes_args = ['shelf_id?']
5888
5904
    takes_options = [
 
5905
        'directory',
5889
5906
        RegistryOption.from_kwargs(
5890
5907
            'action', help="The action to perform.",
5891
5908
            enum_switch=False, value_switches=True,
5899
5916
    ]
5900
5917
    _see_also = ['shelve']
5901
5918
 
5902
 
    def run(self, shelf_id=None, action='apply'):
 
5919
    def run(self, shelf_id=None, action='apply', directory=u'.'):
5903
5920
        from bzrlib.shelf_ui import Unshelver
5904
 
        unshelver = Unshelver.from_args(shelf_id, action)
 
5921
        unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5905
5922
        try:
5906
5923
            unshelver.run()
5907
5924
        finally: