/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-06-17 07:11:55 UTC
  • mto: (5299.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5302.
  • Revision ID: v.ladeuil+lp@free.fr-20100617071155-by34vqnqqlvzuwt1
Fix typo.

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
    return view_info
233
233
 
234
234
 
 
235
def _open_directory_or_containing_tree_or_branch(filename, directory):
 
236
    """Open the tree or branch containing the specified file, unless
 
237
    the --directory option is used to specify a different branch."""
 
238
    if directory is not None:
 
239
        return (None, Branch.open(directory), filename)
 
240
    return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
241
 
 
242
 
235
243
# TODO: Make sure no commands unconditionally use the working directory as a
236
244
# branch.  If a filename argument is used, the first of them should be used to
237
245
# specify the branch.  (Perhaps this can be factored out into some kind of
340
348
 
341
349
    hidden = True
342
350
    takes_args = ['revision_id?']
343
 
    takes_options = ['revision']
 
351
    takes_options = ['directory', 'revision']
344
352
    # cat-revision is more for frontends so should be exact
345
353
    encoding = 'strict'
346
354
 
353
361
        self.outf.write(revtext.decode('utf-8'))
354
362
 
355
363
    @display_command
356
 
    def run(self, revision_id=None, revision=None):
 
364
    def run(self, revision_id=None, revision=None, directory=u'.'):
357
365
        if revision_id is not None and revision is not None:
358
366
            raise errors.BzrCommandError('You can only supply one of'
359
367
                                         ' revision_id or --revision')
360
368
        if revision_id is None and revision is None:
361
369
            raise errors.BzrCommandError('You must supply either'
362
370
                                         ' --revision or a revision_id')
363
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
371
        b = WorkingTree.open_containing(directory)[0].branch
364
372
 
365
373
        revisions = b.repository.revisions
366
374
        if revisions is None:
483
491
    takes_options = [
484
492
        Option('force',
485
493
               help='Remove the working tree even if it has '
486
 
                    'uncommitted changes.'),
 
494
                    'uncommitted or shelved changes.'),
487
495
        ]
488
496
 
489
497
    def run(self, location_list, force=False):
503
511
            if not force:
504
512
                if (working.has_changes()):
505
513
                    raise errors.UncommittedChanges(working)
 
514
                if working.get_shelf_manager().last_shelf() is not None:
 
515
                    raise errors.ShelvedChanges(working)
506
516
 
507
517
            if working.user_url != working.branch.user_url:
508
518
                raise errors.BzrCommandError("You cannot remove the working tree"
552
562
    takes_args = ['revision_info*']
553
563
    takes_options = [
554
564
        'revision',
555
 
        Option('directory',
 
565
        custom_help('directory',
556
566
            help='Branch to examine, '
557
 
                 'rather than the one containing the working directory.',
558
 
            short_name='d',
559
 
            type=unicode,
560
 
            ),
 
567
                 'rather than the one containing the working directory.'),
561
568
        Option('tree', help='Show revno of working tree'),
562
569
        ]
563
570
 
951
958
    takes_options = ['remember', 'overwrite', 'revision',
952
959
        custom_help('verbose',
953
960
            help='Show logs of pulled revisions.'),
954
 
        Option('directory',
 
961
        custom_help('directory',
955
962
            help='Branch to pull into, '
956
 
                 'rather than the one containing the working directory.',
957
 
            short_name='d',
958
 
            type=unicode,
959
 
            ),
 
963
                 'rather than the one containing the working directory.'),
960
964
        Option('local',
961
965
            help="Perform a local pull in a bound "
962
966
                 "branch.  Local pulls are not applied to "
1076
1080
        Option('create-prefix',
1077
1081
               help='Create the path leading up to the branch '
1078
1082
                    'if it does not already exist.'),
1079
 
        Option('directory',
 
1083
        custom_help('directory',
1080
1084
            help='Branch to push from, '
1081
 
                 'rather than the one containing the working directory.',
1082
 
            short_name='d',
1083
 
            type=unicode,
1084
 
            ),
 
1085
                 'rather than the one containing the working directory.'),
1085
1086
        Option('use-existing-dir',
1086
1087
               help='By default push will fail if the target'
1087
1088
                    ' directory exists, but does not already'
1987
1988
    # level of effort but possibly much less IO.  (Or possibly not,
1988
1989
    # if the directories are very large...)
1989
1990
    _see_also = ['status', 'ls']
1990
 
    takes_options = ['show-ids']
 
1991
    takes_options = ['directory', 'show-ids']
1991
1992
 
1992
1993
    @display_command
1993
 
    def run(self, show_ids=False):
1994
 
        tree = WorkingTree.open_containing(u'.')[0]
 
1994
    def run(self, show_ids=False, directory=u'.'):
 
1995
        tree = WorkingTree.open_containing(directory)[0]
1995
1996
        self.add_cleanup(tree.lock_read().unlock)
1996
1997
        old = tree.basis_tree()
1997
1998
        self.add_cleanup(old.lock_read().unlock)
2010
2011
 
2011
2012
    hidden = True
2012
2013
    _see_also = ['status', 'ls']
2013
 
    takes_options = [
2014
 
            Option('null',
2015
 
                   help='Write an ascii NUL (\\0) separator '
2016
 
                   'between files rather than a newline.')
2017
 
            ]
 
2014
    takes_options = ['directory', 'null']
2018
2015
 
2019
2016
    @display_command
2020
 
    def run(self, null=False):
2021
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2017
    def run(self, null=False, directory=u'.'):
 
2018
        tree = WorkingTree.open_containing(directory)[0]
2022
2019
        td = tree.changes_from(tree.basis_tree())
2023
2020
        for path, id, kind, text_modified, meta_modified in td.modified:
2024
2021
            if null:
2033
2030
 
2034
2031
    hidden = True
2035
2032
    _see_also = ['status', 'ls']
2036
 
    takes_options = [
2037
 
            Option('null',
2038
 
                   help='Write an ascii NUL (\\0) separator '
2039
 
                   'between files rather than a newline.')
2040
 
            ]
 
2033
    takes_options = ['directory', 'null']
2041
2034
 
2042
2035
    @display_command
2043
 
    def run(self, null=False):
2044
 
        wt = WorkingTree.open_containing(u'.')[0]
 
2036
    def run(self, null=False, directory=u'.'):
 
2037
        wt = WorkingTree.open_containing(directory)[0]
2045
2038
        self.add_cleanup(wt.lock_read().unlock)
2046
2039
        basis = wt.basis_tree()
2047
2040
        self.add_cleanup(basis.lock_read().unlock)
2053
2046
            if inv.is_root(file_id) and len(basis_inv) == 0:
2054
2047
                continue
2055
2048
            path = inv.id2path(file_id)
2056
 
            if not os.access(osutils.abspath(path), os.F_OK):
 
2049
            if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2057
2050
                continue
2058
2051
            if null:
2059
2052
                self.outf.write(path + '\0')
2259
2252
                   help='Show just the specified revision.'
2260
2253
                   ' See also "help revisionspec".'),
2261
2254
            'log-format',
 
2255
            RegistryOption('authors',
 
2256
                'What names to list as authors - first, all or committer.',
 
2257
                title='Authors',
 
2258
                lazy_registry=('bzrlib.log', 'author_list_registry'),
 
2259
            ),
2262
2260
            Option('levels',
2263
2261
                   short_name='n',
2264
2262
                   help='Number of levels to display - 0 for all, 1 for flat.',
2299
2297
            limit=None,
2300
2298
            show_diff=False,
2301
2299
            include_merges=False,
 
2300
            authors=None,
2302
2301
            exclude_common_ancestry=False,
2303
2302
            ):
2304
2303
        from bzrlib.log import (
2382
2381
                        show_timezone=timezone,
2383
2382
                        delta_format=get_verbosity_level(),
2384
2383
                        levels=levels,
2385
 
                        show_advice=levels is None)
 
2384
                        show_advice=levels is None,
 
2385
                        author_list_handler=authors)
2386
2386
 
2387
2387
        # Choose the algorithm for doing the logging. It's annoying
2388
2388
        # having multiple code paths like this but necessary until
2505
2505
                   help='Recurse into subdirectories.'),
2506
2506
            Option('from-root',
2507
2507
                   help='Print paths relative to the root of the branch.'),
2508
 
            Option('unknown', help='Print unknown files.'),
 
2508
            Option('unknown', short_name='u',
 
2509
                help='Print unknown files.'),
2509
2510
            Option('versioned', help='Print versioned files.',
2510
2511
                   short_name='V'),
2511
 
            Option('ignored', help='Print ignored files.'),
2512
 
            Option('null',
2513
 
                   help='Write an ascii NUL (\\0) separator '
2514
 
                   'between files rather than a newline.'),
2515
 
            Option('kind',
 
2512
            Option('ignored', short_name='i',
 
2513
                help='Print ignored files.'),
 
2514
            Option('kind', short_name='k',
2516
2515
                   help='List entries of a particular kind: file, directory, symlink.',
2517
2516
                   type=unicode),
 
2517
            'null',
2518
2518
            'show-ids',
 
2519
            'directory',
2519
2520
            ]
2520
2521
    @display_command
2521
2522
    def run(self, revision=None, verbose=False,
2522
2523
            recursive=False, from_root=False,
2523
2524
            unknown=False, versioned=False, ignored=False,
2524
 
            null=False, kind=None, show_ids=False, path=None):
 
2525
            null=False, kind=None, show_ids=False, path=None, directory=None):
2525
2526
 
2526
2527
        if kind and kind not in ('file', 'directory', 'symlink'):
2527
2528
            raise errors.BzrCommandError('invalid kind specified')
2539
2540
                raise errors.BzrCommandError('cannot specify both --from-root'
2540
2541
                                             ' and PATH')
2541
2542
            fs_path = path
2542
 
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2543
 
            fs_path)
 
2543
        tree, branch, relpath = \
 
2544
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
2544
2545
 
2545
2546
        # Calculate the prefix to use
2546
2547
        prefix = None
2614
2615
 
2615
2616
    hidden = True
2616
2617
    _see_also = ['ls']
 
2618
    takes_options = ['directory']
2617
2619
 
2618
2620
    @display_command
2619
 
    def run(self):
2620
 
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
 
2621
    def run(self, directory=u'.'):
 
2622
        for f in WorkingTree.open_containing(directory)[0].unknowns():
2621
2623
            self.outf.write(osutils.quotefn(f) + '\n')
2622
2624
 
2623
2625
 
2688
2690
 
2689
2691
    _see_also = ['status', 'ignored', 'patterns']
2690
2692
    takes_args = ['name_pattern*']
2691
 
    takes_options = [
 
2693
    takes_options = ['directory',
2692
2694
        Option('default-rules',
2693
2695
               help='Display the default ignore rules that bzr uses.')
2694
2696
        ]
2695
2697
 
2696
 
    def run(self, name_pattern_list=None, default_rules=None):
 
2698
    def run(self, name_pattern_list=None, default_rules=None,
 
2699
            directory=u'.'):
2697
2700
        from bzrlib import ignores
2698
2701
        if default_rules is not None:
2699
2702
            # dump the default rules and exit
2710
2713
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2714
                raise errors.BzrCommandError(
2712
2715
                    "NAME_PATTERN should not be an absolute path")
2713
 
        tree, relpath = WorkingTree.open_containing(u'.')
 
2716
        tree, relpath = WorkingTree.open_containing(directory)
2714
2717
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2715
2718
        ignored = globbing.Globster(name_pattern_list)
2716
2719
        matches = []
2742
2745
 
2743
2746
    encoding_type = 'replace'
2744
2747
    _see_also = ['ignore', 'ls']
 
2748
    takes_options = ['directory']
2745
2749
 
2746
2750
    @display_command
2747
 
    def run(self):
2748
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2751
    def run(self, directory=u'.'):
 
2752
        tree = WorkingTree.open_containing(directory)[0]
2749
2753
        self.add_cleanup(tree.lock_read().unlock)
2750
2754
        for path, file_class, kind, file_id, entry in tree.list_files():
2751
2755
            if file_class != 'I':
2763
2767
    """
2764
2768
    hidden = True
2765
2769
    takes_args = ['revno']
 
2770
    takes_options = ['directory']
2766
2771
 
2767
2772
    @display_command
2768
 
    def run(self, revno):
 
2773
    def run(self, revno, directory=u'.'):
2769
2774
        try:
2770
2775
            revno = int(revno)
2771
2776
        except ValueError:
2772
2777
            raise errors.BzrCommandError("not a valid revision-number: %r"
2773
2778
                                         % revno)
2774
 
        revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
 
2779
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2775
2780
        self.outf.write("%s\n" % revid)
2776
2781
 
2777
2782
 
2804
2809
      =================       =========================
2805
2810
    """
2806
2811
    takes_args = ['dest', 'branch_or_subdir?']
2807
 
    takes_options = [
 
2812
    takes_options = ['directory',
2808
2813
        Option('format',
2809
2814
               help="Type of file to export to.",
2810
2815
               type=unicode),
2819
2824
                    'revision in which it was changed.'),
2820
2825
        ]
2821
2826
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2822
 
        root=None, filters=False, per_file_timestamps=False):
 
2827
        root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2823
2828
        from bzrlib.export import export
2824
2829
 
2825
2830
        if branch_or_subdir is None:
2826
 
            tree = WorkingTree.open_containing(u'.')[0]
 
2831
            tree = WorkingTree.open_containing(directory)[0]
2827
2832
            b = tree.branch
2828
2833
            subdir = None
2829
2834
        else:
2848
2853
    """
2849
2854
 
2850
2855
    _see_also = ['ls']
2851
 
    takes_options = [
 
2856
    takes_options = ['directory',
2852
2857
        Option('name-from-revision', help='The path name in the old tree.'),
2853
2858
        Option('filters', help='Apply content filters to display the '
2854
2859
                'convenience form.'),
2859
2864
 
2860
2865
    @display_command
2861
2866
    def run(self, filename, revision=None, name_from_revision=False,
2862
 
            filters=False):
 
2867
            filters=False, directory=None):
2863
2868
        if revision is not None and len(revision) != 1:
2864
2869
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2865
2870
                                         " one revision specifier")
2866
2871
        tree, branch, relpath = \
2867
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
2872
            _open_directory_or_containing_tree_or_branch(filename, directory)
2868
2873
        self.add_cleanup(branch.lock_read().unlock)
2869
2874
        return self._run(tree, branch, relpath, filename, revision,
2870
2875
                         name_from_revision, filters)
3142
3147
        def get_message(commit_obj):
3143
3148
            """Callback to get commit message"""
3144
3149
            if file:
3145
 
                my_message = codecs.open(
3146
 
                    file, 'rt', osutils.get_user_encoding()).read()
 
3150
                f = codecs.open(file, 'rt', osutils.get_user_encoding())
 
3151
                try:
 
3152
                    my_message = f.read()
 
3153
                finally:
 
3154
                    f.close()
3147
3155
            elif message is not None:
3148
3156
                my_message = message
3149
3157
            else:
3303
3311
 
3304
3312
            bzr whoami "Frank Chu <fchu@example.com>"
3305
3313
    """
3306
 
    takes_options = [ Option('email',
 
3314
    takes_options = [ 'directory',
 
3315
                      Option('email',
3307
3316
                             help='Display email address only.'),
3308
3317
                      Option('branch',
3309
3318
                             help='Set identity for the current branch instead of '
3313
3322
    encoding_type = 'replace'
3314
3323
 
3315
3324
    @display_command
3316
 
    def run(self, email=False, branch=False, name=None):
 
3325
    def run(self, email=False, branch=False, name=None, directory=None):
3317
3326
        if name is None:
3318
 
            # use branch if we're inside one; otherwise global config
3319
 
            try:
3320
 
                c = Branch.open_containing('.')[0].get_config()
3321
 
            except errors.NotBranchError:
3322
 
                c = config.GlobalConfig()
 
3327
            if directory is None:
 
3328
                # use branch if we're inside one; otherwise global config
 
3329
                try:
 
3330
                    c = Branch.open_containing(u'.')[0].get_config()
 
3331
                except errors.NotBranchError:
 
3332
                    c = config.GlobalConfig()
 
3333
            else:
 
3334
                c = Branch.open(directory).get_config()
3323
3335
            if email:
3324
3336
                self.outf.write(c.user_email() + '\n')
3325
3337
            else:
3335
3347
 
3336
3348
        # use global config unless --branch given
3337
3349
        if branch:
3338
 
            c = Branch.open_containing('.')[0].get_config()
 
3350
            if directory is None:
 
3351
                c = Branch.open_containing(u'.')[0].get_config()
 
3352
            else:
 
3353
                c = Branch.open(directory).get_config()
3339
3354
        else:
3340
3355
            c = config.GlobalConfig()
3341
3356
        c.set_user_option('email', name)
3353
3368
 
3354
3369
    _see_also = ['info']
3355
3370
    takes_args = ['nickname?']
3356
 
    def run(self, nickname=None):
3357
 
        branch = Branch.open_containing(u'.')[0]
 
3371
    takes_options = ['directory']
 
3372
    def run(self, nickname=None, directory=u'.'):
 
3373
        branch = Branch.open_containing(directory)[0]
3358
3374
        if nickname is None:
3359
3375
            self.printme(branch)
3360
3376
        else:
3585
3601
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3586
3602
            # On Windows, disable automatic conversion of '\n' to '\r\n' in
3587
3603
            # stdout, which would corrupt the subunit stream. 
3588
 
            if sys.platform == "win32" and sys.stdout.fileno() >= 0:
 
3604
            # FIXME: This has been fixed in subunit trunk (>0.0.5) so the
 
3605
            # following code can be deleted when it's sufficiently deployed
 
3606
            # -- vila/mgz 20100514
 
3607
            if (sys.platform == "win32"
 
3608
                and getattr(sys.stdout, 'fileno', None) is not None):
3589
3609
                import msvcrt
3590
3610
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3591
3611
        if parallel:
3764
3784
                ' completely merged into the source, pull from the'
3765
3785
                ' source rather than merging.  When this happens,'
3766
3786
                ' you do not need to commit the result.'),
3767
 
        Option('directory',
 
3787
        custom_help('directory',
3768
3788
               help='Branch to merge into, '
3769
 
                    'rather than the one containing the working directory.',
3770
 
               short_name='d',
3771
 
               type=unicode,
3772
 
               ),
 
3789
                    'rather than the one containing the working directory.'),
3773
3790
        Option('preview', help='Instead of merging, show a diff of the'
3774
3791
               ' merge.'),
3775
3792
        Option('interactive', help='Select changes interactively.',
4281
4298
    _see_also = ['merge', 'pull']
4282
4299
    takes_args = ['other_branch?']
4283
4300
    takes_options = [
 
4301
        'directory',
4284
4302
        Option('reverse', 'Reverse the order of revisions.'),
4285
4303
        Option('mine-only',
4286
4304
               'Display changes in the local branch only.'),
4308
4326
            theirs_only=False,
4309
4327
            log_format=None, long=False, short=False, line=False,
4310
4328
            show_ids=False, verbose=False, this=False, other=False,
4311
 
            include_merges=False, revision=None, my_revision=None):
 
4329
            include_merges=False, revision=None, my_revision=None,
 
4330
            directory=u'.'):
4312
4331
        from bzrlib.missing import find_unmerged, iter_log_revisions
4313
4332
        def message(s):
4314
4333
            if not is_quiet():
4327
4346
        elif theirs_only:
4328
4347
            restrict = 'remote'
4329
4348
 
4330
 
        local_branch = Branch.open_containing(u".")[0]
 
4349
        local_branch = Branch.open_containing(directory)[0]
4331
4350
        self.add_cleanup(local_branch.lock_read().unlock)
4332
4351
 
4333
4352
        parent = local_branch.get_parent()
4542
4561
                     Option('long', help='Show commit date in annotations.'),
4543
4562
                     'revision',
4544
4563
                     'show-ids',
 
4564
                     'directory',
4545
4565
                     ]
4546
4566
    encoding_type = 'exact'
4547
4567
 
4548
4568
    @display_command
4549
4569
    def run(self, filename, all=False, long=False, revision=None,
4550
 
            show_ids=False):
 
4570
            show_ids=False, directory=None):
4551
4571
        from bzrlib.annotate import annotate_file, annotate_file_tree
4552
4572
        wt, branch, relpath = \
4553
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
4573
            _open_directory_or_containing_tree_or_branch(filename, directory)
4554
4574
        if wt is not None:
4555
4575
            self.add_cleanup(wt.lock_read().unlock)
4556
4576
        else:
4580
4600
 
4581
4601
    hidden = True # is this right ?
4582
4602
    takes_args = ['revision_id*']
4583
 
    takes_options = ['revision']
 
4603
    takes_options = ['directory', 'revision']
4584
4604
 
4585
 
    def run(self, revision_id_list=None, revision=None):
 
4605
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
4586
4606
        if revision_id_list is not None and revision is not None:
4587
4607
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4588
4608
        if revision_id_list is None and revision is None:
4589
4609
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
4610
        b = WorkingTree.open_containing(directory)[0].branch
4591
4611
        self.add_cleanup(b.lock_write().unlock)
4592
4612
        return self._run(b, revision_id_list, revision)
4593
4613
 
4653
4673
 
4654
4674
    _see_also = ['checkouts', 'unbind']
4655
4675
    takes_args = ['location?']
4656
 
    takes_options = []
 
4676
    takes_options = ['directory']
4657
4677
 
4658
 
    def run(self, location=None):
4659
 
        b, relpath = Branch.open_containing(u'.')
 
4678
    def run(self, location=None, directory=u'.'):
 
4679
        b, relpath = Branch.open_containing(directory)
4660
4680
        if location is None:
4661
4681
            try:
4662
4682
                location = b.get_old_bound_location()
4689
4709
 
4690
4710
    _see_also = ['checkouts', 'bind']
4691
4711
    takes_args = []
4692
 
    takes_options = []
 
4712
    takes_options = ['directory']
4693
4713
 
4694
 
    def run(self):
4695
 
        b, relpath = Branch.open_containing(u'.')
 
4714
    def run(self, directory=u'.'):
 
4715
        b, relpath = Branch.open_containing(directory)
4696
4716
        if not b.unbind():
4697
4717
            raise errors.BzrCommandError('Local branch is not bound')
4698
4718
 
4860
4880
                    'result in a dynamically allocated port.  The default port '
4861
4881
                    'depends on the protocol.',
4862
4882
               type=str),
4863
 
        Option('directory',
4864
 
               help='Serve contents of this directory.',
4865
 
               type=unicode),
 
4883
        custom_help('directory',
 
4884
               help='Serve contents of this directory.'),
4866
4885
        Option('allow-writes',
4867
4886
               help='By default the server is a readonly server.  Supplying '
4868
4887
                    '--allow-writes enables write access to the contents of '
5004
5023
    _see_also = ['send']
5005
5024
 
5006
5025
    takes_options = [
 
5026
        'directory',
5007
5027
        RegistryOption.from_kwargs('patch-type',
5008
5028
            'The type of patch to include in the directive.',
5009
5029
            title='Patch type',
5022
5042
    encoding_type = 'exact'
5023
5043
 
5024
5044
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5025
 
            sign=False, revision=None, mail_to=None, message=None):
 
5045
            sign=False, revision=None, mail_to=None, message=None,
 
5046
            directory=u'.'):
5026
5047
        from bzrlib.revision import ensure_null, NULL_REVISION
5027
5048
        include_patch, include_bundle = {
5028
5049
            'plain': (False, False),
5029
5050
            'diff': (True, False),
5030
5051
            'bundle': (True, True),
5031
5052
            }[patch_type]
5032
 
        branch = Branch.open('.')
 
5053
        branch = Branch.open(directory)
5033
5054
        stored_submit_branch = branch.get_submit_branch()
5034
5055
        if submit_branch is None:
5035
5056
            submit_branch = stored_submit_branch
5120
5141
    given, in which case it is sent to a file.
5121
5142
 
5122
5143
    Mail is sent using your preferred mail program.  This should be transparent
5123
 
    on Windows (it uses MAPI).  On Linux, it requires the xdg-email utility.
 
5144
    on Windows (it uses MAPI).  On Unix, it requires the xdg-email utility.
5124
5145
    If the preferred client can't be found (or used), your editor will be used.
5125
5146
 
5126
5147
    To use a specific mail program, set the mail_client configuration option.
5297
5318
        Option('delete',
5298
5319
            help='Delete this tag rather than placing it.',
5299
5320
            ),
5300
 
        Option('directory',
5301
 
            help='Branch in which to place the tag.',
5302
 
            short_name='d',
5303
 
            type=unicode,
5304
 
            ),
 
5321
        custom_help('directory',
 
5322
            help='Branch in which to place the tag.'),
5305
5323
        Option('force',
5306
5324
            help='Replace existing tags.',
5307
5325
            ),
5349
5367
 
5350
5368
    _see_also = ['tag']
5351
5369
    takes_options = [
5352
 
        Option('directory',
5353
 
            help='Branch whose tags should be displayed.',
5354
 
            short_name='d',
5355
 
            type=unicode,
5356
 
            ),
 
5370
        custom_help('directory',
 
5371
            help='Branch whose tags should be displayed.'),
5357
5372
        RegistryOption.from_kwargs('sort',
5358
5373
            'Sort tags by different criteria.', title='Sorting',
5359
5374
            alpha='Sort tags lexicographically (default).',
5529
5544
    """
5530
5545
 
5531
5546
    takes_args = ['to_location?']
5532
 
    takes_options = [Option('force',
 
5547
    takes_options = ['directory',
 
5548
                     Option('force',
5533
5549
                        help='Switch even if local commits will be lost.'),
5534
5550
                     'revision',
5535
5551
                     Option('create-branch', short_name='b',
5538
5554
                    ]
5539
5555
 
5540
5556
    def run(self, to_location=None, force=False, create_branch=False,
5541
 
            revision=None):
 
5557
            revision=None, directory=u'.'):
5542
5558
        from bzrlib import switch
5543
 
        tree_location = '.'
 
5559
        tree_location = directory
5544
5560
        revision = _get_one_revision('switch', revision)
5545
5561
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5546
5562
        if to_location is None:
5547
5563
            if revision is None:
5548
5564
                raise errors.BzrCommandError('You must supply either a'
5549
5565
                                             ' revision or a location')
5550
 
            to_location = '.'
 
5566
            to_location = tree_location
5551
5567
        try:
5552
5568
            branch = control_dir.open_branch()
5553
5569
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5828
5844
    takes_args = ['file*']
5829
5845
 
5830
5846
    takes_options = [
 
5847
        'directory',
5831
5848
        'revision',
5832
5849
        Option('all', help='Shelve all changes.'),
5833
5850
        'message',
5842
5859
    _see_also = ['unshelve']
5843
5860
 
5844
5861
    def run(self, revision=None, all=False, file_list=None, message=None,
5845
 
            writer=None, list=False, destroy=False):
 
5862
            writer=None, list=False, destroy=False, directory=u'.'):
5846
5863
        if list:
5847
5864
            return self.run_for_list()
5848
5865
        from bzrlib.shelf_ui import Shelver
5850
5867
            writer = bzrlib.option.diff_writer_registry.get()
5851
5868
        try:
5852
5869
            shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5853
 
                file_list, message, destroy=destroy)
 
5870
                file_list, message, destroy=destroy, directory=directory)
5854
5871
            try:
5855
5872
                shelver.run()
5856
5873
            finally:
5884
5901
 
5885
5902
    takes_args = ['shelf_id?']
5886
5903
    takes_options = [
 
5904
        'directory',
5887
5905
        RegistryOption.from_kwargs(
5888
5906
            'action', help="The action to perform.",
5889
5907
            enum_switch=False, value_switches=True,
5897
5915
    ]
5898
5916
    _see_also = ['shelve']
5899
5917
 
5900
 
    def run(self, shelf_id=None, action='apply'):
 
5918
    def run(self, shelf_id=None, action='apply', directory=u'.'):
5901
5919
        from bzrlib.shelf_ui import Unshelver
5902
 
        unshelver = Unshelver.from_args(shelf_id, action)
 
5920
        unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5903
5921
        try:
5904
5922
            unshelver.run()
5905
5923
        finally:
5921
5939
 
5922
5940
    To check what clean-tree will do, use --dry-run.
5923
5941
    """
5924
 
    takes_options = [Option('ignored', help='Delete all ignored files.'),
 
5942
    takes_options = ['directory',
 
5943
                     Option('ignored', help='Delete all ignored files.'),
5925
5944
                     Option('detritus', help='Delete conflict files, merge'
5926
5945
                            ' backups, and failed selftest dirs.'),
5927
5946
                     Option('unknown',
5930
5949
                            ' deleting them.'),
5931
5950
                     Option('force', help='Do not prompt before deleting.')]
5932
5951
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5933
 
            force=False):
 
5952
            force=False, directory=u'.'):
5934
5953
        from bzrlib.clean_tree import clean_tree
5935
5954
        if not (unknown or ignored or detritus):
5936
5955
            unknown = True
5937
5956
        if dry_run:
5938
5957
            force = True
5939
 
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5940
 
                   dry_run=dry_run, no_prompt=force)
 
5958
        clean_tree(directory, unknown=unknown, ignored=ignored,
 
5959
                   detritus=detritus, dry_run=dry_run, no_prompt=force)
5941
5960
 
5942
5961
 
5943
5962
class cmd_reference(Command):